From 84aa0ed684b85ba031611045a2818926a47559bf Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Thu, 21 Nov 2019 16:17:03 +0000 Subject: [PATCH 1/3] fix short flag bug - closes #16 --- examples/config-ini/configly | 3 +++ examples/subcommands/cli | 2 ++ lib/bashly/views/command/command_filter.erb | 1 + .../spec/fixtures/workspaces/short-flag | 16 ++++++++++++++++ .../{script_spec.rb => examples_spec.rb} | 8 +++++++- spec/fixtures/workspaces/short-flag/.gitignore | 2 ++ spec/fixtures/workspaces/short-flag/README.md | 2 ++ .../workspaces/short-flag/src/bashly.yml | 17 +++++++++++++++++ spec/fixtures/workspaces/short-flag/test.sh | 14 ++++++++++++++ 9 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 spec/approvals/spec/fixtures/workspaces/short-flag rename spec/bashly/integration/{script_spec.rb => examples_spec.rb} (77%) create mode 100644 spec/fixtures/workspaces/short-flag/.gitignore create mode 100644 spec/fixtures/workspaces/short-flag/README.md create mode 100644 spec/fixtures/workspaces/short-flag/src/bashly.yml create mode 100644 spec/fixtures/workspaces/short-flag/test.sh 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/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/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/spec/fixtures/workspaces/short-flag b/spec/approvals/spec/fixtures/workspaces/short-flag new file mode 100644 index 00000000..ae987fc4 --- /dev/null +++ b/spec/approvals/spec/fixtures/workspaces/short-flag @@ -0,0 +1,16 @@ ++ rm -f ./src/rush_config_command.sh ./src/rush_get_command.sh ++ rm -f ./rush ++ 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/bashly/integration/script_spec.rb b/spec/bashly/integration/examples_spec.rb similarity index 77% rename from spec/bashly/integration/script_spec.rb rename to spec/bashly/integration/examples_spec.rb index 45ccbde3..1ffff763 100644 --- a/spec/bashly/integration/script_spec.rb +++ b/spec/bashly/integration/examples_spec.rb @@ -6,11 +6,17 @@ # 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| describe example do it "works" do output = "not executed" 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..329b7a43 --- /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 + +set -x + +rm -f ./src/*.sh +rm -f ./rush + +bashly generate + +./rush c +./rush g From ee71b1ff704a2bdbc1fe63f9921f9b3d9a9c7c41 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Thu, 21 Nov 2019 16:21:37 +0000 Subject: [PATCH 2/3] fix integration test approval location --- .../{spec/fixtures/workspaces => examples}/short-flag | 0 spec/bashly/integration/examples_spec.rb | 4 +++- 2 files changed, 3 insertions(+), 1 deletion(-) rename spec/approvals/{spec/fixtures/workspaces => examples}/short-flag (100%) diff --git a/spec/approvals/spec/fixtures/workspaces/short-flag b/spec/approvals/examples/short-flag similarity index 100% rename from spec/approvals/spec/fixtures/workspaces/short-flag rename to spec/approvals/examples/short-flag diff --git a/spec/bashly/integration/examples_spec.rb b/spec/bashly/integration/examples_spec.rb index 1ffff763..486fdcfe 100644 --- a/spec/bashly/integration/examples_spec.rb +++ b/spec/bashly/integration/examples_spec.rb @@ -17,6 +17,8 @@ leeway = ENV['CI'] ? 40 : 0 test_cases.each do |example| + approval_name = example.gsub "spec/fixtures/workspaces", "examples" + describe example do it "works" do output = "not executed" @@ -28,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 From 54770dfee42b281a108f0dc8da7ae47d551f6c93 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Thu, 21 Nov 2019 16:28:00 +0000 Subject: [PATCH 3/3] improve ci by avoiding the echo of the rm commands --- examples/custom-strings/test.sh | 4 ++-- examples/minimal/test.sh | 4 ++-- examples/subcommands/test.sh | 4 ++-- spec/approvals/examples/custom-strings | 1 - spec/approvals/examples/minimal | 1 - spec/approvals/examples/short-flag | 2 -- spec/approvals/examples/subcommands | 1 - spec/fixtures/workspaces/short-flag/test.sh | 4 ++-- 8 files changed, 8 insertions(+), 13 deletions(-) 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/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/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 index ae987fc4..fc628d15 100644 --- a/spec/approvals/examples/short-flag +++ b/spec/approvals/examples/short-flag @@ -1,5 +1,3 @@ -+ rm -f ./src/rush_config_command.sh ./src/rush_get_command.sh -+ rm -f ./rush + bashly generate creating user files in src created src/rush_config_command.sh 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/fixtures/workspaces/short-flag/test.sh b/spec/fixtures/workspaces/short-flag/test.sh index 329b7a43..09de7c7e 100644 --- a/spec/fixtures/workspaces/short-flag/test.sh +++ b/spec/fixtures/workspaces/short-flag/test.sh @@ -3,11 +3,11 @@ # This fixture tests that short flags work properly # Reference issue: https://github.com/DannyBen/bashly/issues/16 -set -x - rm -f ./src/*.sh rm -f ./rush +set -x + bashly generate ./rush c