From 1422bcf3ba5bd54f2248b4b4a97c8930709f44f3 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Fri, 29 Mar 2024 05:09:22 +0000 Subject: [PATCH] - Add `[--]` to usage text when `catch_all` is used --- examples/catch-all-advanced/README.md | 52 ++++++++++++++++--- examples/catch-all-stdin/README.md | 2 +- examples/catch-all/README.md | 4 +- lib/bashly/script/catch_all.rb | 2 +- spec/approvals/examples/catch-all | 4 +- spec/approvals/examples/catch-all-advanced | 6 +-- spec/approvals/examples/catch-all-stdin | 2 +- spec/approvals/fixtures/catch-all-no-args | 2 +- .../mandoc/catch-all-advanced/cli-download.md | 2 +- .../mandoc/catch-all-advanced/cli-upload.md | 2 +- .../catch-all-advanced/cli download.md | 2 +- .../markdown/catch-all-advanced/cli upload.md | 2 +- spec/bashly/script/catch_all_spec.rb | 6 +-- spec/bashly/script/command_spec.rb | 8 +-- 14 files changed, 66 insertions(+), 30 deletions(-) diff --git a/examples/catch-all-advanced/README.md b/examples/catch-all-advanced/README.md index cdc8cf5d..58c5749b 100644 --- a/examples/catch-all-advanced/README.md +++ b/examples/catch-all-advanced/README.md @@ -90,7 +90,7 @@ cli download - Download a file Alias: d Usage: - cli download SOURCE [TARGET] [OPTIONS] [AWS PARAMS...] + cli download SOURCE [TARGET] [OPTIONS] [--] [AWS PARAMS...] cli download --help | -h Options: @@ -143,21 +143,57 @@ args: ```` -### `$ ./cli download source target and --additional stuff` +### `$ ./cli download source target --force` ````shell # this file is located in 'src/download_command.sh' # code for 'cli download' goes here # you can edit it freely and regenerate (it will not be overwritten) args: +- ${args[--force]} = 1 +- ${args[source]} = source +- ${args[target]} = target + + +```` + +### `$ ./cli download source target --force -abc --option=value` + +````shell +# this file is located in 'src/download_command.sh' +# code for 'cli download' goes here +# you can edit it freely and regenerate (it will not be overwritten) +args: +- ${args[--force]} = 1 +- ${args[source]} = source +- ${args[target]} = target + +other_args: +- ${other_args[*]} = -a -b -c --option value +- ${other_args[0]} = -a +- ${other_args[1]} = -b +- ${other_args[2]} = -c +- ${other_args[3]} = --option +- ${other_args[4]} = value + + +```` + +### `$ ./cli download source target --force -- -abc --option=value` + +````shell +# this file is located in 'src/download_command.sh' +# code for 'cli download' goes here +# you can edit it freely and regenerate (it will not be overwritten) +args: +- ${args[--force]} = 1 - ${args[source]} = source - ${args[target]} = target other_args: -- ${other_args[*]} = and --additional stuff -- ${other_args[0]} = and -- ${other_args[1]} = --additional -- ${other_args[2]} = stuff +- ${other_args[*]} = -abc --option=value +- ${other_args[0]} = -abc +- ${other_args[1]} = --option=value ```` @@ -170,7 +206,7 @@ cli upload - Upload a file Alias: u Usage: - cli upload FILES... + cli upload [--] FILES... cli upload --help | -h Options: @@ -189,7 +225,7 @@ Arguments: ````shell missing required argument: FILES... -usage: cli upload FILES... +usage: cli upload [--] FILES... ```` diff --git a/examples/catch-all-stdin/README.md b/examples/catch-all-stdin/README.md index 86c8e462..6d62687f 100644 --- a/examples/catch-all-stdin/README.md +++ b/examples/catch-all-stdin/README.md @@ -74,7 +74,7 @@ echo cli - Sample application Usage: - cli [OPTIONS] [FILE...] + cli [OPTIONS] [--] [FILE...] cli --help | -h cli --version | -v diff --git a/examples/catch-all/README.md b/examples/catch-all/README.md index 74ebf0fc..2b5da2db 100644 --- a/examples/catch-all/README.md +++ b/examples/catch-all/README.md @@ -41,7 +41,7 @@ flags: ````shell missing required argument: MESSAGE -usage: download MESSAGE [OPTIONS] [...] +usage: download MESSAGE [OPTIONS] [--] [...] ```` @@ -52,7 +52,7 @@ usage: download MESSAGE [OPTIONS] [...] download - Catch All Example Usage: - download MESSAGE [OPTIONS] [...] + download MESSAGE [OPTIONS] [--] [...] download --help | -h download --version | -v diff --git a/lib/bashly/script/catch_all.rb b/lib/bashly/script/catch_all.rb index a0f1f1c4..b2abdddb 100644 --- a/lib/bashly/script/catch_all.rb +++ b/lib/bashly/script/catch_all.rb @@ -48,7 +48,7 @@ def required? def usage_string return nil unless enabled? - required? ? label : "[#{label}]" + required? ? "[--] #{label}" : "[--] [#{label}]" end end end diff --git a/spec/approvals/examples/catch-all b/spec/approvals/examples/catch-all index 19732f54..cd6b209c 100644 --- a/spec/approvals/examples/catch-all +++ b/spec/approvals/examples/catch-all @@ -5,12 +5,12 @@ created ./download run ./download --help to test your bash script + ./download missing required argument: MESSAGE -usage: download MESSAGE [OPTIONS] [...] +usage: download MESSAGE [OPTIONS] [--] [...] + ./download -h download - Catch All Example Usage: - download MESSAGE [OPTIONS] [...] + download MESSAGE [OPTIONS] [--] [...] download --help | -h download --version | -v diff --git a/spec/approvals/examples/catch-all-advanced b/spec/approvals/examples/catch-all-advanced index 24c577fc..4c0bb2fc 100644 --- a/spec/approvals/examples/catch-all-advanced +++ b/spec/approvals/examples/catch-all-advanced @@ -22,7 +22,7 @@ cli download - Download a file Alias: d Usage: - cli download SOURCE [TARGET] [OPTIONS] [AWS PARAMS...] + cli download SOURCE [TARGET] [OPTIONS] [--] [AWS PARAMS...] cli download --help | -h Options: @@ -102,7 +102,7 @@ cli upload - Upload a file Alias: u Usage: - cli upload FILES... + cli upload [--] FILES... cli upload --help | -h Options: @@ -115,7 +115,7 @@ Arguments: + ./cli upload missing required argument: FILES... -usage: cli upload FILES... +usage: cli upload [--] FILES... + ./cli upload file1 'file 2' file3 # this file is located in 'src/upload_command.sh' # code for 'cli upload' goes here diff --git a/spec/approvals/examples/catch-all-stdin b/spec/approvals/examples/catch-all-stdin index 67beb900..6c8140d7 100644 --- a/spec/approvals/examples/catch-all-stdin +++ b/spec/approvals/examples/catch-all-stdin @@ -5,7 +5,7 @@ run ./cli --help to test your bash script cli - Sample application Usage: - cli [OPTIONS] [FILE...] + cli [OPTIONS] [--] [FILE...] cli --help | -h cli --version | -v diff --git a/spec/approvals/fixtures/catch-all-no-args b/spec/approvals/fixtures/catch-all-no-args index 2923e679..a8c60fa9 100644 --- a/spec/approvals/fixtures/catch-all-no-args +++ b/spec/approvals/fixtures/catch-all-no-args @@ -11,7 +11,7 @@ args: none download - Download something Usage: - download [URLS...] + download [--] [URLS...] download --help | -h download --version | -v diff --git a/spec/approvals/rendering/mandoc/catch-all-advanced/cli-download.md b/spec/approvals/rendering/mandoc/catch-all-advanced/cli-download.md index a092ea1d..71032227 100644 --- a/spec/approvals/rendering/mandoc/catch-all-advanced/cli-download.md +++ b/spec/approvals/rendering/mandoc/catch-all-advanced/cli-download.md @@ -10,7 +10,7 @@ NAME SYNOPSIS ================================================== -**cli download** SOURCE [TARGET] [OPTIONS] [AWS PARAMS...] +**cli download** SOURCE [TARGET] [OPTIONS] [--] [AWS PARAMS...] DESCRIPTION ================================================== diff --git a/spec/approvals/rendering/mandoc/catch-all-advanced/cli-upload.md b/spec/approvals/rendering/mandoc/catch-all-advanced/cli-upload.md index 1c16ef5b..8dbe8578 100644 --- a/spec/approvals/rendering/mandoc/catch-all-advanced/cli-upload.md +++ b/spec/approvals/rendering/mandoc/catch-all-advanced/cli-upload.md @@ -10,7 +10,7 @@ NAME SYNOPSIS ================================================== -**cli upload** FILES... +**cli upload** [--] FILES... DESCRIPTION ================================================== diff --git a/spec/approvals/rendering/markdown/catch-all-advanced/cli download.md b/spec/approvals/rendering/markdown/catch-all-advanced/cli download.md index 6af73eaf..81dc0689 100644 --- a/spec/approvals/rendering/markdown/catch-all-advanced/cli download.md +++ b/spec/approvals/rendering/markdown/catch-all-advanced/cli download.md @@ -9,7 +9,7 @@ Download a file ## Usage ```bash -cli download SOURCE [TARGET] [OPTIONS] [AWS PARAMS...] +cli download SOURCE [TARGET] [OPTIONS] [--] [AWS PARAMS...] ``` ## Examples diff --git a/spec/approvals/rendering/markdown/catch-all-advanced/cli upload.md b/spec/approvals/rendering/markdown/catch-all-advanced/cli upload.md index a68b3a42..c32ecabd 100644 --- a/spec/approvals/rendering/markdown/catch-all-advanced/cli upload.md +++ b/spec/approvals/rendering/markdown/catch-all-advanced/cli upload.md @@ -9,7 +9,7 @@ Upload a file ## Usage ```bash -cli upload FILES... +cli upload [--] FILES... ``` diff --git a/spec/bashly/script/catch_all_spec.rb b/spec/bashly/script/catch_all_spec.rb index 9a9d7ce2..9414f908 100644 --- a/spec/bashly/script/catch_all_spec.rb +++ b/spec/bashly/script/catch_all_spec.rb @@ -97,7 +97,7 @@ let(:fixture) { :catch_all_hash } it 'returns a usage help without []' do - expect(subject.usage_string).to eq 'ADDITIONAL_PARAMS...' + expect(subject.usage_string).to eq '[--] ADDITIONAL_PARAMS...' end end @@ -105,7 +105,7 @@ let(:fixture) { :catch_all_string } it 'returns a usage help with []' do - expect(subject.usage_string).to eq '[EXTRA_PARAMS...]' + expect(subject.usage_string).to eq '[--] [EXTRA_PARAMS...]' end end @@ -113,7 +113,7 @@ let(:fixture) { :catch_all } it 'returns [...]' do - expect(subject.usage_string).to eq '[...]' + expect(subject.usage_string).to eq '[--] [...]' end end end diff --git a/spec/bashly/script/command_spec.rb b/spec/bashly/script/command_spec.rb index bd74d5ae..1931a54f 100644 --- a/spec/bashly/script/command_spec.rb +++ b/spec/bashly/script/command_spec.rb @@ -617,7 +617,7 @@ let(:fixture) { :mode_args_and_flags } it 'returns the correct string' do - expect(subject.usage_string).to eq 'get SOURCE [TARGET] [OPTIONS] [PARAMS...]' + expect(subject.usage_string).to eq 'get SOURCE [TARGET] [OPTIONS] [--] [PARAMS...]' end end @@ -625,7 +625,7 @@ let(:fixture) { :mode_args } it 'returns the correct string' do - expect(subject.usage_string).to eq 'get SOURCE [TARGET] [PARAMS...]' + expect(subject.usage_string).to eq 'get SOURCE [TARGET] [--] [PARAMS...]' end end @@ -633,7 +633,7 @@ let(:fixture) { :mode_flags } it 'returns the correct string' do - expect(subject.usage_string).to eq 'get [OPTIONS] [PARAMS...]' + expect(subject.usage_string).to eq 'get [OPTIONS] [--] [PARAMS...]' end context 'when it has a parent' do @@ -649,7 +649,7 @@ let(:fixture) { :mode_empty } it 'returns the correct string' do - expect(subject.usage_string).to eq 'get [PARAMS...]' + expect(subject.usage_string).to eq 'get [--] [PARAMS...]' end context 'when it has a parent' do