JMS #39: Removed all calls to os.Exit().
This commit is contained in:
parent
e6e641143c
commit
b25b7a883c
12
app.go
12
app.go
@ -57,16 +57,20 @@ func (a *App) Run(arguments []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
checkHelp(context)
|
||||
checkVersion(context)
|
||||
if checkHelp(context) {
|
||||
return nil
|
||||
}
|
||||
|
||||
if checkVersion(context) {
|
||||
return nil
|
||||
}
|
||||
|
||||
args := context.Args()
|
||||
if len(args) > 0 {
|
||||
name := args[0]
|
||||
c := a.Command(name)
|
||||
if c != nil {
|
||||
c.Run(context)
|
||||
return nil
|
||||
return c.Run(context)
|
||||
}
|
||||
}
|
||||
|
||||
|
10
command.go
10
command.go
@ -3,7 +3,6 @@ package cli
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -24,7 +23,7 @@ type Command struct {
|
||||
}
|
||||
|
||||
// Invokes the command given the context, parses ctx.Args() to generate command-specific flags
|
||||
func (c Command) Run(ctx *Context) {
|
||||
func (c Command) Run(ctx *Context) error {
|
||||
// append help to flags
|
||||
c.Flags = append(
|
||||
c.Flags,
|
||||
@ -55,12 +54,15 @@ func (c Command) Run(ctx *Context) {
|
||||
fmt.Println("Incorrect Usage.\n")
|
||||
ShowCommandHelp(ctx, c.Name)
|
||||
fmt.Println("")
|
||||
os.Exit(1)
|
||||
return err
|
||||
}
|
||||
|
||||
context := NewContext(ctx.App, set, ctx.globalSet)
|
||||
checkCommandHelp(context, c.Name)
|
||||
if checkCommandHelp(context, c.Name) {
|
||||
return nil
|
||||
}
|
||||
c.Action(context)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Returns true if Command.Name or Command.ShortName matches given name
|
||||
|
23
help.go
23
help.go
@ -73,7 +73,6 @@ func ShowCommandHelp(c *Context, command string) {
|
||||
}
|
||||
|
||||
fmt.Printf("No help topic for '%v'\n", command)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Prints the version number of the App
|
||||
@ -88,23 +87,29 @@ func printHelp(templ string, data interface{}) {
|
||||
w.Flush()
|
||||
}
|
||||
|
||||
func checkVersion(c *Context) {
|
||||
func checkVersion(c *Context) bool {
|
||||
if c.GlobalBool("version") {
|
||||
ShowVersion(c)
|
||||
os.Exit(0)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func checkHelp(c *Context) {
|
||||
return false
|
||||
}
|
||||
|
||||
func checkHelp(c *Context) bool {
|
||||
if c.GlobalBool("h") || c.GlobalBool("help") {
|
||||
ShowAppHelp(c)
|
||||
os.Exit(0)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func checkCommandHelp(c *Context, name string) {
|
||||
return false
|
||||
}
|
||||
|
||||
func checkCommandHelp(c *Context, name string) bool {
|
||||
if c.Bool("h") || c.Bool("help") {
|
||||
ShowCommandHelp(c, name)
|
||||
os.Exit(0)
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user