Skip to content

Commit

Permalink
fixed missing default values in some codepaths for issue #46
Browse files Browse the repository at this point in the history
  • Loading branch information
integrii committed Aug 21, 2019
1 parent 842f321 commit 4253042
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion helpValues.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ func (h *Help) parseFlagsToHelpFlags(flags []*Flag) {
continue
}

// parse help values out if the flag hasn't been parsed yet
if !f.parsed {
f.parsed = true
// parse the default value as a string and remember it for help output
f.defaultValue, _ = f.returnAssignmentVarValueAsString()
}

// determine the default value based on the assignment variable
defaultValue := f.defaultValue

Expand All @@ -196,7 +203,6 @@ func (h *Help) parseFlagsToHelpFlags(flags []*Flag) {
Description: f.Description,
DefaultValue: defaultValue,
}

h.AddFlagToHelp(newHelpFlag)
}
}
Expand Down
6 changes: 3 additions & 3 deletions helpValues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestHelpOutput(t *testing.T) {
// defer debugOff()

p := flaggy.NewParser("testCommand")
p.Description = "Description goes here. Get more information at http://flaggy.flag."
p.Description = "Description goes here. Get more information at https://github.com/integrii/flaggy."
scA := flaggy.NewSubcommand("subcommandA")
scA.ShortName = "a"
scA.Description = "Subcommand A is a command that does stuff"
Expand All @@ -51,7 +51,7 @@ func TestHelpOutput(t *testing.T) {
scA.AddPositionalValue(&posA, "testPositionalA", 2, false, "Test positional A does some things with a positional value.")
scB.AddPositionalValue(&posB, "hiddenPositional", 1, false, "Hidden test positional B does some less than serious things with a positional value.")
scB.PositionalFlags[0].Hidden = true
var stringFlag string
var stringFlag = "defaultStringHere"
var intFlag int
var boolFlag bool
var durationFlag time.Duration
Expand All @@ -61,6 +61,6 @@ func TestHelpOutput(t *testing.T) {
p.Duration(&durationFlag, "d", "durationFlag", "This is a test duration flag that does some untimely stuff.")
p.AdditionalHelpPrepend = "This is a prepend for help"
p.AdditionalHelpAppend = "This is an append for help"
p.ShowHelpWithMessage("This is a help addon message")
p.ParseArgs([]string{"subcommandA", "subcommandB", "hiddenPositional1"})
p.ShowHelpWithMessage("This is a help message on exit")
}

0 comments on commit 4253042

Please sign in to comment.