From 95f186cee8499d5f7ec8f865046e35fe4035a9e2 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Mon, 23 Dec 2019 19:32:26 +0000 Subject: [PATCH 1/3] relinquish -v and -h if the user wants them --- Runfile | 2 +- examples/colors/colorly | 6 ++-- examples/command-default/ftp | 14 ++++----- examples/command-groups/ftp | 22 +++++++------- examples/commands-nested/cli | 30 +++++++++---------- examples/commands/cli | 14 ++++----- examples/config-ini/configly | 18 +++++------ examples/custom-includes/download | 6 ++-- examples/custom-strings/download | 6 ++-- examples/dependencies/cli | 14 ++++----- examples/docker-like/docker | 26 ++++++++-------- examples/environment-variables/cli | 10 +++---- examples/git-like/git | 14 ++++----- examples/minimal/download | 6 ++-- examples/multiline/multi | 14 ++++----- examples/yaml/yaml | 6 ++-- lib/bashly/models/command.rb | 5 ++++ .../views/command/fixed_flags_filter.erb | 10 ++++++- .../views/command/usage_fixed_flags.erb | 8 +++++ spec/approvals/examples/command-default | 2 +- spec/approvals/examples/command-groups | 2 +- spec/approvals/examples/commands | 2 +- spec/approvals/examples/commands-nested | 2 +- spec/approvals/examples/config-ini | 2 +- spec/approvals/examples/custom-strings | 2 +- spec/approvals/examples/docker-like | 2 +- spec/approvals/examples/environment-variables | 2 +- spec/approvals/examples/git-like | 2 +- spec/approvals/examples/minimal | 2 +- spec/approvals/examples/multiline | 2 +- .../{short-flag => short-command-code} | 0 spec/approvals/examples/yaml | 2 +- spec/bashly/models/command_spec.rb | 17 +++++++++++ spec/fixtures/models/commands.yml | 9 +++++- .../.gitignore | 0 .../README.md | 0 .../src/bashly.yml | 0 .../test.sh | 3 +- 38 files changed, 165 insertions(+), 119 deletions(-) rename spec/approvals/examples/{short-flag => short-command-code} (100%) rename spec/fixtures/workspaces/{short-flag => short-command-code}/.gitignore (100%) rename spec/fixtures/workspaces/{short-flag => short-command-code}/README.md (100%) rename spec/fixtures/workspaces/{short-flag => short-command-code}/src/bashly.yml (100%) rename spec/fixtures/workspaces/{short-flag => short-command-code}/test.sh (58%) diff --git a/Runfile b/Runfile index 4e4777f5..e717030f 100644 --- a/Runfile +++ b/Runfile @@ -40,7 +40,7 @@ def examples "examples/minimal/download", "examples/multiline/multi", "examples/yaml/yaml", - "spec/fixtures/workspaces/short-flag/rush", + "spec/fixtures/workspaces/short-command-code/rush", ] end diff --git a/examples/colors/colorly b/examples/colors/colorly index e9c721db..d4eb02f9 100644 --- a/examples/colors/colorly +++ b/examples/colors/colorly @@ -42,7 +42,7 @@ colorly_usage() { echo " --help, -h" printf " Show this help\n" echo - echo " --version" + echo " --version, -v" printf " Show version number\n" echo @@ -104,12 +104,12 @@ cyan_underlined() { printf "\e[4;36m%b\e[0m\n" "$*"; } parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes colorly_usage exit 1 diff --git a/examples/command-default/ftp b/examples/command-default/ftp index b7773656..29707dec 100644 --- a/examples/command-default/ftp +++ b/examples/command-default/ftp @@ -34,7 +34,7 @@ ftp_usage() { echo " --help, -h" printf " Show this help\n" echo - echo " --version" + echo " --version, -v" printf " Show version number\n" echo @@ -142,12 +142,12 @@ ftp_download_command() { parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes ftp_usage exit 1 @@ -215,12 +215,12 @@ parse_requirements() { ftp_upload_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes ftp_upload_usage exit 1 @@ -269,12 +269,12 @@ ftp_upload_parse_requirements() { ftp_download_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes ftp_download_usage exit 1 diff --git a/examples/command-groups/ftp b/examples/command-groups/ftp index a1e285d9..d0b3458e 100644 --- a/examples/command-groups/ftp +++ b/examples/command-groups/ftp @@ -37,7 +37,7 @@ ftp_usage() { echo " --help, -h" printf " Show this help\n" echo - echo " --version" + echo " --version, -v" printf " Show version number\n" echo @@ -207,12 +207,12 @@ ftp_logout_command() { parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes ftp_usage exit 1 @@ -288,12 +288,12 @@ parse_requirements() { ftp_download_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes ftp_download_usage exit 1 @@ -342,12 +342,12 @@ ftp_download_parse_requirements() { ftp_upload_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes ftp_upload_usage exit 1 @@ -396,12 +396,12 @@ ftp_upload_parse_requirements() { ftp_login_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes ftp_login_usage exit 1 @@ -438,12 +438,12 @@ ftp_login_parse_requirements() { ftp_logout_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes ftp_logout_usage exit 1 diff --git a/examples/commands-nested/cli b/examples/commands-nested/cli index bf6e57b0..62b55fa1 100644 --- a/examples/commands-nested/cli +++ b/examples/commands-nested/cli @@ -34,7 +34,7 @@ cli_usage() { echo " --help, -h" printf " Show this help\n" echo - echo " --version" + echo " --version, -v" printf " Show version number\n" echo @@ -291,12 +291,12 @@ cli_file_edit_command() { parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes cli_usage exit 1 @@ -358,12 +358,12 @@ parse_requirements() { cli_dir_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes cli_dir_usage exit 1 @@ -425,12 +425,12 @@ cli_dir_parse_requirements() { cli_dir_list_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes cli_dir_list_usage exit 1 @@ -479,12 +479,12 @@ cli_dir_list_parse_requirements() { cli_dir_remove_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes cli_dir_remove_usage exit 1 @@ -539,12 +539,12 @@ cli_dir_remove_parse_requirements() { cli_file_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes cli_file_usage exit 1 @@ -606,12 +606,12 @@ cli_file_parse_requirements() { cli_file_show_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes cli_file_show_usage exit 1 @@ -660,12 +660,12 @@ cli_file_show_parse_requirements() { cli_file_edit_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes cli_file_edit_usage exit 1 diff --git a/examples/commands/cli b/examples/commands/cli index 0bbe719d..f62ed881 100644 --- a/examples/commands/cli +++ b/examples/commands/cli @@ -34,7 +34,7 @@ cli_usage() { echo " --help, -h" printf " Show this help\n" echo - echo " --version" + echo " --version, -v" printf " Show version number\n" echo @@ -181,12 +181,12 @@ cli_upload_command() { parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes cli_usage exit 1 @@ -248,12 +248,12 @@ parse_requirements() { cli_download_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes cli_download_usage exit 1 @@ -311,12 +311,12 @@ cli_download_parse_requirements() { cli_upload_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes cli_upload_usage exit 1 diff --git a/examples/config-ini/configly b/examples/config-ini/configly index 17e70988..e9e6364d 100644 --- a/examples/config-ini/configly +++ b/examples/config-ini/configly @@ -35,7 +35,7 @@ configly_usage() { echo " --help, -h" printf " Show this help\n" echo - echo " --version" + echo " --version, -v" printf " Show version number\n" echo @@ -314,12 +314,12 @@ configly_list_command() { parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes configly_usage exit 1 @@ -388,12 +388,12 @@ parse_requirements() { configly_set_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes configly_set_usage exit 1 @@ -453,12 +453,12 @@ configly_set_parse_requirements() { configly_get_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes configly_get_usage exit 1 @@ -507,12 +507,12 @@ configly_get_parse_requirements() { configly_list_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes configly_list_usage exit 1 diff --git a/examples/custom-includes/download b/examples/custom-includes/download index 53edde0c..44a36689 100644 --- a/examples/custom-includes/download +++ b/examples/custom-includes/download @@ -38,7 +38,7 @@ download_usage() { echo " --help, -h" printf " Show this help\n" echo - echo " --version" + echo " --version, -v" printf " Show version number\n" echo @@ -76,12 +76,12 @@ my_extra_function() { parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes download_usage exit 1 diff --git a/examples/custom-strings/download b/examples/custom-strings/download index fbc6b79c..629c5ad3 100644 --- a/examples/custom-strings/download +++ b/examples/custom-strings/download @@ -37,7 +37,7 @@ download_usage() { echo " --help, -h" printf " Show this helpful help\n" echo - echo " --version" + echo " --version, -v" printf " Show version number\n" echo # :command.usage_flags @@ -68,12 +68,12 @@ inspect_args() { parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes download_usage exit 1 diff --git a/examples/dependencies/cli b/examples/dependencies/cli index 9b4f3658..02e1eeb0 100644 --- a/examples/dependencies/cli +++ b/examples/dependencies/cli @@ -34,7 +34,7 @@ cli_usage() { echo " --help, -h" printf " Show this help\n" echo - echo " --version" + echo " --version, -v" printf " Show version number\n" echo @@ -120,12 +120,12 @@ cli_upload_command() { parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes cli_usage exit 1 @@ -187,12 +187,12 @@ parse_requirements() { cli_download_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes cli_download_usage exit 1 @@ -237,12 +237,12 @@ cli_download_parse_requirements() { cli_upload_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes cli_upload_usage exit 1 diff --git a/examples/docker-like/docker b/examples/docker-like/docker index 620342b8..3450594d 100644 --- a/examples/docker-like/docker +++ b/examples/docker-like/docker @@ -34,7 +34,7 @@ docker_usage() { echo " --help, -h" printf " Show this help\n" echo - echo " --version" + echo " --version, -v" printf " Show version number\n" echo @@ -239,12 +239,12 @@ docker_image_ls_command() { parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes docker_usage exit 1 @@ -306,12 +306,12 @@ parse_requirements() { docker_container_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes docker_container_usage exit 1 @@ -373,12 +373,12 @@ docker_container_parse_requirements() { docker_container_run_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes docker_container_run_usage exit 1 @@ -427,12 +427,12 @@ docker_container_run_parse_requirements() { docker_container_stop_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes docker_container_stop_usage exit 1 @@ -481,12 +481,12 @@ docker_container_stop_parse_requirements() { docker_image_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes docker_image_usage exit 1 @@ -541,12 +541,12 @@ docker_image_parse_requirements() { docker_image_ls_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes docker_image_ls_usage exit 1 diff --git a/examples/environment-variables/cli b/examples/environment-variables/cli index 4c352735..38b402a5 100644 --- a/examples/environment-variables/cli +++ b/examples/environment-variables/cli @@ -33,7 +33,7 @@ cli_usage() { echo " --help, -h" printf " Show this help\n" echo - echo " --version" + echo " --version, -v" printf " Show version number\n" echo @@ -107,12 +107,12 @@ cli_verify_command() { parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes cli_usage exit 1 @@ -167,12 +167,12 @@ parse_requirements() { cli_verify_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes cli_verify_usage exit 1 diff --git a/examples/git-like/git b/examples/git-like/git index acfd50ab..d5602662 100644 --- a/examples/git-like/git +++ b/examples/git-like/git @@ -34,7 +34,7 @@ git_usage() { echo " --help, -h" printf " Show this help\n" echo - echo " --version" + echo " --version, -v" printf " Show version number\n" echo @@ -136,12 +136,12 @@ git_commit_command() { parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes git_usage exit 1 @@ -203,12 +203,12 @@ parse_requirements() { git_status_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes git_status_usage exit 1 @@ -245,12 +245,12 @@ git_status_parse_requirements() { git_commit_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes git_commit_usage exit 1 diff --git a/examples/minimal/download b/examples/minimal/download index 0df38088..308285b6 100644 --- a/examples/minimal/download +++ b/examples/minimal/download @@ -37,7 +37,7 @@ download_usage() { echo " --help, -h" printf " Show this help\n" echo - echo " --version" + echo " --version, -v" printf " Show version number\n" echo # :command.usage_flags @@ -80,12 +80,12 @@ inspect_args() { parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes download_usage exit 1 diff --git a/examples/multiline/multi b/examples/multiline/multi index af7ba9ca..8de8f9e7 100644 --- a/examples/multiline/multi +++ b/examples/multiline/multi @@ -36,7 +36,7 @@ multi_usage() { echo " --help, -h" printf " Show this help\n" echo - echo " --version" + echo " --version, -v" printf " Show version number\n" echo @@ -157,12 +157,12 @@ multi_regular_command() { parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes multi_usage exit 1 @@ -224,12 +224,12 @@ parse_requirements() { multi_multiline_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes multi_multiline_usage exit 1 @@ -277,12 +277,12 @@ multi_multiline_parse_requirements() { multi_regular_parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes multi_regular_usage exit 1 diff --git a/examples/yaml/yaml b/examples/yaml/yaml index 11422f88..0999d236 100644 --- a/examples/yaml/yaml +++ b/examples/yaml/yaml @@ -52,7 +52,7 @@ yaml_usage() { echo " --help, -h" printf " Show this help\n" echo - echo " --version" + echo " --version, -v" printf " Show version number\n" echo # :command.usage_flags @@ -134,12 +134,12 @@ yaml_load() { parse_requirements() { # :command.fixed_flag_filter case "$1" in - --version ) + --version | -v ) version_command exit 1 ;; - --help | -h ) + --help | -h ) long_usage=yes yaml_usage exit 1 diff --git a/lib/bashly/models/command.rb b/lib/bashly/models/command.rb index ca9d750c..6056d212 100644 --- a/lib/bashly/models/command.rb +++ b/lib/bashly/models/command.rb @@ -136,6 +136,11 @@ def root_command? parents.empty? end + # Returns true if one of the flags matches the provided short code + def short_flag_exist?(flag) + flags.select { |f| f.short == flag }.any? + end + # Returns a constructed string suitable for Usage pattern def usage_string result = [full_name] diff --git a/lib/bashly/views/command/fixed_flags_filter.erb b/lib/bashly/views/command/fixed_flags_filter.erb index 9804589b..a1d74279 100644 --- a/lib/bashly/views/command/fixed_flags_filter.erb +++ b/lib/bashly/views/command/fixed_flags_filter.erb @@ -1,11 +1,19 @@ # :command.fixed_flag_filter case "$1" in +<%- if short_flag_exist? "-v" -%> --version ) +<%- else -%> +--version | -v ) +<%- end -%> version_command exit 1 ;; ---help | -h ) +<%- if short_flag_exist? "-h" -%> +--help ) +<%- else -%> +--help | -h ) +<%- end -%> long_usage=yes <%= function_name %>_usage exit 1 diff --git a/lib/bashly/views/command/usage_fixed_flags.erb b/lib/bashly/views/command/usage_fixed_flags.erb index 9ecb6228..ed41a54a 100644 --- a/lib/bashly/views/command/usage_fixed_flags.erb +++ b/lib/bashly/views/command/usage_fixed_flags.erb @@ -1,9 +1,17 @@ # :command.usage_fixed_flags +<%- if short_flag_exist? "-h" -%> +echo " --help" +<%- else -%> echo " --help, -h" +<%- end -%> printf " <%= strings[:help_flag_text] %>\n" echo <%- if root_command? -%> +<%- if short_flag_exist? "-v" -%> echo " --version" +<%- else -%> +echo " --version, -v" +<%- end -%> printf " <%= strings[:version_flag_text] %>\n" echo <%- end -%> diff --git a/spec/approvals/examples/command-default b/spec/approvals/examples/command-default index 36acb906..c99e422e 100644 --- a/spec/approvals/examples/command-default +++ b/spec/approvals/examples/command-default @@ -33,7 +33,7 @@ Options: --help, -h Show this help - --version + --version, -v Show version number + ./ftp download something diff --git a/spec/approvals/examples/command-groups b/spec/approvals/examples/command-groups index 31c1ccf5..58872499 100644 --- a/spec/approvals/examples/command-groups +++ b/spec/approvals/examples/command-groups @@ -43,7 +43,7 @@ Options: --help, -h Show this help - --version + --version, -v Show version number + ./ftp login diff --git a/spec/approvals/examples/commands b/spec/approvals/examples/commands index 34af25a6..a3073788 100644 --- a/spec/approvals/examples/commands +++ b/spec/approvals/examples/commands @@ -33,7 +33,7 @@ Options: --help, -h Show this help - --version + --version, -v Show version number Environment Variables: diff --git a/spec/approvals/examples/commands-nested b/spec/approvals/examples/commands-nested index 02a216b3..ba2dde73 100644 --- a/spec/approvals/examples/commands-nested +++ b/spec/approvals/examples/commands-nested @@ -35,7 +35,7 @@ Options: --help, -h Show this help - --version + --version, -v Show version number + ./cli dir diff --git a/spec/approvals/examples/config-ini b/spec/approvals/examples/config-ini index 5f9eeaf2..62012794 100644 --- a/spec/approvals/examples/config-ini +++ b/spec/approvals/examples/config-ini @@ -23,7 +23,7 @@ Options: --help, -h Show this help - --version + --version, -v Show version number + ./configly set hello world diff --git a/spec/approvals/examples/custom-strings b/spec/approvals/examples/custom-strings index 9fdf9cdf..f4f98dfa 100644 --- a/spec/approvals/examples/custom-strings +++ b/spec/approvals/examples/custom-strings @@ -21,7 +21,7 @@ download - Sample minimal application with custom strings --help, -h Show this helpful help - --version + --version, -v Show version number --out, -o DIR (required) diff --git a/spec/approvals/examples/docker-like b/spec/approvals/examples/docker-like index 89f7cd87..89d6ea98 100644 --- a/spec/approvals/examples/docker-like +++ b/spec/approvals/examples/docker-like @@ -34,7 +34,7 @@ Options: --help, -h Show this help - --version + --version, -v Show version number + ./docker container diff --git a/spec/approvals/examples/environment-variables b/spec/approvals/examples/environment-variables index e757ce0c..39db7b9b 100644 --- a/spec/approvals/examples/environment-variables +++ b/spec/approvals/examples/environment-variables @@ -30,7 +30,7 @@ Options: --help, -h Show this help - --version + --version, -v Show version number Environment Variables: diff --git a/spec/approvals/examples/git-like b/spec/approvals/examples/git-like index d33e40ae..232b32bc 100644 --- a/spec/approvals/examples/git-like +++ b/spec/approvals/examples/git-like @@ -33,7 +33,7 @@ Options: --help, -h Show this help - --version + --version, -v Show version number + ./git s diff --git a/spec/approvals/examples/minimal b/spec/approvals/examples/minimal index 3f31d752..13e9de93 100644 --- a/spec/approvals/examples/minimal +++ b/spec/approvals/examples/minimal @@ -19,7 +19,7 @@ Options: --help, -h Show this help - --version + --version, -v Show version number --force, -f diff --git a/spec/approvals/examples/multiline b/spec/approvals/examples/multiline index e584d3d0..cd5eb44c 100644 --- a/spec/approvals/examples/multiline +++ b/spec/approvals/examples/multiline @@ -38,7 +38,7 @@ Options: --help, -h Show this help - --version + --version, -v Show version number Environment Variables: diff --git a/spec/approvals/examples/short-flag b/spec/approvals/examples/short-command-code similarity index 100% rename from spec/approvals/examples/short-flag rename to spec/approvals/examples/short-command-code diff --git a/spec/approvals/examples/yaml b/spec/approvals/examples/yaml index de212db3..0a761f7f 100644 --- a/spec/approvals/examples/yaml +++ b/spec/approvals/examples/yaml @@ -16,7 +16,7 @@ Options: --help, -h Show this help - --version + --version, -v Show version number --prefix, -p PREFIX diff --git a/spec/bashly/models/command_spec.rb b/spec/bashly/models/command_spec.rb index 8d832126..a65d3946 100644 --- a/spec/bashly/models/command_spec.rb +++ b/spec/bashly/models/command_spec.rb @@ -215,9 +215,26 @@ end end + describe '#short_flag_exist?' do + let(:fixture) { :flag_hog } + + context "when the command has this short flag" do + it "returns true" do + expect(subject.short_flag_exist? "-h").to be true + end + end + + context "when the command does not have this short flag" do + it "returns false" do + expect(subject.short_flag_exist? "-s").to be false + end + end + end + describe '#usage_string' do context "when no args and no commands are defined" do let(:fixture) { :git_status } + it "returns a string suitable to be used as a usage pattern" do expect(subject.usage_string).to eq "git status [options]" end diff --git a/spec/fixtures/models/commands.yml b/spec/fixtures/models/commands.yml index d6ccf599..287df363 100644 --- a/spec/fixtures/models/commands.yml +++ b/spec/fixtures/models/commands.yml @@ -70,4 +70,11 @@ - name: post - name: put - +:flag_hog: + name: cli + help: test when -h and -v are defined + flags: + - short: -h + long: --hello + - short: -v + long: --vorld diff --git a/spec/fixtures/workspaces/short-flag/.gitignore b/spec/fixtures/workspaces/short-command-code/.gitignore similarity index 100% rename from spec/fixtures/workspaces/short-flag/.gitignore rename to spec/fixtures/workspaces/short-command-code/.gitignore diff --git a/spec/fixtures/workspaces/short-flag/README.md b/spec/fixtures/workspaces/short-command-code/README.md similarity index 100% rename from spec/fixtures/workspaces/short-flag/README.md rename to spec/fixtures/workspaces/short-command-code/README.md diff --git a/spec/fixtures/workspaces/short-flag/src/bashly.yml b/spec/fixtures/workspaces/short-command-code/src/bashly.yml similarity index 100% rename from spec/fixtures/workspaces/short-flag/src/bashly.yml rename to spec/fixtures/workspaces/short-command-code/src/bashly.yml diff --git a/spec/fixtures/workspaces/short-flag/test.sh b/spec/fixtures/workspaces/short-command-code/test.sh similarity index 58% rename from spec/fixtures/workspaces/short-flag/test.sh rename to spec/fixtures/workspaces/short-command-code/test.sh index 09de7c7e..58e6bae9 100644 --- a/spec/fixtures/workspaces/short-flag/test.sh +++ b/spec/fixtures/workspaces/short-command-code/test.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash -# This fixture tests that short flags work properly +# This fixture tests that short command codes work properly +# It is executed as part of the Runfile examples test # Reference issue: https://github.com/DannyBen/bashly/issues/16 rm -f ./src/*.sh From 361792ec692e2a9290498b3652fad8d3af3e524f Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Mon, 23 Dec 2019 19:38:29 +0000 Subject: [PATCH 2/3] readme: mention -h and -v special treatment --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1858640b..f6cba90a 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,7 @@ bash function. ### Flag options The flag's value will be available to you as `${args[--output]}` in your -bash function (regardless of whether the user provided ut with the long or +bash function (regardless of whether the user provided it with the long or short form). Option | Description @@ -174,6 +174,12 @@ short form). `arg` | If the flag requires an argument, specify its name here. `required` | Specify if this flag is required. +#### Special handling for -v and -h + +The `-v` and `-h` flags will be used as the short options for `--version` and +`--help` respectively **only if you are not using them in any of your own +flags**. + ### Environment Variable options The below configuration generates this environment variable usage text: From f5b61c0bb5d0ede57d8c8a301996ef6b38b74bdb Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Mon, 23 Dec 2019 20:05:53 +0000 Subject: [PATCH 3/3] fix usage header for proper display of fixed flags --- Runfile | 1 + examples/colors/colorly | 2 +- examples/command-default/ftp | 2 +- examples/command-groups/ftp | 2 +- examples/commands-nested/cli | 2 +- examples/commands/cli | 6 +- examples/config-ini/configly | 2 +- examples/custom-includes/download | 2 +- examples/custom-strings/download | 4 +- examples/dependencies/cli | 2 +- examples/docker-like/docker | 2 +- examples/environment-variables/cli | 2 +- examples/git-like/git | 4 +- examples/minimal/download | 2 +- examples/minimal/test.sh | 2 +- examples/minus-v/README.md | 7 + examples/minus-v/cli | 156 ++++++++++++++++++ examples/minus-v/src/bashly.yml | 14 ++ examples/minus-v/src/initialize.sh | 6 + examples/minus-v/src/root_command.sh | 3 + examples/minus-v/test.sh | 14 ++ examples/multiline/multi | 2 +- examples/yaml/yaml | 4 +- lib/bashly/templates/strings.yml | 2 - lib/bashly/views/command/usage.erb | 6 +- lib/bashly/views/flag/case.erb | 2 +- spec/approvals/examples/command-default | 4 +- spec/approvals/examples/command-groups | 4 +- spec/approvals/examples/commands | 4 +- spec/approvals/examples/commands-nested | 4 +- spec/approvals/examples/config-ini | 2 +- spec/approvals/examples/custom-strings | 2 +- spec/approvals/examples/docker-like | 4 +- spec/approvals/examples/environment-variables | 4 +- spec/approvals/examples/git-like | 4 +- spec/approvals/examples/minimal | 4 +- spec/approvals/examples/minus-v | 46 ++++++ spec/approvals/examples/multiline | 4 +- spec/approvals/examples/yaml | 2 +- 39 files changed, 293 insertions(+), 48 deletions(-) create mode 100644 examples/minus-v/README.md create mode 100644 examples/minus-v/cli create mode 100644 examples/minus-v/src/bashly.yml create mode 100644 examples/minus-v/src/initialize.sh create mode 100644 examples/minus-v/src/root_command.sh create mode 100644 examples/minus-v/test.sh create mode 100644 spec/approvals/examples/minus-v diff --git a/Runfile b/Runfile index e717030f..338a3337 100644 --- a/Runfile +++ b/Runfile @@ -38,6 +38,7 @@ def examples "examples/environment-variables/cli", "examples/git-like/git", "examples/minimal/download", + "examples/minus-v/cli", "examples/multiline/multi", "examples/yaml/yaml", "spec/fixtures/workspaces/short-command-code/rush", diff --git a/examples/colors/colorly b/examples/colors/colorly index d4eb02f9..3f5e1db3 100644 --- a/examples/colors/colorly +++ b/examples/colors/colorly @@ -33,7 +33,7 @@ colorly_usage() { printf "Usage:\n" printf " colorly [MESSAGE] [options]\n" printf " colorly --help | -h\n" - printf " colorly --version\n" + printf " colorly --version | -v\n" echo if [[ -n $long_usage ]]; then diff --git a/examples/command-default/ftp b/examples/command-default/ftp index 29707dec..918988a2 100644 --- a/examples/command-default/ftp +++ b/examples/command-default/ftp @@ -20,7 +20,7 @@ ftp_usage() { printf "Usage:\n" printf " ftp [command] [options]\n" printf " ftp [command] --help | -h\n" - printf " ftp --version\n" + printf " ftp --version | -v\n" echo # :command.usage_commands printf "Commands:\n" diff --git a/examples/command-groups/ftp b/examples/command-groups/ftp index d0b3458e..595aac69 100644 --- a/examples/command-groups/ftp +++ b/examples/command-groups/ftp @@ -20,7 +20,7 @@ ftp_usage() { printf "Usage:\n" printf " ftp [command] [options]\n" printf " ftp [command] --help | -h\n" - printf " ftp --version\n" + printf " ftp --version | -v\n" echo # :command.usage_commands printf "File Commands:\n" diff --git a/examples/commands-nested/cli b/examples/commands-nested/cli index 62b55fa1..cb999443 100644 --- a/examples/commands-nested/cli +++ b/examples/commands-nested/cli @@ -20,7 +20,7 @@ cli_usage() { printf "Usage:\n" printf " cli [command] [options]\n" printf " cli [command] --help | -h\n" - printf " cli --version\n" + printf " cli --version | -v\n" echo # :command.usage_commands printf "Commands:\n" diff --git a/examples/commands/cli b/examples/commands/cli index f62ed881..9dbb3edb 100644 --- a/examples/commands/cli +++ b/examples/commands/cli @@ -20,7 +20,7 @@ cli_usage() { printf "Usage:\n" printf " cli [command] [options]\n" printf " cli [command] --help | -h\n" - printf " cli --version\n" + printf " cli --version | -v\n" echo # :command.usage_commands printf "Commands:\n" @@ -352,7 +352,7 @@ cli_upload_parse_requirements() { shift shift else - printf "--user requires an argument: --user, -u USER\n" + printf "%s\n" "--user requires an argument: --user, -u USER" exit 1 fi ;; @@ -364,7 +364,7 @@ cli_upload_parse_requirements() { shift shift else - printf "--password requires an argument: --password, -p PASSWORD\n" + printf "%s\n" "--password requires an argument: --password, -p PASSWORD" exit 1 fi ;; diff --git a/examples/config-ini/configly b/examples/config-ini/configly index e9e6364d..3cbabb7a 100644 --- a/examples/config-ini/configly +++ b/examples/config-ini/configly @@ -20,7 +20,7 @@ configly_usage() { printf "Usage:\n" printf " configly [command] [options]\n" printf " configly [command] --help | -h\n" - printf " configly --version\n" + printf " configly --version | -v\n" echo # :command.usage_commands printf "Commands:\n" diff --git a/examples/custom-includes/download b/examples/custom-includes/download index 44a36689..7c0cd10a 100644 --- a/examples/custom-includes/download +++ b/examples/custom-includes/download @@ -29,7 +29,7 @@ download_usage() { printf "Usage:\n" printf " download [SOURCE] [options]\n" printf " download --help | -h\n" - printf " download --version\n" + printf " download --version | -v\n" echo if [[ -n $long_usage ]]; then diff --git a/examples/custom-strings/download b/examples/custom-strings/download index 629c5ad3..5f734c37 100644 --- a/examples/custom-strings/download +++ b/examples/custom-strings/download @@ -28,7 +28,7 @@ download_usage() { printf "== Usage ==\n\n" printf " download SOURCE [options]\n" printf " download --help | -h\n" - printf " download --version\n" + printf " download --version | -v\n" echo if [[ -n $long_usage ]]; then @@ -109,7 +109,7 @@ parse_requirements() { shift shift else - printf "Hey! the flag --out requires an argument: --out, -o DIR\n" + printf "%s\n" "Hey! the flag --out requires an argument: --out, -o DIR" exit 1 fi ;; diff --git a/examples/dependencies/cli b/examples/dependencies/cli index 02e1eeb0..df4ef3aa 100644 --- a/examples/dependencies/cli +++ b/examples/dependencies/cli @@ -20,7 +20,7 @@ cli_usage() { printf "Usage:\n" printf " cli [command] [options]\n" printf " cli [command] --help | -h\n" - printf " cli --version\n" + printf " cli --version | -v\n" echo # :command.usage_commands printf "Commands:\n" diff --git a/examples/docker-like/docker b/examples/docker-like/docker index 3450594d..8984b9eb 100644 --- a/examples/docker-like/docker +++ b/examples/docker-like/docker @@ -20,7 +20,7 @@ docker_usage() { printf "Usage:\n" printf " docker [command] [options]\n" printf " docker [command] --help | -h\n" - printf " docker --version\n" + printf " docker --version | -v\n" echo # :command.usage_commands printf "Commands:\n" diff --git a/examples/environment-variables/cli b/examples/environment-variables/cli index 38b402a5..52ffe55e 100644 --- a/examples/environment-variables/cli +++ b/examples/environment-variables/cli @@ -20,7 +20,7 @@ cli_usage() { printf "Usage:\n" printf " cli [command] [options]\n" printf " cli [command] --help | -h\n" - printf " cli --version\n" + printf " cli --version | -v\n" echo # :command.usage_commands printf "Commands:\n" diff --git a/examples/git-like/git b/examples/git-like/git index d5602662..80a77161 100644 --- a/examples/git-like/git +++ b/examples/git-like/git @@ -20,7 +20,7 @@ git_usage() { printf "Usage:\n" printf " git [command] [options]\n" printf " git [command] --help | -h\n" - printf " git --version\n" + printf " git --version | -v\n" echo # :command.usage_commands printf "Commands:\n" @@ -274,7 +274,7 @@ git_commit_parse_requirements() { shift shift else - printf "--message requires an argument: --message, -m MESSAGE\n" + printf "%s\n" "--message requires an argument: --message, -m MESSAGE" exit 1 fi ;; diff --git a/examples/minimal/download b/examples/minimal/download index 308285b6..bbde59da 100644 --- a/examples/minimal/download +++ b/examples/minimal/download @@ -28,7 +28,7 @@ download_usage() { printf "Usage:\n" printf " download SOURCE [TARGET] [options]\n" printf " download --help | -h\n" - printf " download --version\n" + printf " download --version | -v\n" echo if [[ -n $long_usage ]]; then diff --git a/examples/minimal/test.sh b/examples/minimal/test.sh index 799ae295..3c2c507e 100644 --- a/examples/minimal/test.sh +++ b/examples/minimal/test.sh @@ -8,5 +8,5 @@ bashly generate ./download ./download -h -./download --version +./download -v ./download somesource -f \ No newline at end of file diff --git a/examples/minus-v/README.md b/examples/minus-v/README.md new file mode 100644 index 00000000..7343ecb5 --- /dev/null +++ b/examples/minus-v/README.md @@ -0,0 +1,7 @@ +Example -v and -h override +================================================== + +This example was generated with: + + $ bashly init --minimal + $ bashly generate diff --git a/examples/minus-v/cli b/examples/minus-v/cli new file mode 100644 index 00000000..c2e1eaf4 --- /dev/null +++ b/examples/minus-v/cli @@ -0,0 +1,156 @@ +#!/usr/bin/env bash +# This script was generated by bashly (https://github.com/DannyBen/bashly) +# Modifying it manually is not recommended + +# :command.root_command +root_command() { + # :src/root_command.sh + echo "# this file is located in 'src/root_command.sh'" + echo "# you can edit it freely and regenerate (it will not be overwritten)" + inspect_args +} + +# :command.version_command +version_command() { + echo "$version" +} + +# :command.usage +cli_usage() { + if [[ -n $long_usage ]]; then + printf "cli - Example that replaces the default behavior of -v and -h\n" + echo + else + printf "cli - Example that replaces the default behavior of -v and -h\n" + echo + fi + + printf "Usage:\n" + printf " cli [options]\n" + printf " cli --help\n" + printf " cli --version\n" + echo + + if [[ -n $long_usage ]]; then + printf "Options:\n" + # :command.usage_fixed_flags + echo " --help" + printf " Show this help\n" + echo + echo " --version" + printf " Show version number\n" + echo + # :command.usage_flags + # :flag.usage + echo " --verbose, -v" + printf " Show verbose output\n" + echo + + # :flag.usage + echo " --host, -h HOST" + printf " Host address\n" + echo + + fi +} + +# :command.inspect_args +inspect_args() { + echo args: + for k in "${!args[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done +} + +# :command.command_functions + +# :command.parse_requirements +parse_requirements() { + # :command.fixed_flag_filter + case "$1" in + --version ) + version_command + exit 1 + ;; + + --help ) + long_usage=yes + cli_usage + exit 1 + ;; + + esac + # :command.environment_variables_filter + # :command.dependencies_filter + # :command.command_filter + action="root" + # :command.required_args_filter + # :command.required_flags_filter + # :command.parse_requirements_while + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + # :flag.case + --verbose | -v ) + args[--verbose]=1 + shift + ;; + + # :flag.case + --host | -h ) + if [[ $2 && $2 != -* ]]; then + args[--host]="$2" + shift + shift + else + printf "%s\n" "--host requires an argument: --host, -h HOST" + 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.initialize +initialize() { + version="0.1.0" + long_usage='' + set -e + + # :src/initialize.sh + # Code here runs inside the initialize() function + # Use it for anything that you need to run before any other function, like + # setting environment vairables: + # CONFIG_FILE=settings.ini + # + # Feel free to empty (but not delete) this file. +} + +# :command.run +run() { + declare -A args + parse_requirements "$@" + + if [[ ${args[--version]} ]]; then + version_command + elif [[ ${args[--help]} ]]; then + long_usage=yes + cli_usage + elif [[ $action == "root" ]]; then + root_command + fi +} + +initialize +run "$@" diff --git a/examples/minus-v/src/bashly.yml b/examples/minus-v/src/bashly.yml new file mode 100644 index 00000000..edc1fe17 --- /dev/null +++ b/examples/minus-v/src/bashly.yml @@ -0,0 +1,14 @@ +name: cli +help: Example that replaces the default behavior of -v and -h +version: 0.1.0 + +flags: +- long: --verbose + short: -v + help: Show verbose output + +- long: --host + short: -h + arg: host + help: Host address + diff --git a/examples/minus-v/src/initialize.sh b/examples/minus-v/src/initialize.sh new file mode 100644 index 00000000..f2dbc52c --- /dev/null +++ b/examples/minus-v/src/initialize.sh @@ -0,0 +1,6 @@ +# Code here runs inside the initialize() function +# Use it for anything that you need to run before any other function, like +# setting environment vairables: +# CONFIG_FILE=settings.ini +# +# Feel free to empty (but not delete) this file. diff --git a/examples/minus-v/src/root_command.sh b/examples/minus-v/src/root_command.sh new file mode 100644 index 00000000..91e64307 --- /dev/null +++ b/examples/minus-v/src/root_command.sh @@ -0,0 +1,3 @@ +echo "# this file is located in 'src/root_command.sh'" +echo "# you can edit it freely and regenerate (it will not be overwritten)" +inspect_args diff --git a/examples/minus-v/test.sh b/examples/minus-v/test.sh new file mode 100644 index 00000000..9560711d --- /dev/null +++ b/examples/minus-v/test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +rm -f ./src/*.sh + +set -x + +bashly generate + +./cli +./cli --help +./cli --version +./cli -h +./cli -v +./cli -h localhost -v diff --git a/examples/multiline/multi b/examples/multiline/multi index 8de8f9e7..6022ead9 100644 --- a/examples/multiline/multi +++ b/examples/multiline/multi @@ -22,7 +22,7 @@ multi_usage() { printf "Usage:\n" printf " multi [command] [options]\n" printf " multi [command] --help | -h\n" - printf " multi --version\n" + printf " multi --version | -v\n" echo # :command.usage_commands printf "Commands:\n" diff --git a/examples/yaml/yaml b/examples/yaml/yaml index 0999d236..a7fd300d 100644 --- a/examples/yaml/yaml +++ b/examples/yaml/yaml @@ -43,7 +43,7 @@ yaml_usage() { printf "Usage:\n" printf " yaml FILENAME [VARIABLE] [options]\n" printf " yaml --help | -h\n" - printf " yaml --version\n" + printf " yaml --version | -v\n" echo if [[ -n $long_usage ]]; then @@ -170,7 +170,7 @@ parse_requirements() { shift shift else - printf "--prefix requires an argument: --prefix, -p PREFIX\n" + printf "%s\n" "--prefix requires an argument: --prefix, -p PREFIX" exit 1 fi ;; diff --git a/lib/bashly/templates/strings.yml b/lib/bashly/templates/strings.yml index bce57b80..f91a82f9 100644 --- a/lib/bashly/templates/strings.yml +++ b/lib/bashly/templates/strings.yml @@ -14,8 +14,6 @@ group: "%{group} Commands:" command_shortcut: "Shortcut: %{short}" default_command_summary: "%{summary} (default)" required: "(required)" -help_flag: "--help | -h" -version_flag: "--version" # Fixed flags help text help_flag_text: Show this help diff --git a/lib/bashly/views/command/usage.erb b/lib/bashly/views/command/usage.erb index 7a873220..33f68d95 100644 --- a/lib/bashly/views/command/usage.erb +++ b/lib/bashly/views/command/usage.erb @@ -23,12 +23,12 @@ printf "<%= strings[:usage] %>\n" printf " <%= usage_string %>\n" <%- if commands.any? -%> - printf " <%= full_name %> [command] --help | -h\n" + printf " <%= full_name %> [command] --help<%= " | -h" unless short_flag_exist? "-h" -%>\n" <%- else -%> - printf " <%= full_name %> <%= strings[:help_flag] %>\n" + printf " <%= full_name %> --help<%= " | -h" unless short_flag_exist? "-h" -%>\n" <%- end -%> <%- if root_command? -%> - printf " <%= full_name %> <%= strings[:version_flag] %>\n" + printf " <%= full_name %> --version<%= " | -v" unless short_flag_exist? "-v" -%>\n" <%- end -%> echo <%= render(:usage_commands).indent 2 if commands.any? %> diff --git a/lib/bashly/views/flag/case.erb b/lib/bashly/views/flag/case.erb index ce7b795c..d57cb817 100644 --- a/lib/bashly/views/flag/case.erb +++ b/lib/bashly/views/flag/case.erb @@ -6,7 +6,7 @@ shift shift else - printf "<%= strings[:flag_requires_an_argument] % { long: long, usage: usage_string } %>\n" + printf "%s\n" "<%= strings[:flag_requires_an_argument] % { long: long, usage: usage_string } %>" exit 1 fi <%- else -%> diff --git a/spec/approvals/examples/command-default b/spec/approvals/examples/command-default index c99e422e..495b46ef 100644 --- a/spec/approvals/examples/command-default +++ b/spec/approvals/examples/command-default @@ -11,7 +11,7 @@ ftp - Sample application that uses the default command option Usage: ftp [command] [options] ftp [command] --help | -h - ftp --version + ftp --version | -v Commands: upload Upload a file (default) @@ -23,7 +23,7 @@ ftp - Sample application that uses the default command option Usage: ftp [command] [options] ftp [command] --help | -h - ftp --version + ftp --version | -v Commands: upload Upload a file (default) diff --git a/spec/approvals/examples/command-groups b/spec/approvals/examples/command-groups index 58872499..6957d7c3 100644 --- a/spec/approvals/examples/command-groups +++ b/spec/approvals/examples/command-groups @@ -13,7 +13,7 @@ ftp - Sample application with command grouping Usage: ftp [command] [options] ftp [command] --help | -h - ftp --version + ftp --version | -v File Commands: download Download a file @@ -29,7 +29,7 @@ ftp - Sample application with command grouping Usage: ftp [command] [options] ftp [command] --help | -h - ftp --version + ftp --version | -v File Commands: download Download a file diff --git a/spec/approvals/examples/commands b/spec/approvals/examples/commands index a3073788..89eb0819 100644 --- a/spec/approvals/examples/commands +++ b/spec/approvals/examples/commands @@ -11,7 +11,7 @@ cli - Sample application Usage: cli [command] [options] cli [command] --help | -h - cli --version + cli --version | -v Commands: download Download a file @@ -23,7 +23,7 @@ cli - Sample application Usage: cli [command] [options] cli [command] --help | -h - cli --version + cli --version | -v Commands: download Download a file diff --git a/spec/approvals/examples/commands-nested b/spec/approvals/examples/commands-nested index ba2dde73..8c674ad6 100644 --- a/spec/approvals/examples/commands-nested +++ b/spec/approvals/examples/commands-nested @@ -13,7 +13,7 @@ cli - Sample application with nested commands Usage: cli [command] [options] cli [command] --help | -h - cli --version + cli --version | -v Commands: dir Directory commands @@ -25,7 +25,7 @@ cli - Sample application with nested commands Usage: cli [command] [options] cli [command] --help | -h - cli --version + cli --version | -v Commands: dir Directory commands diff --git a/spec/approvals/examples/config-ini b/spec/approvals/examples/config-ini index 62012794..dbee6905 100644 --- a/spec/approvals/examples/config-ini +++ b/spec/approvals/examples/config-ini @@ -12,7 +12,7 @@ configly - Sample application that uses the config functions Usage: configly [command] [options] configly [command] --help | -h - configly --version + configly --version | -v Commands: set Save a value in the config file diff --git a/spec/approvals/examples/custom-strings b/spec/approvals/examples/custom-strings index f4f98dfa..6a894d98 100644 --- a/spec/approvals/examples/custom-strings +++ b/spec/approvals/examples/custom-strings @@ -14,7 +14,7 @@ download - Sample minimal application with custom strings download SOURCE [options] download --help | -h - download --version + download --version | -v == Options == diff --git a/spec/approvals/examples/docker-like b/spec/approvals/examples/docker-like index 89d6ea98..b854c552 100644 --- a/spec/approvals/examples/docker-like +++ b/spec/approvals/examples/docker-like @@ -12,7 +12,7 @@ docker - Docker example Usage: docker [command] [options] docker [command] --help | -h - docker --version + docker --version | -v Commands: container Container commands @@ -24,7 +24,7 @@ docker - Docker example Usage: docker [command] [options] docker [command] --help | -h - docker --version + docker --version | -v Commands: container Container commands diff --git a/spec/approvals/examples/environment-variables b/spec/approvals/examples/environment-variables index 39db7b9b..dc6c665a 100644 --- a/spec/approvals/examples/environment-variables +++ b/spec/approvals/examples/environment-variables @@ -10,7 +10,7 @@ cli - Sample application that requires environment variables Usage: cli [command] [options] cli [command] --help | -h - cli --version + cli --version | -v Commands: verify Verify your user @@ -21,7 +21,7 @@ cli - Sample application that requires environment variables Usage: cli [command] [options] cli [command] --help | -h - cli --version + cli --version | -v Commands: verify Verify your user diff --git a/spec/approvals/examples/git-like b/spec/approvals/examples/git-like index 232b32bc..543a35f1 100644 --- a/spec/approvals/examples/git-like +++ b/spec/approvals/examples/git-like @@ -11,7 +11,7 @@ git - Git example Usage: git [command] [options] git [command] --help | -h - git --version + git --version | -v Commands: status Show repository status @@ -23,7 +23,7 @@ git - Git example Usage: git [command] [options] git [command] --help | -h - git --version + git --version | -v Commands: status Show repository status diff --git a/spec/approvals/examples/minimal b/spec/approvals/examples/minimal index 13e9de93..9957f3b8 100644 --- a/spec/approvals/examples/minimal +++ b/spec/approvals/examples/minimal @@ -13,7 +13,7 @@ download - Sample minimal application without commands Usage: download SOURCE [TARGET] [options] download --help | -h - download --version + download --version | -v Options: --help, -h @@ -36,7 +36,7 @@ Examples: download example.com download example.com ./output -f -+ ./download --version ++ ./download -v 0.1.0 + ./download somesource -f # this file is located in 'src/root_command.sh' diff --git a/spec/approvals/examples/minus-v b/spec/approvals/examples/minus-v new file mode 100644 index 00000000..47bb155e --- /dev/null +++ b/spec/approvals/examples/minus-v @@ -0,0 +1,46 @@ ++ bashly generate +creating user files in src +created src/initialize.sh +created src/root_command.sh +created ./cli +run ./cli --help to test your bash script ++ ./cli +# this file is located in 'src/root_command.sh' +# you can edit it freely and regenerate (it will not be overwritten) +args: ++ ./cli --help +cli - Example that replaces the default behavior of -v and -h + +Usage: + cli [options] + cli --help + cli --version + +Options: + --help + Show this help + + --version + Show version number + + --verbose, -v + Show verbose output + + --host, -h HOST + Host address + ++ ./cli --version +0.1.0 ++ ./cli -h +--host requires an argument: --host, -h HOST ++ ./cli -v +# this file is located in 'src/root_command.sh' +# you can edit it freely and regenerate (it will not be overwritten) +args: +- ${args[--verbose]} = 1 ++ ./cli -h localhost -v +# this file is located in 'src/root_command.sh' +# you can edit it freely and regenerate (it will not be overwritten) +args: +- ${args[--host]} = localhost +- ${args[--verbose]} = 1 diff --git a/spec/approvals/examples/multiline b/spec/approvals/examples/multiline index cd5eb44c..00ff0176 100644 --- a/spec/approvals/examples/multiline +++ b/spec/approvals/examples/multiline @@ -11,7 +11,7 @@ multi - Multiline test Usage: multi [command] [options] multi [command] --help | -h - multi --version + multi --version | -v Commands: multiline Do some multiline work. @@ -28,7 +28,7 @@ multi Usage: multi [command] [options] multi [command] --help | -h - multi --version + multi --version | -v Commands: multiline Do some multiline work. diff --git a/spec/approvals/examples/yaml b/spec/approvals/examples/yaml index 0a761f7f..dd075290 100644 --- a/spec/approvals/examples/yaml +++ b/spec/approvals/examples/yaml @@ -10,7 +10,7 @@ yaml - Sample application that uses the YAML functions Usage: yaml FILENAME [VARIABLE] [options] yaml --help | -h - yaml --version + yaml --version | -v Options: --help, -h