The issue has been solved
Some 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

In most cases I would handle this in the API. Any reason you need to do it in the CLI?
posted by kevva over 8 years ago
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.
posted by SamVerschueren over 8 years ago
Going to close for now. If there are some good arguments for having this as an option we might re-open it again.
posted by kevva over 7 years ago
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:
flags: {
rainbow: {
type: 'boolean',
alias: 'r',
required: true
}
}
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.
posted by sindresorhus over 7 years ago
posted by IssueHuntBot about 6 years ago 
If a required field takes a function, should the expected return value of the function be a boolean? A quick example could be helpful as I am currently working in this.
Thanks
posted by HackAfro about 6 years ago
posted by IssueHuntBot about 6 years ago 
should the expected return value of the function be a boolean?
Yes
A quick example could be helpful as I am currently working in this.
{
flags: {
rainbow: {
type: 'boolean',
required: (input, flags) => flags.unicorn === '🦄'
}
}
}
Note, I'm not exactly sure what the function arguments should be. I'm open to suggestions there. I guess the input
and flags
. Anything else?
I also think we should call the option isRequired
, not required
.
posted by sindresorhus about 6 years ago
posted by sindresorhus about 5 years ago 
posted by issuehunt-app[bot] almost 5 years ago 
Can we get this, but for input (non-flag arguments)?
posted by NSExceptional about 3 years ago