question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support `required` flags

See original GitHub issue

Issuehunt badges

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

IssueHunt Summary

sbencoding sbencoding has been rewarded.

Backers (Total: $60.00)

Submitted pull Requests


Tips

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:10
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

7reactions
sindresorhuscommented, Nov 26, 2017

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.

2reactions
SamVerschuerencommented, Oct 14, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found