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

Add support for allowed values for flags #66

Merged
merged 3 commits into from
Mar 2, 2021
Merged

Conversation

DannyBen
Copy link
Owner

@DannyBen DannyBen commented Mar 1, 2021

Closes #65


TODO:

  • Implementation
  • Second opinion test
  • Update README
  • Add example
  • Implement specs

This PR allows defining allowed: [value1, value2] for flag items

# bashly.yml
flags:
- long: --user
  short: -u
  arg: NAME
  allowed: [user, admin]
  # required: true
  default: user
  help: "User name"

This will:

Exit with an error unless the provided value is in the whitelist:

$ ./login --user asd
--user must be one of: user, admin

Show the allowed default values in the usage text:

$ ./login --help
...
Options:
  --user, -u NAME
    User name
    Allowed: user, admin
    Default: user
...

As usual, output strings are configurable.

@DannyBen DannyBen merged commit 0c737ff into master Mar 2, 2021
@DannyBen DannyBen deleted the add/flag-whitelist branch March 2, 2021 06:14
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.

[Feature] Support allowed argument values as an option
1 participant