Demonstrates how to specify a predetermined list of allowed values for arguments and flag arguments.
This example was generated with:
$ bashly init
# ... now edit src/bashly.yml to match the example ...
$ bashly generatename: login
help: Sample showing the use of arg and flag whitelist (allowed values)
version: 0.1.0
args:
- name: region
help: Region to connect to
# Whitelist + required
allowed: [eu, us]
required: true
- name: environment
help: Environment to connect to
# Whitelist + default
allowed: [stage, production, development]
default: development
flags:
- long: --user
short: -u
arg: name
help: User name
# Whitelist + required
allowed: [user, admin]
required: true
- long: --protocol
short: -p
arg: type
help: Protocol to connect with
# Whitelist + default
allowed: [ftp, ssh, http]
default: sshmissing required argument: REGION
usage: login REGION [ENVIRONMENT] [OPTIONS]
login - Sample showing the use of arg and flag whitelist (allowed values)
Usage:
login REGION [ENVIRONMENT] [OPTIONS]
login --help | -h
login --version | -v
Options:
--user, -u NAME (required)
User name
Allowed: user, admin
--protocol, -p TYPE
Protocol to connect with
Allowed: ftp, ssh, http
Default: ssh
--help, -h
Show this help
--version, -v
Show version number
Arguments:
REGION
Region to connect to
Allowed: eu, us
ENVIRONMENT
Environment to connect to
Allowed: stage, production, development
Default: development
missing required flag: --user, -u NAME
region must be one of: eu, us
--user must be one of: user, admin
# This file is located at 'src/root_command.sh'.
# It contains the implementation for the 'login' command.
# The code you write here will be wrapped by a function named 'login_command()'.
# Feel free to edit this file; your changes will persist when regenerating.
args:
- ${args[environment]} = development
- ${args[--protocol]} = ssh
- ${args[region]} = eu
- ${args[--user]} = admin
--protocol must be one of: ftp, ssh, http
# This file is located at 'src/root_command.sh'.
# It contains the implementation for the 'login' command.
# The code you write here will be wrapped by a function named 'login_command()'.
# Feel free to edit this file; your changes will persist when regenerating.
args:
- ${args[environment]} = production
- ${args[--protocol]} = ssh
- ${args[region]} = eu
- ${args[--user]} = admin