Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

refactor: cmd/phlare/main.go #566

Merged
merged 4 commits into from
Mar 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions cmd/phlare/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,29 @@ func (mf *mainFlags) RegisterFlags(fs *flag.FlagSet) {
fs.BoolVar(&mf.PrintHelp, "help", false, "Print basic help.")
fs.BoolVar(&mf.PrintHelpAll, "help-all", false, "Print help, also including advanced and experimental parameters.")
}
func errorHandler() {
testMode := cfg.GetTestMode()
if !testMode {
os.Exit(1)
}

}
func main() {
var (
flags mainFlags
)

testMode := cfg.GetTestMode()

if err := cfg.DynamicUnmarshal(&flags, os.Args[1:], flag.CommandLine); err != nil {
fmt.Fprintf(os.Stderr, "failed parsing config: %v\n", err)
if testMode {
return
}
os.Exit(1)
errorHandler()
return
}

f, err := phlare.New(flags.Config)
if err != nil {
fmt.Fprintf(os.Stderr, "failed creating phlare: %v\n", err)
if testMode {
return
}
os.Exit(1)
errorHandler()
return
}

if flags.PrintVersion {
Expand Down Expand Up @@ -97,10 +97,8 @@ func main() {
flag.CommandLine.SetOutput(os.Stdout)
if err := usage.Usage(flags.PrintHelpAll, &flags); err != nil {
fmt.Fprintf(os.Stderr, "error printing usage: %s\n", err)
if testMode {
return
}
os.Exit(1)
errorHandler()
return
}

return
Expand All @@ -109,9 +107,7 @@ func main() {
err = f.Run()
if err != nil {
fmt.Fprintf(os.Stderr, "failed running phlare: %v\n", err)
if testMode {
return
}
os.Exit(1)
errorHandler()
return
}
}