Closed nyang5 closed 5 years ago
This does feel inconsistent. Thanks for the report @nyang5 !
An invalid flag will bubble an error up to App.Run()
so you can check and exit at that level with a non-zero code.
An invalid flag will bubble an error up to App.Run() so you can check and exit at that level with a non-zero code.
@jszwedko can you explain a bit more how that might look? I've tried replicating the app.OnUsageError
function like in https://github.com/vektorlab/slackcat/commit/5add3e434b990f33931ecc5bfccc38ef0ace08a7, but we still see a silent app exit when a BoolFlag has a value like test
.
Some more details on the above, the latest master of urfave/cli seems to handle parameters with non-parseable values:
go run *.go bootstrap --clean-checkout=llamas
Incorrect Usage: invalid boolean value "llamas" for -clean-checkout: strconv.ParseBool: parsing "llamas": invalid syntax
However, it silently fails with environment variables:
BUILDKITE_CLEAN_CHECKOUT=llamas go run *.go bootstrap
exit 0
Hi @lox,
Can you try that with the latest cli
? Or provide the commit you are using? I wasn't able to replicate with:
package main
import (
"log"
"os"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "clean-checkout",
EnvVar: "BUILDKITE_CLEAN_CHECKOUT",
Usage: "language for the greeting",
},
}
app.Action = func(c *cli.Context) error {
return nil
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
$ BUILDKITE_CLEAN_CHECKOUT=llamas go run /tmp/tmp.go
2017/11/11 16:09:34 could not parse llamas as bool value for flag clean-checkout: strconv.ParseBool: parsing "llamas": invalid syntax
exit status 1
Ah-hah, I wasn't catching the error from app.Run
. Works with master now. Thanks!
No problem! I'll leave this open to make sure the issue with exit codes is addressed.
Should HandleExitCoder
call OsExiter(1)
when passed a "normal" error?
For example:
err := errors.New("neither an ExitCoder nor a MultiError")
cli.HandleExitCoder(err) // should this os.Exit(1) ?
Given that this is from last year, I think I'm comfortable closing it 🙂 feel free to re-open / open a new issue / comment in support if there's still interest here!
currently if an invalid command is given the exit code will be 3 when an invalid flag is given the exit code is 0?
is there a reason for this and how do I change the exit code when an invalid flag is given?