summaryrefslogtreecommitdiff
path: root/pkg/rtree/main.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2017-05-07 21:09:31 +0200
committerStefan Majewsky <majewsky@gmx.net>2017-05-07 21:09:31 +0200
commit385645d1a0bb9ae618e92d2e7a2ea6fe256b5ba2 (patch)
treea3dc1b31c22db47e515f541e87fbfc2e8bb872f4 /pkg/rtree/main.go
parenta54004fbd960e4851f1f249ce0d030cf56b20f1b (diff)
downloadgofu-385645d1a0bb9ae618e92d2e7a2ea6fe256b5ba2.tar.gz
bubble up exit codes instead of calling os.Exit() in functions
Diffstat (limited to 'pkg/rtree/main.go')
-rw-r--r--pkg/rtree/main.go42
1 files changed, 21 insertions, 21 deletions
diff --git a/pkg/rtree/main.go b/pkg/rtree/main.go
index b77d6ca..d57b399 100644
--- a/pkg/rtree/main.go
+++ b/pkg/rtree/main.go
@@ -27,9 +27,9 @@ import (
//Exec executes the rtree applet and does not return. The argument is os.Args
//minus the leading "rtree" or "gofu rtree".
-func Exec(args []string) {
+func Exec(args []string) int {
if len(args) == 0 {
- usageAndExit()
+ return usage()
}
index, errs := ReadIndex()
@@ -37,65 +37,64 @@ func Exec(args []string) {
for _, err := range errs {
util.ShowError(err)
}
- os.Exit(255)
+ return 255
}
var err error
switch args[0] {
case "get":
if len(args) != 2 {
- usageAndExit()
+ return usage()
}
err = commandGet(index, args[1])
case "drop":
if len(args) != 2 {
- usageAndExit()
+ return usage()
}
err = commandDrop(index, args[1])
case "index":
if len(args) != 1 {
- usageAndExit()
+ return usage()
}
err = commandIndex(index)
case "repos":
if len(args) != 1 {
- usageAndExit()
+ return usage()
}
commandRepos(index)
case "remotes":
if len(args) != 1 {
- usageAndExit()
+ return usage()
}
commandRemotes(index)
case "import":
if len(args) != 2 {
- usageAndExit()
+ return usage()
}
err = commandImport(index, args[1])
case "each":
if len(args) < 2 {
- usageAndExit()
+ return usage()
}
- commandEach(index, args[1], args[2:])
+ return commandEach(index, args[1], args[2:])
default:
- usageAndExit()
+ return usage()
}
if err == nil {
- os.Exit(0)
- } else {
- util.ShowError(err)
- os.Exit(1)
+ return 0
}
+ util.ShowError(err)
+ return 1
}
-func usageAndExit() {
+func usage() int {
fmt.Fprintln(os.Stderr, "Usage:")
fmt.Fprintln(os.Stderr, " rtree [get|drop] <url>")
fmt.Fprintln(os.Stderr, " rtree [index|repos|remotes]")
fmt.Fprintln(os.Stderr, " rtree import <path>")
fmt.Fprintln(os.Stderr, " rtree each <command>")
- os.Exit(1)
+ return 1
}
func commandGet(index *Index, url string) error {
@@ -145,7 +144,7 @@ func commandRemotes(index *Index) {
util.ShowSorted(items)
}
-func commandEach(index *Index, command string, args []string) {
+func commandEach(index *Index, command string, args []string) int {
allOK := true
for _, repo := range index.Repos {
ok := repo.InteractiveExec(command, args...)
@@ -154,9 +153,10 @@ func commandEach(index *Index, command string, args []string) {
}
}
- if !allOK {
- os.Exit(1)
+ if allOK {
+ return 0
}
+ return 1
}
func commandImport(index *Index, dirPath string) error {