Skip to content

Commit

Permalink
fix shellcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyBen committed Aug 2, 2024
1 parent cb05983 commit 4d15e2b
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 45 deletions.
2 changes: 1 addition & 1 deletion examples/command-default-force/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ args: none
tester all - Run all tests

Usage:
tester all
tester [all]
tester all --help | -h

Options:
Expand Down
32 changes: 32 additions & 0 deletions examples/command-default/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,38 @@ args:
- ${args[source]} = something


````

### `$ ./ftp upload`

````shell
missing required argument: SOURCE
usage: ftp [upload] SOURCE


````

### `$ ./ftp upload -h`

````shell
ftp upload - Upload a file

Alias: u

Usage:
ftp [upload] SOURCE
ftp upload --help | -h

Options:
--help, -h
Show this help

Arguments:
SOURCE
File to upload



````

### `$ ./ftp upload something`
Expand Down
3 changes: 3 additions & 0 deletions examples/conflicts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ Usage:
Options:
--cache
Enable cache
Conflicts: --no-cache

--no-cache
Disable cache
Conflicts: --cache, --fast

--fast
Run faster
Conflicts: --no-cache

--help, -h
Show this help
Expand Down
86 changes: 54 additions & 32 deletions examples/needs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,60 @@ $ bashly generate
## `bashly.yml`

````yaml
name: download
help: Sample application to demonstrate the use of conflicting flags
name: cli
help: Sample application to demonstrate the use of needy flags
version: 0.1.0

flags:
- long: --cache
help: Enable cache
# Running --cache with --no-cache is not permitted
conflicts: [--no-cache]
- long: --no-cache
help: Disable cache
# Running --no-cache with --cache or with --fast is not permitted
conflicts: [--cache, --fast]
- long: --fast
help: Run faster
# Make sure to add the conflicting flags in both flags
conflicts: [--no-cache]
- long: --add
short: -a
arg: alias
help: Alias to add
# When using --add, --command and --target must also be provided
needs: [--command, --target]

- long: --command
short: -c
arg: command
help: Command for the alias
# Note that this relationship is marked on both sides
needs: [--add]

- long: --target
short: -t
arg: target
help: Where to add the alias
needs: [--add]
allowed: [global, local]
````



## Output

### `$ ./download -h`
### `$ ./cli -h`

````shell
download - Sample application to demonstrate the use of conflicting flags
cli - Sample application to demonstrate the use of needy flags

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

Options:
--cache
Enable cache
--add, -a ALIAS
Alias to add
Needs: --command, --target

--no-cache
Disable cache
--command, -c COMMAND
Command for the alias
Needs: --add

--fast
Run faster
--target, -t TARGET
Where to add the alias
Allowed: global, local
Needs: --add

--help, -h
Show this help
Expand All @@ -68,21 +80,31 @@ Options:

````

### `$ ./download --cache`
### `$ ./cli --add deploy`

````shell
# this file is located in 'src/root_command.sh'
# you can edit it freely and regenerate (it will not be overwritten)
args:
- ${args[--cache]} = 1
--add requires --command


````

### `$ ./cli --add deploy --command 'git push'`

````shell
--add requires --target


````

### `$ ./download --no-cache --fast`
### `$ ./cli --add deploy --command 'git push' --target local`

````shell
conflicting options: --fast cannot be used with --no-cache
# this file is located in 'src/root_command.sh'
# you can edit it freely and regenerate (it will not be overwritten)
args:
- ${args[--add]} = deploy
- ${args[--command]} = git push
- ${args[--target]} = local


````
Expand Down
2 changes: 1 addition & 1 deletion examples/needs/src/bashly.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: cli
help: Sample application to demonstrate the use of conflicting flags
help: Sample application to demonstrate the use of needy flags
version: 0.1.0

flags:
Expand Down
2 changes: 1 addition & 1 deletion examples/render-mandoc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ ISSUE TRACKER
AUTHORS
Lana Lang.

Version 0.1.0 July 2024 download(1)
Version 0.1.0 August 2024 download(1)


````
Expand Down
31 changes: 21 additions & 10 deletions lib/bashly/views/flag/needs.gtx
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
= view_marker
if needs

> if [[ -n ${args['{{ name }}']+x} ]]; then
> for need in {{ needs.join ' ' }}; do
> if [[ -z "${args[$need]:-}" ]]; then
> printf "%s\n" "{{ strings[:flag_requires_another] % { name: name, need: "$need" } }}" >&2
> exit 1
> fi
> done
> fi
>
= view_marker

if needs.count == 1
> if [[ -n ${args['{{ name }}']+x} ]] && [[ -z "${args[{{ needs.first }}]:-}" ]]; then
> printf "%s\n" "{{ strings[:flag_requires_another] % { name: name, need: needs.first } }}" >&2
> exit 1
> fi
>
else
> if [[ -n ${args['{{ name }}']+x} ]]; then
> for need in {{ needs.join ' ' }}; do
> if [[ -z "${args[$need]:-}" ]]; then
> printf "%s\n" "{{ strings[:flag_requires_another] % { name: name, need: "$need" } }}" >&2
> exit 1
> fi
> done
> fi
>
end
end

0 comments on commit 4d15e2b

Please sign in to comment.