diff --git a/examples/catch-all-advanced/cli b/examples/catch-all-advanced/cli index a1dd4234..070c6ed3 100644 --- a/examples/catch-all-advanced/cli +++ b/examples/catch-all-advanced/cli @@ -11,10 +11,12 @@ version_command() { cli_usage() { if [[ -n $long_usage ]]; then printf "cli - Sample application\n" - echo + echo + else printf "cli - Sample application\n" - echo + echo + fi printf "Usage:\n" @@ -45,10 +47,12 @@ cli_usage() { cli_download_usage() { if [[ -n $long_usage ]]; then printf "cli download - Download a file\n" - echo + echo + else printf "cli download - Download a file\n" - echo + echo + fi printf "Shortcut: d\n" @@ -72,25 +76,24 @@ cli_download_usage() { echo # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " SOURCE" printf " URL to download from\n" echo - + # :argument.usage echo " TARGET" printf " Target filename (default: same as source)\n" echo - - + echo " AWS PARAMS..." printf " Additional arguments or flags for AWS CLI\n" echo # :command.usage_examples printf "Examples:\n" - + printf " cli download example.com\n" printf " cli download example.com ./output -f\n" echo @@ -102,10 +105,12 @@ cli_download_usage() { cli_upload_usage() { if [[ -n $long_usage ]]; then printf "cli upload - Upload a file\n" - echo + echo + else printf "cli upload - Upload a file\n" - echo + echo + fi printf "Shortcut: u\n" @@ -125,7 +130,7 @@ cli_upload_usage() { # :command.usage_args printf "Arguments:\n" - + echo " FILES..." printf " Files to upload\n" echo @@ -204,43 +209,43 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter # :command.command_filter action=$1 - + case $action in -* ) ;; - + download | d ) action="download" shift cli_download_parse_requirements "$@" shift $# - ;; - + ;; + upload | u ) action="upload" shift cli_upload_parse_requirements "$@" shift $# - ;; - + ;; + # :command.command_fallback * ) cli_usage exit 1 ;; - + esac # :command.required_args_filter # :command.required_flags_filter @@ -248,18 +253,18 @@ parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -275,13 +280,13 @@ cli_download_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_download_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -305,13 +310,12 @@ cli_download_parse_requirements() { args[--force]=1 shift ;; - - + -* ) other_args+=("$1") shift ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[source]} ]]; then @@ -325,7 +329,7 @@ cli_download_parse_requirements() { shift fi ;; - + esac done # :command.catch_all_filter @@ -341,13 +345,13 @@ cli_upload_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_upload_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -359,18 +363,18 @@ cli_upload_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) other_args+=("$1") shift ;; - + * ) # :command.parse_requirements_case other_args+=("$1") shift ;; - + esac done # :command.catch_all_filter @@ -417,7 +421,7 @@ run() { else cli_download_command fi - + elif [[ $action == "upload" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -425,7 +429,7 @@ run() { else cli_upload_command fi - + elif [[ $action == "root" ]]; then root_command fi diff --git a/examples/catch-all/download b/examples/catch-all/download index b630d0ca..54f33bca 100644 --- a/examples/catch-all/download +++ b/examples/catch-all/download @@ -19,10 +19,12 @@ version_command() { download_usage() { if [[ -n $long_usage ]]; then printf "download - Catch All Example\n" - echo + echo + else printf "download - Catch All Example\n" - echo + echo + fi printf "Usage:\n" @@ -43,7 +45,7 @@ download_usage() { # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " MESSAGE" printf " Message\n" @@ -106,13 +108,13 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes download_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -131,12 +133,12 @@ parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) other_args+=("$1") shift ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[message]} ]]; then @@ -147,7 +149,7 @@ parse_requirements() { shift fi ;; - + esac done # :command.catch_all_filter diff --git a/examples/colors/colorly b/examples/colors/colorly index ccd7ef25..ce0c9921 100644 --- a/examples/colors/colorly +++ b/examples/colors/colorly @@ -6,7 +6,7 @@ root_command() { # :src/root_command.sh message=${args[message]:-hello colors} - + underlined "Message Recevied": echo echo " => $(green_bold "$message")" @@ -24,10 +24,12 @@ version_command() { colorly_usage() { if [[ -n $long_usage ]]; then printf "colorly - Sample application that uses the color functions\n" - echo + echo + else printf "colorly - Sample application that uses the color functions\n" - echo + echo + fi printf "Usage:\n" @@ -48,7 +50,7 @@ colorly_usage() { # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " MESSAGE" printf " Message to show [default: hello colors]\n" @@ -109,7 +111,8 @@ inspect_args() { # # Usage: # Use any of the functions below to color or format a portion of a string. -# +# + # echo "before $(red this is red) after" # echo "before $(green_bold this is green_bold) after" # @@ -146,13 +149,13 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes colorly_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -164,12 +167,12 @@ parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[message]} ]]; then @@ -180,7 +183,7 @@ parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter diff --git a/examples/command-default/ftp b/examples/command-default/ftp index a5f8dac9..1cc8bd0e 100644 --- a/examples/command-default/ftp +++ b/examples/command-default/ftp @@ -11,10 +11,12 @@ version_command() { ftp_usage() { if [[ -n $long_usage ]]; then printf "ftp - Sample application that uses the default command option\n" - echo + echo + else printf "ftp - Sample application that uses the default command option\n" - echo + echo + fi printf "Usage:\n" @@ -45,10 +47,12 @@ ftp_usage() { ftp_upload_usage() { if [[ -n $long_usage ]]; then printf "ftp upload - Upload a file\n" - echo + echo + else printf "ftp upload - Upload a file\n" - echo + echo + fi printf "Shortcut: u\n" @@ -68,7 +72,7 @@ ftp_upload_usage() { # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " SOURCE" printf " File to upload\n" @@ -81,10 +85,12 @@ ftp_upload_usage() { ftp_download_usage() { if [[ -n $long_usage ]]; then printf "ftp download - Download a file\n" - echo + echo + else printf "ftp download - Download a file\n" - echo + echo + fi printf "Shortcut: d\n" @@ -104,7 +110,7 @@ ftp_download_usage() { # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " SOURCE" printf " File to download\n" @@ -184,49 +190,49 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes ftp_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter # :command.command_filter action=$1 - + case $action in -* ) ;; - + upload | u ) action="upload" shift ftp_upload_parse_requirements "$@" shift $# - ;; - + ;; + download | d ) action="download" shift ftp_download_parse_requirements "$@" shift $# - ;; - + ;; + # :command.command_fallback "" ) ftp_usage exit 1 ;; - + * ) action="upload" ftp_upload_parse_requirements "$@" shift $# ;; - + esac # :command.required_args_filter # :command.required_flags_filter @@ -234,18 +240,18 @@ parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -261,13 +267,13 @@ ftp_upload_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes ftp_upload_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -286,12 +292,12 @@ ftp_upload_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[source]} ]]; then @@ -302,7 +308,7 @@ ftp_upload_parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter @@ -318,13 +324,13 @@ ftp_download_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes ftp_download_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -343,12 +349,12 @@ ftp_download_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[source]} ]]; then @@ -359,7 +365,7 @@ ftp_download_parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter @@ -402,7 +408,7 @@ run() { else ftp_upload_command fi - + elif [[ $action == "download" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -410,7 +416,7 @@ run() { else ftp_download_command fi - + elif [[ $action == "root" ]]; then root_command fi diff --git a/examples/command-groups/ftp b/examples/command-groups/ftp index 56c6d147..5e934b94 100644 --- a/examples/command-groups/ftp +++ b/examples/command-groups/ftp @@ -11,10 +11,12 @@ version_command() { ftp_usage() { if [[ -n $long_usage ]]; then printf "ftp - Sample application with command grouping\n" - echo + echo + else printf "ftp - Sample application with command grouping\n" - echo + echo + fi printf "Usage:\n" @@ -48,10 +50,12 @@ ftp_usage() { ftp_download_usage() { if [[ -n $long_usage ]]; then printf "ftp download - Download a file\n" - echo + echo + else printf "ftp download - Download a file\n" - echo + echo + fi printf "Usage:\n" @@ -68,7 +72,7 @@ ftp_download_usage() { # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " FILE" printf " File to download\n" @@ -81,10 +85,12 @@ ftp_download_usage() { ftp_upload_usage() { if [[ -n $long_usage ]]; then printf "ftp upload - Upload a file\n" - echo + echo + else printf "ftp upload - Upload a file\n" - echo + echo + fi printf "Usage:\n" @@ -101,7 +107,7 @@ ftp_upload_usage() { # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " FILE" printf " File to upload\n" @@ -114,10 +120,12 @@ ftp_upload_usage() { ftp_login_usage() { if [[ -n $long_usage ]]; then printf "ftp login - Write login credentials to the config file\n" - echo + echo + else printf "ftp login - Write login credentials to the config file\n" - echo + echo + fi printf "Usage:\n" @@ -139,10 +147,12 @@ ftp_login_usage() { ftp_logout_usage() { if [[ -n $long_usage ]]; then printf "ftp logout - Delete login credentials to the config file\n" - echo + echo + else printf "ftp logout - Delete login credentials to the config file\n" - echo + echo + fi printf "Usage:\n" @@ -249,57 +259,57 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes ftp_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter # :command.command_filter action=$1 - + case $action in -* ) ;; - + download ) action="download" shift ftp_download_parse_requirements "$@" shift $# - ;; - + ;; + upload ) action="upload" shift ftp_upload_parse_requirements "$@" shift $# - ;; - + ;; + login ) action="login" shift ftp_login_parse_requirements "$@" shift $# - ;; - + ;; + logout ) action="logout" shift ftp_logout_parse_requirements "$@" shift $# - ;; - + ;; + # :command.command_fallback * ) ftp_usage exit 1 ;; - + esac # :command.required_args_filter # :command.required_flags_filter @@ -307,18 +317,18 @@ parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -334,13 +344,13 @@ ftp_download_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes ftp_download_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -359,12 +369,12 @@ ftp_download_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[file]} ]]; then @@ -375,7 +385,7 @@ ftp_download_parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter @@ -391,13 +401,13 @@ ftp_upload_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes ftp_upload_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -416,12 +426,12 @@ ftp_upload_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[file]} ]]; then @@ -432,7 +442,7 @@ ftp_upload_parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter @@ -448,13 +458,13 @@ ftp_login_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes ftp_login_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -466,18 +476,18 @@ ftp_login_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -493,13 +503,13 @@ ftp_logout_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes ftp_logout_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -511,18 +521,18 @@ ftp_logout_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -565,7 +575,7 @@ run() { else ftp_download_command fi - + elif [[ $action == "upload" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -573,7 +583,7 @@ run() { else ftp_upload_command fi - + elif [[ $action == "login" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -581,7 +591,7 @@ run() { else ftp_login_command fi - + elif [[ $action == "logout" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -589,7 +599,7 @@ run() { else ftp_logout_command fi - + elif [[ $action == "root" ]]; then root_command fi diff --git a/examples/commands-nested/cli b/examples/commands-nested/cli index fd13a88f..078b6801 100644 --- a/examples/commands-nested/cli +++ b/examples/commands-nested/cli @@ -11,10 +11,12 @@ version_command() { cli_usage() { if [[ -n $long_usage ]]; then printf "cli - Sample application with nested commands\n" - echo + echo + else printf "cli - Sample application with nested commands\n" - echo + echo + fi printf "Usage:\n" @@ -45,10 +47,12 @@ cli_usage() { cli_dir_usage() { if [[ -n $long_usage ]]; then printf "cli dir - Directory commands\n" - echo + echo + else printf "cli dir - Directory commands\n" - echo + echo + fi printf "Shortcut: d\n" @@ -78,10 +82,12 @@ cli_dir_usage() { cli_dir_list_usage() { if [[ -n $long_usage ]]; then printf "cli dir list - Show files in the directory\n" - echo + echo + else printf "cli dir list - Show files in the directory\n" - echo + echo + fi printf "Usage:\n" @@ -98,7 +104,7 @@ cli_dir_list_usage() { # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " PATH" printf " Directory path\n" @@ -111,10 +117,12 @@ cli_dir_list_usage() { cli_dir_remove_usage() { if [[ -n $long_usage ]]; then printf "cli dir remove - Remove directory\n" - echo + echo + else printf "cli dir remove - Remove directory\n" - echo + echo + fi printf "Usage:\n" @@ -135,7 +143,7 @@ cli_dir_remove_usage() { echo # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " PATH" printf " Directory path\n" @@ -148,10 +156,12 @@ cli_dir_remove_usage() { cli_file_usage() { if [[ -n $long_usage ]]; then printf "cli file - File commands\n" - echo + echo + else printf "cli file - File commands\n" - echo + echo + fi printf "Shortcut: f\n" @@ -181,10 +191,12 @@ cli_file_usage() { cli_file_show_usage() { if [[ -n $long_usage ]]; then printf "cli file show - Show file contents\n" - echo + echo + else printf "cli file show - Show file contents\n" - echo + echo + fi printf "Usage:\n" @@ -201,7 +213,7 @@ cli_file_show_usage() { # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " PATH" printf " Path to file\n" @@ -214,10 +226,12 @@ cli_file_show_usage() { cli_file_edit_usage() { if [[ -n $long_usage ]]; then printf "cli file edit - Edit the file\n" - echo + echo + else printf "cli file edit - Edit the file\n" - echo + echo + fi printf "Usage:\n" @@ -234,7 +248,7 @@ cli_file_edit_usage() { # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " PATH" printf " Path to file\n" @@ -333,43 +347,43 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter # :command.command_filter action=$1 - + case $action in -* ) ;; - + dir | d ) action="dir" shift cli_dir_parse_requirements "$@" shift $# - ;; - + ;; + file | f ) action="file" shift cli_file_parse_requirements "$@" shift $# - ;; - + ;; + # :command.command_fallback * ) cli_usage exit 1 ;; - + esac # :command.required_args_filter # :command.required_flags_filter @@ -377,18 +391,18 @@ parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -404,43 +418,43 @@ cli_dir_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_dir_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter # :command.command_filter action=$1 - + case $action in -* ) ;; - + list ) action="list" shift cli_dir_list_parse_requirements "$@" shift $# - ;; - + ;; + remove ) action="remove" shift cli_dir_remove_parse_requirements "$@" shift $# - ;; - + ;; + # :command.command_fallback * ) cli_dir_usage exit 1 ;; - + esac # :command.required_args_filter # :command.required_flags_filter @@ -448,18 +462,18 @@ cli_dir_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -475,13 +489,13 @@ cli_dir_list_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_dir_list_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -500,12 +514,12 @@ cli_dir_list_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[path]} ]]; then @@ -516,7 +530,7 @@ cli_dir_list_parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter @@ -532,13 +546,13 @@ cli_dir_remove_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_dir_remove_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -562,13 +576,12 @@ cli_dir_remove_parse_requirements() { args[--force]=1 shift ;; - - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[path]} ]]; then @@ -579,7 +592,7 @@ cli_dir_remove_parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter @@ -595,43 +608,43 @@ cli_file_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_file_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter # :command.command_filter action=$1 - + case $action in -* ) ;; - + show ) action="show" shift cli_file_show_parse_requirements "$@" shift $# - ;; - + ;; + edit ) action="edit" shift cli_file_edit_parse_requirements "$@" shift $# - ;; - + ;; + # :command.command_fallback * ) cli_file_usage exit 1 ;; - + esac # :command.required_args_filter # :command.required_flags_filter @@ -639,18 +652,18 @@ cli_file_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -666,13 +679,13 @@ cli_file_show_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_file_show_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -691,12 +704,12 @@ cli_file_show_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[path]} ]]; then @@ -707,7 +720,7 @@ cli_file_show_parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter @@ -723,13 +736,13 @@ cli_file_edit_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_file_edit_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -748,12 +761,12 @@ cli_file_edit_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[path]} ]]; then @@ -764,7 +777,7 @@ cli_file_edit_parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter @@ -807,7 +820,7 @@ run() { else cli_dir_command fi - + elif [[ $action == "dir list" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -815,7 +828,7 @@ run() { else cli_dir_list_command fi - + elif [[ $action == "dir remove" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -823,7 +836,7 @@ run() { else cli_dir_remove_command fi - + elif [[ $action == "file" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -831,7 +844,7 @@ run() { else cli_file_command fi - + elif [[ $action == "file show" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -839,7 +852,7 @@ run() { else cli_file_show_command fi - + elif [[ $action == "file edit" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -847,7 +860,7 @@ run() { else cli_file_edit_command fi - + elif [[ $action == "root" ]]; then root_command fi diff --git a/examples/commands/cli b/examples/commands/cli index ad5be3fe..ebca4aae 100644 --- a/examples/commands/cli +++ b/examples/commands/cli @@ -11,10 +11,12 @@ version_command() { cli_usage() { if [[ -n $long_usage ]]; then printf "cli - Sample application\n" - echo + echo + else printf "cli - Sample application\n" - echo + echo + fi printf "Usage:\n" @@ -40,7 +42,7 @@ cli_usage() { # :command.usage_environment_variables printf "Environment Variables:\n" - + # :environment_variable.usage echo " API_KEY" printf " Set your API key\n" @@ -53,10 +55,12 @@ cli_usage() { cli_download_usage() { if [[ -n $long_usage ]]; then printf "cli download - Download a file\n" - echo + echo + else printf "cli download - Download a file\n" - echo + echo + fi printf "Shortcut: d\n" @@ -80,26 +84,26 @@ cli_download_usage() { echo # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " SOURCE" printf " URL to download from\n" echo - + # :argument.usage echo " TARGET" printf " Target filename (default: same as source)\n" echo # :command.usage_environment_variables printf "Environment Variables:\n" - + # :environment_variable.usage echo " DEFAULT_TARGET_LOCATION" printf " Set the default location to download to\n" echo # :command.usage_examples printf "Examples:\n" - + printf " cli download example.com\n" printf " cli download example.com ./output -f\n" echo @@ -111,10 +115,12 @@ cli_download_usage() { cli_upload_usage() { if [[ -n $long_usage ]]; then printf "cli upload - Upload a file\n" - echo + echo + else printf "cli upload - Upload a file\n" - echo + echo + fi printf "Shortcut: u\n" @@ -136,14 +142,14 @@ cli_upload_usage() { echo " --user, -u USER (required)" printf " Username to use for logging in\n" echo - + # :flag.usage echo " --password, -p PASSWORD" printf " Password to use for logging in\n" echo # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " SOURCE" printf " File to upload\n" @@ -223,43 +229,43 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter # :command.command_filter action=$1 - + case $action in -* ) ;; - + download | d ) action="download" shift cli_download_parse_requirements "$@" shift $# - ;; - + ;; + upload | u ) action="upload" shift cli_upload_parse_requirements "$@" shift $# - ;; - + ;; + # :command.command_fallback * ) cli_usage exit 1 ;; - + esac # :command.required_args_filter # :command.required_flags_filter @@ -267,18 +273,18 @@ parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -294,13 +300,13 @@ cli_download_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_download_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -324,13 +330,12 @@ cli_download_parse_requirements() { args[--force]=1 shift ;; - - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[source]} ]]; then @@ -344,7 +349,7 @@ cli_download_parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter @@ -360,13 +365,13 @@ cli_upload_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_upload_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -401,7 +406,7 @@ cli_upload_parse_requirements() { exit 1 fi ;; - + # :flag.case --password | -p ) if [[ $2 ]]; then @@ -413,13 +418,12 @@ cli_upload_parse_requirements() { exit 1 fi ;; - - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[source]} ]]; then @@ -430,7 +434,7 @@ cli_upload_parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter @@ -473,7 +477,7 @@ run() { else cli_download_command fi - + elif [[ $action == "upload" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -481,7 +485,7 @@ run() { else cli_upload_command fi - + elif [[ $action == "root" ]]; then root_command fi diff --git a/examples/completions/cli b/examples/completions/cli index cf6caa36..70377279 100644 --- a/examples/completions/cli +++ b/examples/completions/cli @@ -11,10 +11,12 @@ version_command() { cli_usage() { if [[ -n $long_usage ]]; then printf "cli - Sample application with bash completions\n" - echo + echo + else printf "cli - Sample application with bash completions\n" - echo + echo + fi printf "Usage:\n" @@ -46,12 +48,15 @@ cli_usage() { cli_completions_usage() { if [[ -n $long_usage ]]; then printf "cli completions\n" - echo + echo + printf " Generate bash completions\n Usage: eval \"\$(cli completions)\"\n" - echo + echo + else printf "cli completions - Generate bash completions\n" - echo + echo + fi printf "Usage:\n" @@ -73,10 +78,12 @@ cli_completions_usage() { cli_download_usage() { if [[ -n $long_usage ]]; then printf "cli download - Download a file\n" - echo + echo + else printf "cli download - Download a file\n" - echo + echo + fi printf "Shortcut: d\n" @@ -100,26 +107,26 @@ cli_download_usage() { echo # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " SOURCE" printf " URL to download from\n" echo - + # :argument.usage echo " TARGET" printf " Target filename (default: same as source)\n" echo # :command.usage_environment_variables printf "Environment Variables:\n" - + # :environment_variable.usage echo " DEFAULT_TARGET_LOCATION" printf " Set the default location to download to\n" echo # :command.usage_examples printf "Examples:\n" - + printf " cli download example.com\n" printf " cli download example.com ./output -f\n" echo @@ -131,10 +138,12 @@ cli_download_usage() { cli_upload_usage() { if [[ -n $long_usage ]]; then printf "cli upload - Upload a file\n" - echo + echo + else printf "cli upload - Upload a file\n" - echo + echo + fi printf "Shortcut: u\n" @@ -156,14 +165,14 @@ cli_upload_usage() { echo " --user, -u USER (required)" printf " Username to use for logging in\n" echo - + # :flag.usage echo " --password, -p PASSWORD" printf " Password to use for logging in\n" echo # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " SOURCE" printf " File to upload\n" @@ -280,50 +289,50 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter # :command.command_filter action=$1 - + case $action in -* ) ;; - + completions ) action="completions" shift cli_completions_parse_requirements "$@" shift $# - ;; - + ;; + download | d ) action="download" shift cli_download_parse_requirements "$@" shift $# - ;; - + ;; + upload | u ) action="upload" shift cli_upload_parse_requirements "$@" shift $# - ;; - + ;; + # :command.command_fallback * ) cli_usage exit 1 ;; - + esac # :command.required_args_filter # :command.required_flags_filter @@ -331,18 +340,18 @@ parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -358,13 +367,13 @@ cli_completions_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_completions_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -376,18 +385,18 @@ cli_completions_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -403,13 +412,13 @@ cli_download_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_download_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -433,13 +442,12 @@ cli_download_parse_requirements() { args[--force]=1 shift ;; - - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[source]} ]]; then @@ -453,7 +461,7 @@ cli_download_parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter @@ -469,13 +477,13 @@ cli_upload_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_upload_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -510,7 +518,7 @@ cli_upload_parse_requirements() { exit 1 fi ;; - + # :flag.case --password | -p ) if [[ $2 ]]; then @@ -522,13 +530,12 @@ cli_upload_parse_requirements() { exit 1 fi ;; - - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[source]} ]]; then @@ -539,7 +546,7 @@ cli_upload_parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter @@ -582,7 +589,7 @@ run() { else cli_completions_command fi - + elif [[ $action == "download" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -590,7 +597,7 @@ run() { else cli_download_command fi - + elif [[ $action == "upload" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -598,7 +605,7 @@ run() { else cli_upload_command fi - + elif [[ $action == "root" ]]; then root_command fi diff --git a/examples/config-ini/configly b/examples/config-ini/configly index c4740b2a..ef4aad52 100644 --- a/examples/config-ini/configly +++ b/examples/config-ini/configly @@ -11,10 +11,12 @@ version_command() { configly_usage() { if [[ -n $long_usage ]]; then printf "configly - Sample application that uses the config functions\n" - echo + echo + else printf "configly - Sample application that uses the config functions\n" - echo + echo + fi printf "Usage:\n" @@ -46,10 +48,12 @@ configly_usage() { configly_set_usage() { if [[ -n $long_usage ]]; then printf "configly set - Save a value in the config file\n" - echo + echo + else printf "configly set - Save a value in the config file\n" - echo + echo + fi printf "Shortcut: s\n" @@ -69,12 +73,12 @@ configly_set_usage() { # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " KEY" printf " Config key\n" echo - + # :argument.usage echo " VALUE" printf " Config value\n" @@ -82,7 +86,7 @@ configly_set_usage() { # :command.usage_examples printf "Examples:\n" - + printf " configly set hello world\n" echo @@ -93,10 +97,12 @@ configly_set_usage() { configly_get_usage() { if [[ -n $long_usage ]]; then printf "configly get - Read a value from the config file\n" - echo + echo + else printf "configly get - Read a value from the config file\n" - echo + echo + fi printf "Shortcut: g\n" @@ -116,7 +122,7 @@ configly_get_usage() { # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " KEY" printf " Config key\n" @@ -124,7 +130,7 @@ configly_get_usage() { # :command.usage_examples printf "Examples:\n" - + printf " configly set hello\n" echo @@ -135,10 +141,12 @@ configly_get_usage() { configly_list_usage() { if [[ -n $long_usage ]]; then printf "configly list - Show the entire config file\n" - echo + echo + else printf "configly list - Show the entire config file\n" - echo + echo + fi printf "Shortcut: l\n" @@ -231,7 +239,7 @@ config_get() { regex="^$key\s*=\s*(.+)$" config_init - + while IFS= read -r line || [ -n "$line" ]; do if [[ $line =~ $regex ]]; then value="${BASH_REMATCH[1]}" @@ -254,7 +262,7 @@ config_set() { regex="^($key)\s*=\s*.+$" output="" found_key="" - + while IFS= read -r line || [ -n "$line" ]; do newline=$line if [[ $line =~ $regex ]]; then @@ -345,14 +353,15 @@ configly_set_command() { configly_get_command() { # :src/get_command.sh # Using the standard library (lib/config.sh) to show a value from the config - + key="${args[key]}" - if config_has_key "$key" ; then + if config_has_key "$key" ; then + config_get "$key" else echo "No such key: $key" fi - + # Example of how to assign the config value to a variable: # result=$(config_get "${args[key]}") # echo $result @@ -363,7 +372,7 @@ configly_list_command() { # :src/list_command.sh # Using the standard library (lib/config.sh) to show the entire config file config_show - + # Or to iterate through keys for key in $(config_keys) ; do echo "$key === $(config_get "$key")" @@ -378,50 +387,50 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes configly_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter # :command.command_filter action=$1 - + case $action in -* ) ;; - + set | s ) action="set" shift configly_set_parse_requirements "$@" shift $# - ;; - + ;; + get | g ) action="get" shift configly_get_parse_requirements "$@" shift $# - ;; - + ;; + list | l ) action="list" shift configly_list_parse_requirements "$@" shift $# - ;; - + ;; + # :command.command_fallback * ) configly_usage exit 1 ;; - + esac # :command.required_args_filter # :command.required_flags_filter @@ -429,18 +438,18 @@ parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -456,13 +465,13 @@ configly_set_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes configly_set_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -476,7 +485,7 @@ configly_set_parse_requirements() { printf "missing required argument: KEY\nusage: configly set KEY VALUE\n" exit 1 fi - + if [[ $1 && $1 != -* ]]; then args[value]=$1 shift @@ -489,12 +498,12 @@ configly_set_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[key]} ]]; then @@ -508,7 +517,7 @@ configly_set_parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter @@ -524,13 +533,13 @@ configly_get_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes configly_get_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -549,12 +558,12 @@ configly_get_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[key]} ]]; then @@ -565,7 +574,7 @@ configly_get_parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter @@ -581,13 +590,13 @@ configly_list_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes configly_list_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -599,18 +608,18 @@ configly_list_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -653,7 +662,7 @@ run() { else configly_set_command fi - + elif [[ $action == "get" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -661,7 +670,7 @@ run() { else configly_get_command fi - + elif [[ $action == "list" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -669,7 +678,7 @@ run() { else configly_list_command fi - + elif [[ $action == "root" ]]; then root_command fi diff --git a/examples/custom-includes/download b/examples/custom-includes/download index d449ff95..70f562b0 100644 --- a/examples/custom-includes/download +++ b/examples/custom-includes/download @@ -20,10 +20,12 @@ version_command() { download_usage() { if [[ -n $long_usage ]]; then printf "download - Sample minimal application with custom strings\n" - echo + echo + else printf "download - Sample minimal application with custom strings\n" - echo + echo + fi printf "Usage:\n" @@ -44,7 +46,7 @@ download_usage() { # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " SOURCE" printf " URL to download from\n" @@ -123,13 +125,13 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes download_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -141,12 +143,12 @@ parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[source]} ]]; then @@ -157,7 +159,7 @@ parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter diff --git a/examples/custom-strings/download b/examples/custom-strings/download index 698aa487..94c77334 100644 --- a/examples/custom-strings/download +++ b/examples/custom-strings/download @@ -19,10 +19,12 @@ version_command() { download_usage() { if [[ -n $long_usage ]]; then printf "download - Sample minimal application with custom strings\n" - echo + echo + else printf "download - Sample minimal application with custom strings\n" - echo + echo + fi printf "== Usage ==\n\n" @@ -47,7 +49,7 @@ download_usage() { echo # :command.usage_args printf "== Arguments ==\n\n" - + # :argument.usage echo " SOURCE" printf " URL to download from\n" @@ -110,13 +112,13 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes download_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -151,13 +153,12 @@ parse_requirements() { exit 1 fi ;; - - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[source]} ]]; then @@ -168,7 +169,7 @@ parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter diff --git a/examples/default-values/convert b/examples/default-values/convert index a450b972..b0bc81f3 100644 --- a/examples/default-values/convert +++ b/examples/default-values/convert @@ -19,10 +19,12 @@ version_command() { convert_usage() { if [[ -n $long_usage ]]; then printf "convert - Sample application using default arguments and flags\n" - echo + echo + else printf "convert - Sample application using default arguments and flags\n" - echo + echo + fi printf "Usage:\n" @@ -48,7 +50,7 @@ convert_usage() { echo # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " SOURCE" printf " Files to convert\n" @@ -57,7 +59,7 @@ convert_usage() { # :command.usage_examples printf "Examples:\n" - + printf " convert *.bmp\n" printf " convert --format jpg\n" printf " convert *.bmp --format jpg\n" @@ -120,13 +122,13 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes convert_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -149,13 +151,12 @@ parse_requirements() { exit 1 fi ;; - - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[source]} ]]; then @@ -166,7 +167,7 @@ parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter diff --git a/examples/dependencies/cli b/examples/dependencies/cli index 696ffb05..5260bbe8 100644 --- a/examples/dependencies/cli +++ b/examples/dependencies/cli @@ -11,10 +11,12 @@ version_command() { cli_usage() { if [[ -n $long_usage ]]; then printf "cli - Sample application that requires dependencies\n" - echo + echo + else printf "cli - Sample application that requires dependencies\n" - echo + echo + fi printf "Usage:\n" @@ -45,10 +47,12 @@ cli_usage() { cli_download_usage() { if [[ -n $long_usage ]]; then printf "cli download - Download something\n" - echo + echo + else printf "cli download - Download something\n" - echo + echo + fi printf "Usage:\n" @@ -70,10 +74,12 @@ cli_download_usage() { cli_upload_usage() { if [[ -n $long_usage ]]; then printf "cli upload - Upload something\n" - echo + echo + else printf "cli upload - Upload something\n" - echo + echo + fi printf "Usage:\n" @@ -162,43 +168,43 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter # :command.command_filter action=$1 - + case $action in -* ) ;; - + download ) action="download" shift cli_download_parse_requirements "$@" shift $# - ;; - + ;; + upload ) action="upload" shift cli_upload_parse_requirements "$@" shift $# - ;; - + ;; + # :command.command_fallback * ) cli_usage exit 1 ;; - + esac # :command.required_args_filter # :command.required_flags_filter @@ -206,18 +212,18 @@ parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -233,13 +239,13 @@ cli_download_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_download_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -263,18 +269,18 @@ cli_download_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -290,13 +296,13 @@ cli_upload_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_upload_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -308,18 +314,18 @@ cli_upload_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -362,7 +368,7 @@ run() { else cli_download_command fi - + elif [[ $action == "upload" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -370,7 +376,7 @@ run() { else cli_upload_command fi - + elif [[ $action == "root" ]]; then root_command fi diff --git a/examples/docker-like/docker b/examples/docker-like/docker index f09d3d58..d18cd131 100644 --- a/examples/docker-like/docker +++ b/examples/docker-like/docker @@ -11,10 +11,12 @@ version_command() { docker_usage() { if [[ -n $long_usage ]]; then printf "docker - Docker example\n" - echo + echo + else printf "docker - Docker example\n" - echo + echo + fi printf "Usage:\n" @@ -45,10 +47,12 @@ docker_usage() { docker_container_usage() { if [[ -n $long_usage ]]; then printf "docker container - Container commands\n" - echo + echo + else printf "docker container - Container commands\n" - echo + echo + fi printf "Shortcut: c*\n" @@ -78,10 +82,12 @@ docker_container_usage() { docker_container_run_usage() { if [[ -n $long_usage ]]; then printf "docker container run - Run a container\n" - echo + echo + else printf "docker container run - Run a container\n" - echo + echo + fi printf "Usage:\n" @@ -98,7 +104,7 @@ docker_container_run_usage() { # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " IMAGE" printf " Image name\n" @@ -111,10 +117,12 @@ docker_container_run_usage() { docker_container_stop_usage() { if [[ -n $long_usage ]]; then printf "docker container stop - Stop a container\n" - echo + echo + else printf "docker container stop - Stop a container\n" - echo + echo + fi printf "Usage:\n" @@ -131,7 +139,7 @@ docker_container_stop_usage() { # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " CONTAINER" printf " Container name\n" @@ -144,10 +152,12 @@ docker_container_stop_usage() { docker_image_usage() { if [[ -n $long_usage ]]; then printf "docker image - Image commands\n" - echo + echo + else printf "docker image - Image commands\n" - echo + echo + fi printf "Shortcut: i*\n" @@ -176,10 +186,12 @@ docker_image_usage() { docker_image_ls_usage() { if [[ -n $long_usage ]]; then printf "docker image ls - Show all images\n" - echo + echo + else printf "docker image ls - Show all images\n" - echo + echo + fi printf "Shortcut: l\n" @@ -281,43 +293,43 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes docker_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter # :command.command_filter action=$1 - + case $action in -* ) ;; - + container | c* ) action="container" shift docker_container_parse_requirements "$@" shift $# - ;; - + ;; + image | i* ) action="image" shift docker_image_parse_requirements "$@" shift $# - ;; - + ;; + # :command.command_fallback * ) docker_usage exit 1 ;; - + esac # :command.required_args_filter # :command.required_flags_filter @@ -325,18 +337,18 @@ parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -352,43 +364,43 @@ docker_container_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes docker_container_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter # :command.command_filter action=$1 - + case $action in -* ) ;; - + run ) action="run" shift docker_container_run_parse_requirements "$@" shift $# - ;; - + ;; + stop ) action="stop" shift docker_container_stop_parse_requirements "$@" shift $# - ;; - + ;; + # :command.command_fallback * ) docker_container_usage exit 1 ;; - + esac # :command.required_args_filter # :command.required_flags_filter @@ -396,18 +408,18 @@ docker_container_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -423,13 +435,13 @@ docker_container_run_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes docker_container_run_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -448,12 +460,12 @@ docker_container_run_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[image]} ]]; then @@ -464,7 +476,7 @@ docker_container_run_parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter @@ -480,13 +492,13 @@ docker_container_stop_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes docker_container_stop_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -505,12 +517,12 @@ docker_container_stop_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[container]} ]]; then @@ -521,7 +533,7 @@ docker_container_stop_parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter @@ -537,36 +549,36 @@ docker_image_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes docker_image_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter # :command.command_filter action=$1 - + case $action in -* ) ;; - + ls | l ) action="ls" shift docker_image_ls_parse_requirements "$@" shift $# - ;; - + ;; + # :command.command_fallback * ) docker_image_usage exit 1 ;; - + esac # :command.required_args_filter # :command.required_flags_filter @@ -574,18 +586,18 @@ docker_image_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -601,13 +613,13 @@ docker_image_ls_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes docker_image_ls_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -619,18 +631,18 @@ docker_image_ls_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -673,7 +685,7 @@ run() { else docker_container_command fi - + elif [[ $action == "container run" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -681,7 +693,7 @@ run() { else docker_container_run_command fi - + elif [[ $action == "container stop" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -689,7 +701,7 @@ run() { else docker_container_stop_command fi - + elif [[ $action == "image" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -697,7 +709,7 @@ run() { else docker_image_command fi - + elif [[ $action == "image ls" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -705,7 +717,7 @@ run() { else docker_image_ls_command fi - + elif [[ $action == "root" ]]; then root_command fi diff --git a/examples/environment-variables/cli b/examples/environment-variables/cli index 6c1167ed..11616f06 100644 --- a/examples/environment-variables/cli +++ b/examples/environment-variables/cli @@ -11,10 +11,12 @@ version_command() { cli_usage() { if [[ -n $long_usage ]]; then printf "cli - Sample application that requires environment variables\n" - echo + echo + else printf "cli - Sample application that requires environment variables\n" - echo + echo + fi printf "Usage:\n" @@ -39,7 +41,7 @@ cli_usage() { # :command.usage_environment_variables printf "Environment Variables:\n" - + # :environment_variable.usage echo " API_KEY" printf " Set your API key\n" @@ -52,10 +54,12 @@ cli_usage() { cli_verify_usage() { if [[ -n $long_usage ]]; then printf "cli verify - Verify your user\n" - echo + echo + else printf "cli verify - Verify your user\n" - echo + echo + fi printf "Shortcut: v\n" @@ -75,12 +79,12 @@ cli_verify_usage() { # :command.usage_environment_variables printf "Environment Variables:\n" - + # :environment_variable.usage echo " MY_SECRET (required)" printf " Your secret\n" echo - + # :environment_variable.usage echo " ENVIRONMENT" printf " One of development, production or test\n" @@ -142,7 +146,7 @@ cli_verify_command() { echo "# code for 'cli verify' goes here" echo "# you can edit it freely and regenerate (it will not be overwritten)" inspect_args - + echo "environment:" echo "- API_KEY=$API_KEY" echo "- ENVIRONMENT=$ENVIRONMENT" @@ -157,36 +161,36 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter # :command.command_filter action=$1 - + case $action in -* ) ;; - + verify | v ) action="verify" shift cli_verify_parse_requirements "$@" shift $# - ;; - + ;; + # :command.command_fallback * ) cli_usage exit 1 ;; - + esac # :command.required_args_filter # :command.required_flags_filter @@ -194,18 +198,18 @@ parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -221,13 +225,13 @@ cli_verify_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_verify_usage exit ;; - + esac # :command.environment_variables_filter export ENVIRONMENT="${ENVIRONMENT:-development}" @@ -244,18 +248,18 @@ cli_verify_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -298,7 +302,7 @@ run() { else cli_verify_command fi - + elif [[ $action == "root" ]]; then root_command fi diff --git a/examples/extensible-delegate/mygit b/examples/extensible-delegate/mygit index e757d851..ac637726 100644 --- a/examples/extensible-delegate/mygit +++ b/examples/extensible-delegate/mygit @@ -11,10 +11,12 @@ version_command() { mygit_usage() { if [[ -n $long_usage ]]; then printf "mygit - Sample application that delegates unknown commands to a different executable\n" - echo + echo + else printf "mygit - Sample application that delegates unknown commands to a different executable\n" - echo + echo + fi printf "Usage:\n" @@ -45,10 +47,12 @@ mygit_usage() { mygit_push_usage() { if [[ -n $long_usage ]]; then printf "mygit push - Push to my repository\n" - echo + echo + else printf "mygit push - Push to my repository\n" - echo + echo + fi printf "Shortcut: p\n" @@ -73,10 +77,12 @@ mygit_push_usage() { mygit_pull_usage() { if [[ -n $long_usage ]]; then printf "mygit pull - Pull from my repository\n" - echo + echo + else printf "mygit pull - Pull from my repository\n" - echo + echo + fi printf "Shortcut: l\n" @@ -168,43 +174,43 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes mygit_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter # :command.command_filter action=$1 - + case $action in -* ) ;; - + push | p ) action="push" shift mygit_push_parse_requirements "$@" shift $# - ;; - + ;; + pull | l ) action="pull" shift mygit_pull_parse_requirements "$@" shift $# - ;; - + ;; + # :command.command_fallback "" ) mygit_usage exit 1 ;; - + * ) if [[ -x "$(command -v "git")" ]]; then exec git "$@" @@ -212,7 +218,7 @@ parse_requirements() { mygit_usage exit 1 fi - + esac # :command.required_args_filter # :command.required_flags_filter @@ -220,18 +226,18 @@ parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -247,13 +253,13 @@ mygit_push_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes mygit_push_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -265,18 +271,18 @@ mygit_push_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -292,13 +298,13 @@ mygit_pull_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes mygit_pull_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -310,18 +316,18 @@ mygit_pull_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -364,7 +370,7 @@ run() { else mygit_push_command fi - + elif [[ $action == "pull" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -372,7 +378,7 @@ run() { else mygit_pull_command fi - + elif [[ $action == "root" ]]; then root_command fi diff --git a/examples/extensible/cli b/examples/extensible/cli index adb5503e..dd58fa47 100644 --- a/examples/extensible/cli +++ b/examples/extensible/cli @@ -11,10 +11,12 @@ version_command() { cli_usage() { if [[ -n $long_usage ]]; then printf "cli - Sample application that can be externally extended\n" - echo + echo + else printf "cli - Sample application that can be externally extended\n" - echo + echo + fi printf "Usage:\n" @@ -45,10 +47,12 @@ cli_usage() { cli_upload_usage() { if [[ -n $long_usage ]]; then printf "cli upload - Upload a file\n" - echo + echo + else printf "cli upload - Upload a file\n" - echo + echo + fi printf "Shortcut: u\n" @@ -68,7 +72,7 @@ cli_upload_usage() { # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " SOURCE" printf " File to upload\n" @@ -81,10 +85,12 @@ cli_upload_usage() { cli_download_usage() { if [[ -n $long_usage ]]; then printf "cli download - Download a file\n" - echo + echo + else printf "cli download - Download a file\n" - echo + echo + fi printf "Shortcut: d\n" @@ -104,7 +110,7 @@ cli_download_usage() { # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " SOURCE" printf " File to download\n" @@ -184,43 +190,43 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter # :command.command_filter action=$1 - + case $action in -* ) ;; - + upload | u ) action="upload" shift cli_upload_parse_requirements "$@" shift $# - ;; - + ;; + download | d ) action="download" shift cli_download_parse_requirements "$@" shift $# - ;; - + ;; + # :command.command_fallback "" ) cli_usage exit 1 ;; - + * ) if [[ -x "$(command -v "cli-$action")" ]]; then shift @@ -229,7 +235,7 @@ parse_requirements() { cli_usage exit 1 fi - + esac # :command.required_args_filter # :command.required_flags_filter @@ -237,18 +243,18 @@ parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -264,13 +270,13 @@ cli_upload_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_upload_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -289,12 +295,12 @@ cli_upload_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[source]} ]]; then @@ -305,7 +311,7 @@ cli_upload_parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter @@ -321,13 +327,13 @@ cli_download_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes cli_download_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -346,12 +352,12 @@ cli_download_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[source]} ]]; then @@ -362,7 +368,7 @@ cli_download_parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter @@ -405,7 +411,7 @@ run() { else cli_upload_command fi - + elif [[ $action == "download" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -413,7 +419,7 @@ run() { else cli_download_command fi - + elif [[ $action == "root" ]]; then root_command fi diff --git a/examples/footer/download b/examples/footer/download index a9b8a77c..1f34a761 100644 --- a/examples/footer/download +++ b/examples/footer/download @@ -19,10 +19,12 @@ version_command() { download_usage() { if [[ -n $long_usage ]]; then printf "download - Sample application with a help footer\n" - echo + echo + else printf "download - Sample application with a help footer\n" - echo + echo + fi printf "Usage:\n" @@ -43,7 +45,7 @@ download_usage() { # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " SOURCE" printf " URL to download from\n" @@ -109,13 +111,13 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes download_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -127,12 +129,12 @@ parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[source]} ]]; then @@ -143,7 +145,7 @@ parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter diff --git a/examples/git-like/git b/examples/git-like/git index 7f110086..44bf15df 100644 --- a/examples/git-like/git +++ b/examples/git-like/git @@ -11,10 +11,12 @@ version_command() { git_usage() { if [[ -n $long_usage ]]; then printf "git - Git example\n" - echo + echo + else printf "git - Git example\n" - echo + echo + fi printf "Usage:\n" @@ -45,10 +47,12 @@ git_usage() { git_status_usage() { if [[ -n $long_usage ]]; then printf "git status - Show repository status\n" - echo + echo + else printf "git status - Show repository status\n" - echo + echo + fi printf "Shortcut: s*\n" @@ -73,10 +77,12 @@ git_status_usage() { git_commit_usage() { if [[ -n $long_usage ]]; then printf "git commit - Commit changes\n" - echo + echo + else printf "git commit - Commit changes\n" - echo + echo + fi printf "Shortcut: c*\n" @@ -98,7 +104,7 @@ git_commit_usage() { echo " --message, -m MESSAGE" printf " Commit message\n" echo - + # :flag.usage echo " --all, -a" printf " Automatically stage files\n" @@ -178,43 +184,43 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes git_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter # :command.command_filter action=$1 - + case $action in -* ) ;; - + status | s* ) action="status" shift git_status_parse_requirements "$@" shift $# - ;; - + ;; + commit | c* ) action="commit" shift git_commit_parse_requirements "$@" shift $# - ;; - + ;; + # :command.command_fallback * ) git_usage exit 1 ;; - + esac # :command.required_args_filter # :command.required_flags_filter @@ -222,18 +228,18 @@ parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -249,13 +255,13 @@ git_status_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes git_status_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -267,18 +273,18 @@ git_status_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -294,13 +300,13 @@ git_commit_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes git_commit_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -323,25 +329,24 @@ git_commit_parse_requirements() { exit 1 fi ;; - + # :flag.case --all | -a ) args[--all]=1 shift ;; - - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -384,7 +389,7 @@ run() { else git_status_command fi - + elif [[ $action == "commit" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -392,7 +397,7 @@ run() { else git_commit_command fi - + elif [[ $action == "root" ]]; then root_command fi diff --git a/examples/minimal/download b/examples/minimal/download index 8d432f57..7a7c09bb 100644 --- a/examples/minimal/download +++ b/examples/minimal/download @@ -19,10 +19,12 @@ version_command() { download_usage() { if [[ -n $long_usage ]]; then printf "download - Sample minimal application without commands\n" - echo + echo + else printf "download - Sample minimal application without commands\n" - echo + echo + fi printf "Usage:\n" @@ -47,12 +49,12 @@ download_usage() { echo # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " SOURCE" printf " URL to download from\n" echo - + # :argument.usage echo " TARGET" printf " Target filename (default: same as source)\n" @@ -60,7 +62,7 @@ download_usage() { # :command.usage_examples printf "Examples:\n" - + printf " download example.com\n" printf " download example.com ./output -f\n" echo @@ -122,13 +124,13 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes download_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -152,13 +154,12 @@ parse_requirements() { args[--force]=1 shift ;; - - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[source]} ]]; then @@ -172,7 +173,7 @@ parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter diff --git a/examples/minus-v/cli b/examples/minus-v/cli index 123b6296..c371d1f0 100644 --- a/examples/minus-v/cli +++ b/examples/minus-v/cli @@ -19,10 +19,12 @@ version_command() { cli_usage() { if [[ -n $long_usage ]]; then printf "cli - Example that replaces the default behavior of -v and -h\n" - echo + echo + else printf "cli - Example that replaces the default behavior of -v and -h\n" - echo + echo + fi printf "Usage:\n" @@ -45,7 +47,7 @@ cli_usage() { echo " --verbose, -v" printf " Show verbose output\n" echo - + # :flag.usage echo " --host, -h HOST" printf " Host address\n" @@ -108,13 +110,13 @@ parse_requirements() { version_command exit ;; - + --help ) long_usage=yes cli_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -131,7 +133,7 @@ parse_requirements() { args[--verbose]=1 shift ;; - + # :flag.case --host | -h ) if [[ $2 ]]; then @@ -143,19 +145,18 @@ parse_requirements() { exit 1 fi ;; - - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter diff --git a/examples/multiline/multi b/examples/multiline/multi index 33e94646..df895397 100644 --- a/examples/multiline/multi +++ b/examples/multiline/multi @@ -11,12 +11,15 @@ version_command() { multi_usage() { if [[ -n $long_usage ]]; then printf "multi\n" - echo + echo + printf " Multiline test\n \n This is a multiline test example. Long lines are going to be properly wrapped\n at the 80 character mark.\n" - echo + echo + else printf "multi - Multiline test\n" - echo + echo + fi printf "Usage:\n" @@ -42,14 +45,14 @@ multi_usage() { # :command.usage_environment_variables printf "Environment Variables:\n" - + # :environment_variable.usage echo " MULTI_VITAMIN" printf " Environment variables can also use multiple lines. This can be useful if we\n need to explain - in excruciating detail - what the environemnt variable is\n used for.\n" echo # :command.usage_examples printf "Examples:\n" - + printf " Examples can also use multiple lines. This can be useful if we need to explain\n the example, for instance like we are doing here:\n \n multi multiline --flag\n" echo @@ -60,12 +63,15 @@ multi_usage() { multi_multiline_usage() { if [[ -n $long_usage ]]; then printf "multi multiline\n" - echo + echo + printf " Do some multiline work.\n \n This is a long process and takes time, therefore it takes a lot of lines to\n describe and this line is particularly long.\n \n But - not all hope is lost. Bashly should respect newlines and word-wrap long\n lines properly at the 80 character mark.\n" - echo + echo + else printf "multi multiline - Do some multiline work.\n" - echo + echo + fi printf "Usage:\n" @@ -86,7 +92,7 @@ multi_multiline_usage() { echo # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " MY_ARG" printf " Argument with multiline.\n \n Once again we gather here to prepare some long lines that will most likely\n seem silly to anyone who reads them.\n \n But, it is just needed for testing - otherwise, it will not only be silly,\n but it will also be buggy!\n" @@ -99,10 +105,12 @@ multi_multiline_usage() { multi_regular_usage() { if [[ -n $long_usage ]]; then printf "multi regular - Standard help line\n" - echo + echo + else printf "multi regular - Standard help line\n" - echo + echo + fi printf "Usage:\n" @@ -119,7 +127,7 @@ multi_regular_usage() { # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " REPO" printf " Repository name\n" @@ -199,43 +207,43 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes multi_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter # :command.command_filter action=$1 - + case $action in -* ) ;; - + multiline ) action="multiline" shift multi_multiline_parse_requirements "$@" shift $# - ;; - + ;; + regular ) action="regular" shift multi_regular_parse_requirements "$@" shift $# - ;; - + ;; + # :command.command_fallback * ) multi_usage exit 1 ;; - + esac # :command.required_args_filter # :command.required_flags_filter @@ -243,18 +251,18 @@ parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter @@ -270,13 +278,13 @@ multi_multiline_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes multi_multiline_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -293,13 +301,12 @@ multi_multiline_parse_requirements() { args[--long]=1 shift ;; - - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[my_arg]} ]]; then @@ -310,7 +317,7 @@ multi_multiline_parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter @@ -326,13 +333,13 @@ multi_regular_parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes multi_regular_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -344,12 +351,12 @@ multi_regular_parse_requirements() { while [[ $# -gt 0 ]]; do key="$1" case "$key" in - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[repo]} ]]; then @@ -360,7 +367,7 @@ multi_regular_parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter @@ -403,7 +410,7 @@ run() { else multi_multiline_command fi - + elif [[ $action == "regular" ]]; then if [[ ${args[--help]} ]]; then long_usage=yes @@ -411,7 +418,7 @@ run() { else multi_regular_command fi - + elif [[ $action == "root" ]]; then root_command fi diff --git a/examples/whitelist/login b/examples/whitelist/login index 9f2e1c81..3c3633ca 100644 --- a/examples/whitelist/login +++ b/examples/whitelist/login @@ -19,10 +19,12 @@ version_command() { login_usage() { if [[ -n $long_usage ]]; then printf "login - Sample showing the use of arg and flag whitelist (allowed values)\n" - echo + echo + else printf "login - Sample showing the use of arg and flag whitelist (allowed values)\n" - echo + echo + fi printf "Usage:\n" @@ -46,7 +48,7 @@ login_usage() { printf " User name\n" printf " Allowed: user, admin\n" echo - + # :flag.usage echo " --protocol, -p TYPE" printf " Protocol to connect with\n" @@ -55,13 +57,13 @@ login_usage() { echo # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " REGION" printf " Region to connect to\n" printf " Allowed: eu, us\n" echo - + # :argument.usage echo " ENVIRONMENT" printf " Environment to connect to\n" @@ -126,13 +128,13 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes login_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -167,7 +169,7 @@ parse_requirements() { exit 1 fi ;; - + # :flag.case --protocol | -p ) if [[ $2 ]]; then @@ -179,13 +181,12 @@ parse_requirements() { exit 1 fi ;; - - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[region]} ]]; then @@ -199,7 +200,7 @@ parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter diff --git a/examples/yaml/yaml b/examples/yaml/yaml index 0eced53d..e24845e7 100644 --- a/examples/yaml/yaml +++ b/examples/yaml/yaml @@ -8,20 +8,20 @@ root_command() { filename=${args[filename]} variable=${args[variable]} prefix=${args[--prefix]} - + if [[ $variable ]]; then eval "$(yaml_load "$filename" "$prefix")" value=${!variable} - + if [[ $value ]]; then echo "$variable=$value" else echo "variable not found: $variable" fi - + else yaml_load "$filename" "$prefix" - + fi } @@ -34,10 +34,12 @@ version_command() { yaml_usage() { if [[ -n $long_usage ]]; then printf "yaml - Sample application that uses the YAML functions\n" - echo + echo + else printf "yaml - Sample application that uses the YAML functions\n" - echo + echo + fi printf "Usage:\n" @@ -62,12 +64,12 @@ yaml_usage() { echo # :command.usage_args printf "Arguments:\n" - + # :argument.usage echo " FILENAME" printf " The YAML file to read\n" echo - + # :argument.usage echo " VARIABLE" printf " Show only this variable\n" @@ -75,7 +77,7 @@ yaml_usage() { # :command.usage_examples printf "Examples:\n" - + printf " yaml settings.yml\n" printf " yaml settings.yml --prefix config_\n" printf " yaml settings.yml server_port\n" @@ -176,13 +178,13 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes yaml_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -212,13 +214,12 @@ parse_requirements() { exit 1 fi ;; - - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case if [[ ! ${args[filename]} ]]; then @@ -232,7 +233,7 @@ parse_requirements() { exit 1 fi ;; - + esac done # :command.catch_all_filter diff --git a/lib/bashly/extensions/string.rb b/lib/bashly/extensions/string.rb index d7ff8896..940e9bcb 100644 --- a/lib/bashly/extensions/string.rb +++ b/lib/bashly/extensions/string.rb @@ -24,7 +24,7 @@ def wrap(length = 80) end def lint - gsub(/\n{2,}/, "\n\n") + gsub(/\s+\n/m, "\n\n") end end diff --git a/spec/bashly/extensions/string_spec.rb b/spec/bashly/extensions/string_spec.rb index 1372a5aa..c28829f5 100644 --- a/spec/bashly/extensions/string_spec.rb +++ b/spec/bashly/extensions/string_spec.rb @@ -56,10 +56,10 @@ end describe '#lint' do - subject { "one\ntwo\n\nthree\n\n\nfour\n\n\n\n" } + subject { "one\n two\n \n three\n \n \nfour\n\n\n\n" } it "replaces two or more newlines with two newlines" do - expect(subject.lint).to eq "one\ntwo\n\nthree\n\nfour\n\n" + expect(subject.lint).to eq "one\n two\n\n three\n\nfour\n\n" end end end diff --git a/spec/fixtures/workspaces/flag-args-with-dash/argflag b/spec/fixtures/workspaces/flag-args-with-dash/argflag index 9de769eb..e4b2a7cd 100644 --- a/spec/fixtures/workspaces/flag-args-with-dash/argflag +++ b/spec/fixtures/workspaces/flag-args-with-dash/argflag @@ -19,10 +19,12 @@ version_command() { argflag_usage() { if [[ -n $long_usage ]]; then printf "argflag - Personal package manager\n" - echo + echo + else printf "argflag - Personal package manager\n" - echo + echo + fi printf "Usage:\n" @@ -45,7 +47,7 @@ argflag_usage() { echo " --force, -f" printf " Force\n" echo - + # :flag.usage echo " --options, -o LIST" printf " Options\n" @@ -108,13 +110,13 @@ parse_requirements() { version_command exit ;; - + --help | -h ) long_usage=yes argflag_usage exit ;; - + esac # :command.environment_variables_filter # :command.dependencies_filter @@ -131,7 +133,7 @@ parse_requirements() { args[--force]=1 shift ;; - + # :flag.case --options | -o ) if [[ $2 ]]; then @@ -143,19 +145,18 @@ parse_requirements() { exit 1 fi ;; - - + -* ) printf "invalid option: %s\n" "$key" exit 1 ;; - + * ) # :command.parse_requirements_case printf "invalid argument: %s\n" "$key" exit 1 ;; - + esac done # :command.catch_all_filter