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

Purposely call usage after argument validation, #84

Closed
gavinmcnair opened this issue Aug 6, 2019 · 3 comments
Closed

Purposely call usage after argument validation, #84

gavinmcnair opened this issue Aug 6, 2019 · 3 comments

Comments

@gavinmcnair
Copy link

I am trying to get the usage message when failing to validate arguments passed

arg.WriteHelp(os.Stdout)

does not work and is not really relevant without the &args struct.

What is the best way to purposely call usage?

@alexflint
Copy link
Owner

one way you can do this is with this sample:

var args struct {
	Foo string
	Bar string
}
p := arg.MustParse(&args)
if args.Foo == "" && args.Bar == "" {
	p.Fail("you must provide either --foo or --bar")
}

output is:

./example
Usage: samples [--foo FOO] [--bar BAR]
error: you must provide either --foo or --bar

Is this what you want?

(Also, in what way does p.WriteHelp(os.Stdout) not work?)

@alexflint
Copy link
Owner

Closing for now, feel free to reopen if this does not solve your problem

@gavinmcnair
Copy link
Author

Perfect, i wasn't capturing p (in your example). This works great now. Thanks

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

No branches or pull requests

2 participants