diff --git a/entry.go b/entry.go index 9a6044c..221e0a8 100644 --- a/entry.go +++ b/entry.go @@ -424,11 +424,20 @@ func FromConfigFileFlagPath(cliFlagName, defaultPath, description string, config return func(c *options) error { commandLine := flag.NewFlagSet(os.Args[0], flag.ContinueOnError) + commandLine.SetOutput(io.Discard) configPath := commandLine.String(cliFlagName, defaultPath, description) if err := commandLine.Parse(os.Args[1:]); err != nil { if errors.Is(err, flag.ErrHelp) { + // This weirdness is because Parse will print out things if it doesnt recognise them + // as this section of the code has no knowledge of what structs are actually defined + // we want to only print help if asked for it + commandLine.SetOutput(os.Stdout) + fmt.Fprintf(os.Stdout, "Usage of %s:\n", os.Args[0]) + commandLine.PrintDefaults() + commandLine.SetOutput(io.Discard) + return flag.ErrHelp } diff --git a/entry_test.go b/entry_test.go index ecc8b2c..0e20fd9 100644 --- a/entry_test.go +++ b/entry_test.go @@ -53,5 +53,4 @@ func TestConfigurationHelp(t *testing.T) { t.Fatal("should return that help was asked for") } - t.Fail() }