Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Whitelist Arguments and Flag Arguments

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 generate

bashly.yml

name: 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: ssh

Output

$ ./login

missing required argument: REGION
usage: login REGION [ENVIRONMENT] [OPTIONS]

$ ./login -h

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


$ ./login america

missing required flag: --user, -u NAME

$ ./login america --user admin

region must be one of: eu, us

$ ./login eu --user hacker

--user must be one of: user, admin

$ ./login eu --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

$ ./login us --user user --protocol icmp

--protocol must be one of: ftp, ssh, http

$ ./login eu production --user admin --protocol ssh

# 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