Support `required` flags
See original GitHub issueSome options must always be specified.
I want to have a way to specify the required options in API.
Example
const cli = meow(`
Usage
$ process
Options
-i, --input Input file
-o, --output Output file
Examples
$ process --input=lib/file.js --output=dest/file.js
`, {
required: ['input', 'output']
});
A program without required options must quit with an error message.
$ process --output=dest/file.js
Missing required option:
--input, -i Input file
IssueHunt Summary
sbencoding has been rewarded.
Backers (Total: $60.00)
issuehunt ($60.00)
Submitted pull Requests
Tips
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on IssueHunt to raise funds.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:10
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Can command line flags in Go be set to mandatory?
The flag package does not support mandatory or required flags (meaning the flag must be specified explicitly).
Read more >flags, required flag? · Issue #42 · abseil/abseil-py - GitHub
I must be missing something but I'm not finding any way to mark a flag as being required? Or is it an intentional...
Read more >United States Flag Code | The American Legion
(g) When flags of two or more nations are displayed, they are to be flown from separate staffs of the same height. The...
Read more >Required flags are not printed when using --help (#96) - GitLab
The help text should display when a field is optional or required. Drag your designs here or click to upload.
Read more >flag - Go Packages
Package flag implements command-line flag parsing. Usage ¶. Define flags using flag.String(), Bool(), Int(), etc. This declares an integer flag, -n, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m gonna reopen this as I think it could be useful for CLI only tools (ones that don’t have an API).
It could be specified like:
We should be clear in the docs that API level option validation should be preferred.
The
required
option could also accept a function that could receive the arguments and do its own check whether it’s required. For example, if the flag is only required when another flag is specified.I agree with @kevva. I believe this should be handled by the code that is called. That allows the most flexibility with informative custom error messages.