Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow default values in struct tags #91

Merged
merged 8 commits into from
Oct 22, 2019
Merged

Allow default values in struct tags #91

merged 8 commits into from
Oct 22, 2019

Conversation

alexflint
Copy link
Owner

@alexflint alexflint commented Oct 8, 2019

This pr introduces support for default values specified as struct tags:

var args struct {
  Foo int `default:"123"`
}
arg.MustParse(&args)

This means there are now two ways to provide default values. The old way still works as expected:

var args struct {
  Foo int
}
args.Foo = 123
arg.MustParse(&args)

The reason I'm introducing this feature is that it has now been requested many times, and the old approach does not work with subcommands (introduced in #82; see discussion in #86).

Fixes #40 #68 #86 #92

@atc0005
Copy link

atc0005 commented Oct 16, 2019

This pr introduces support for default values specified as struct tags:

var args struct {
  Foo int `default:"123"`
}
arg.MustParse(&args)

Does this result in the default values being shown in the help text? I tested using commit 5d3ebcc, but the default "labels" only show when setting them via the "old way".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Default value vs required arg
2 participants