Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add [--] to usage text when catch_all is used #512

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 44 additions & 8 deletions examples/catch-all-advanced/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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


````
Expand All @@ -170,7 +206,7 @@ cli upload - Upload a file
Alias: u

Usage:
cli upload FILES...
cli upload [--] FILES...
cli upload --help | -h

Options:
Expand All @@ -189,7 +225,7 @@ Arguments:

````shell
missing required argument: FILES...
usage: cli upload FILES...
usage: cli upload [--] FILES...


````
Expand Down
2 changes: 1 addition & 1 deletion examples/catch-all-stdin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ echo
cli - Sample application

Usage:
cli [OPTIONS] [FILE...]
cli [OPTIONS] [--] [FILE...]
cli --help | -h
cli --version | -v

Expand Down
4 changes: 2 additions & 2 deletions examples/catch-all/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ flags:

````shell
missing required argument: MESSAGE
usage: download MESSAGE [OPTIONS] [...]
usage: download MESSAGE [OPTIONS] [--] [...]


````
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/bashly/script/catch_all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def required?
def usage_string
return nil unless enabled?

required? ? label : "[#{label}]"
required? ? "[--] #{label}" : "[--] [#{label}]"
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/approvals/examples/catch-all
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions spec/approvals/examples/catch-all-advanced
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -102,7 +102,7 @@ cli upload - Upload a file
Alias: u

Usage:
cli upload FILES...
cli upload [--] FILES...
cli upload --help | -h

Options:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/approvals/examples/catch-all-stdin
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/approvals/fixtures/catch-all-no-args
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ args: none
download - Download something

Usage:
download [URLS...]
download [--] [URLS...]
download --help | -h
download --version | -v

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ NAME
SYNOPSIS
==================================================

**cli download** SOURCE [TARGET] [OPTIONS] [AWS PARAMS...]
**cli download** SOURCE [TARGET] [OPTIONS] [--] [AWS PARAMS...]

DESCRIPTION
==================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ NAME
SYNOPSIS
==================================================

**cli upload** FILES...
**cli upload** [--] FILES...

DESCRIPTION
==================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Download a file
## Usage

```bash
cli download SOURCE [TARGET] [OPTIONS] [AWS PARAMS...]
cli download SOURCE [TARGET] [OPTIONS] [--] [AWS PARAMS...]
```

## Examples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Upload a file
## Usage

```bash
cli upload FILES...
cli upload [--] FILES...
```


6 changes: 3 additions & 3 deletions spec/bashly/script/catch_all_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,23 @@
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

context "when catch_all['required'] is false" do
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

context 'when catch_all is true' do
let(:fixture) { :catch_all }

it 'returns [...]' do
expect(subject.usage_string).to eq '[...]'
expect(subject.usage_string).to eq '[--] [...]'
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/bashly/script/command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -617,23 +617,23 @@
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

context 'when only args are defined' do
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

context 'when only flags are defined' do
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
Expand All @@ -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
Expand Down