diff --git a/examples/config-ini/configly b/examples/config-ini/configly index d2462c81..02dba791 100644 --- a/examples/config-ini/configly +++ b/examples/config-ini/configly @@ -299,18 +299,21 @@ parse_args() { ;; set | s ) + action=set shift set_parse_args "$@" shift $# ;; get | g ) + action=get shift get_parse_args "$@" shift $# ;; list | l ) + action=list shift list_parse_args "$@" shift $# diff --git a/examples/custom-strings/test.sh b/examples/custom-strings/test.sh index 111ac5c7..f6958596 100644 --- a/examples/custom-strings/test.sh +++ b/examples/custom-strings/test.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash -set -x - rm -f ./src/*.sh +set -x + bashly generate ./download diff --git a/examples/minimal/test.sh b/examples/minimal/test.sh index f6197016..799ae295 100644 --- a/examples/minimal/test.sh +++ b/examples/minimal/test.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash -set -x - rm -f ./src/*.sh +set -x + bashly generate ./download diff --git a/examples/subcommands/cli b/examples/subcommands/cli index dbee4684..6a042605 100644 --- a/examples/subcommands/cli +++ b/examples/subcommands/cli @@ -186,12 +186,14 @@ parse_args() { ;; download | d ) + action=download shift download_parse_args "$@" shift $# ;; upload | u ) + action=upload shift upload_parse_args "$@" shift $# diff --git a/examples/subcommands/test.sh b/examples/subcommands/test.sh index dfa6b2bd..3e8cae3e 100644 --- a/examples/subcommands/test.sh +++ b/examples/subcommands/test.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash -set -x - rm -f ./src/*.sh +set -x + bashly generate ./cli diff --git a/lib/bashly/views/command/command_filter.erb b/lib/bashly/views/command/command_filter.erb index 46e78272..4b222710 100644 --- a/lib/bashly/views/command/command_filter.erb +++ b/lib/bashly/views/command/command_filter.erb @@ -8,6 +8,7 @@ case $action in <%- commands.each do |command| -%> <%= command.aliases.join " | " %> ) + action=<%= command.name %> shift <%= command.name %>_parse_args "$@" shift $# diff --git a/spec/approvals/examples/custom-strings b/spec/approvals/examples/custom-strings index 4bd97e42..f03f2741 100644 --- a/spec/approvals/examples/custom-strings +++ b/spec/approvals/examples/custom-strings @@ -1,4 +1,3 @@ -+ rm -f ./src/root_command.sh + bashly generate creating user files in src created src/root_command.sh diff --git a/spec/approvals/examples/minimal b/spec/approvals/examples/minimal index 2a57a19c..d4472ef8 100644 --- a/spec/approvals/examples/minimal +++ b/spec/approvals/examples/minimal @@ -1,4 +1,3 @@ -+ rm -f ./src/root_command.sh + bashly generate creating user files in src created src/root_command.sh diff --git a/spec/approvals/examples/short-flag b/spec/approvals/examples/short-flag new file mode 100644 index 00000000..fc628d15 --- /dev/null +++ b/spec/approvals/examples/short-flag @@ -0,0 +1,14 @@ ++ bashly generate +creating user files in src +created src/rush_config_command.sh +created src/rush_get_command.sh +created ./rush +run ./rush --help to test your bash script ++ ./rush c +# this file is located in 'src/rush_config_command.sh' +# code for 'rush config' goes here +# you can edit it freely and regenerate (it will not be overwritten) +args: ++ ./rush g +missing required argument: REPO +usage: rush get REPO [options] diff --git a/spec/approvals/examples/subcommands b/spec/approvals/examples/subcommands index f6b4c215..b106c4a8 100644 --- a/spec/approvals/examples/subcommands +++ b/spec/approvals/examples/subcommands @@ -1,4 +1,3 @@ -+ rm -f ./src/cli_download_command.sh ./src/cli_upload_command.sh + bashly generate creating user files in src created src/cli_download_command.sh diff --git a/spec/bashly/integration/script_spec.rb b/spec/bashly/integration/examples_spec.rb similarity index 67% rename from spec/bashly/integration/script_spec.rb rename to spec/bashly/integration/examples_spec.rb index 45ccbde3..486fdcfe 100644 --- a/spec/bashly/integration/script_spec.rb +++ b/spec/bashly/integration/examples_spec.rb @@ -6,11 +6,19 @@ # folder describe 'generated bash scripts' do + # Test public examples from the examples folder... examples = Dir["examples/*"].select { |f| File.directory? f } + # ...as well as internal examples, not suitable for public view + fixtures = Dir["spec/fixtures/workspaces/*"].select { |f| File.directory? f } + + test_cases = fixtures + examples + leeway = ENV['CI'] ? 40 : 0 - examples.each do |example| + test_cases.each do |example| + approval_name = example.gsub "spec/fixtures/workspaces", "examples" + describe example do it "works" do output = "not executed" @@ -22,7 +30,7 @@ # This was observed in at least these two cases: # - The "+ ..." shell messages driven by `set -x` have no space # - The order of our `inspect_args` sometimes differs - expect(output).to match_fixture(example).diff(leeway) + expect(output).to match_fixture(approval_name).diff(leeway) end end end diff --git a/spec/fixtures/workspaces/short-flag/.gitignore b/spec/fixtures/workspaces/short-flag/.gitignore new file mode 100644 index 00000000..8314185d --- /dev/null +++ b/spec/fixtures/workspaces/short-flag/.gitignore @@ -0,0 +1,2 @@ +rush +src/*.sh \ No newline at end of file diff --git a/spec/fixtures/workspaces/short-flag/README.md b/spec/fixtures/workspaces/short-flag/README.md new file mode 100644 index 00000000..39cc7303 --- /dev/null +++ b/spec/fixtures/workspaces/short-flag/README.md @@ -0,0 +1,2 @@ +This fixture tests that short flags work properly +Reference issue: https://github.com/DannyBen/bashly/issues/16 \ No newline at end of file diff --git a/spec/fixtures/workspaces/short-flag/src/bashly.yml b/spec/fixtures/workspaces/short-flag/src/bashly.yml new file mode 100644 index 00000000..97705f0c --- /dev/null +++ b/spec/fixtures/workspaces/short-flag/src/bashly.yml @@ -0,0 +1,17 @@ +name: rush +help: Personal package manager +version: 0.1.0 + +commands: +- name: config + short: c + help: Show the configuration file + +- name: get + short: g + help: Install a package + + args: + - name: repo + required: true + help: Repository name diff --git a/spec/fixtures/workspaces/short-flag/test.sh b/spec/fixtures/workspaces/short-flag/test.sh new file mode 100644 index 00000000..09de7c7e --- /dev/null +++ b/spec/fixtures/workspaces/short-flag/test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# This fixture tests that short flags work properly +# Reference issue: https://github.com/DannyBen/bashly/issues/16 + +rm -f ./src/*.sh +rm -f ./rush + +set -x + +bashly generate + +./rush c +./rush g