diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2017-05-07 21:09:31 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2017-05-07 21:09:31 +0200 |
| commit | 385645d1a0bb9ae618e92d2e7a2ea6fe256b5ba2 (patch) | |
| tree | a3dc1b31c22db47e515f541e87fbfc2e8bb872f4 /main.go | |
| parent | a54004fbd960e4851f1f249ce0d030cf56b20f1b (diff) | |
| download | gofu-385645d1a0bb9ae618e92d2e7a2ea6fe256b5ba2.tar.gz | |
bubble up exit codes instead of calling os.Exit() in functions
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 22 |
1 files changed, 8 insertions, 14 deletions
@@ -23,34 +23,28 @@ import ( "os" "path/filepath" - "github.com/majewsky/gofu/pkg/cli" "github.com/majewsky/gofu/pkg/rtree" ) func main() { - execApplet(filepath.Base(os.Args[0]), os.Args[1:], true) + os.Exit(execApplet(filepath.Base(os.Args[0]), os.Args[1:], true)) } -func execApplet(applet string, args []string, allowGofu bool) { +func execApplet(applet string, args []string, allowGofu bool) int { //allow explicit specification of applet as "./build/gofu <applet> <args>" if allowGofu && applet == "gofu" { if len(args) == 0 { fmt.Fprintln(os.Stderr, "Usage: gofu <applet> [args...]") - os.Exit(1) + return 1 } - execApplet(args[0], args[1:], false) - return + return execApplet(args[0], args[1:], false) } switch applet { case "rtree": - rtree.Exec(args) - case "test": - choice, _ := cli.Query("Which is the best editor?", - cli.Choice{Shortcut: 'v', Text: "vim"}, - cli.Choice{Shortcut: 'e', Text: "emacs"}, - cli.Choice{Text: "atom"}, - ) - fmt.Printf("You selected %s. Good choice!\n", choice.Text) + return rtree.Exec(args) + default: + fmt.Fprintln(os.Stderr, "ERROR: unknown applet: "+applet) + return 255 } } |
