Add an explicit help flag that exits with 0 (#3654)

`stash --help` exits with a non-zero exit code. Because `stash --help`
is a legitimate invocation, it should return an exit code of zero.
Adding an explicit help flag allows for exiting with a successful exit
code.
This commit is contained in:
charitybell 2023-04-25 14:48:43 -07:00 committed by GitHub
parent 8d3f632d4c
commit 85c893fd81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -24,6 +24,7 @@ type flagStruct struct {
configFilePath string
cpuProfilePath string
nobrowser bool
helpFlag bool
}
func GetInstance() *Instance {
@ -40,6 +41,12 @@ func Initialize() (*Instance, error) {
var err error
initOnce.Do(func() {
flags := initFlags()
if flags.helpFlag {
pflag.Usage()
os.Exit(0)
}
overrides := makeOverrideConfig()
_ = GetInstance()
@ -126,6 +133,7 @@ func initFlags() flagStruct {
pflag.StringVarP(&flags.configFilePath, "config", "c", "", "config file to use")
pflag.StringVar(&flags.cpuProfilePath, "cpuprofile", "", "write cpu profile to file")
pflag.BoolVar(&flags.nobrowser, "nobrowser", false, "Don't open a browser window after launch")
pflag.BoolVarP(&flags.helpFlag, "help", "h", false, "show this help text and exit")
pflag.Parse()