From 4d15e2b3985d84a41509f30361add63911b50e9f Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Fri, 2 Aug 2024 02:42:14 +0000 Subject: [PATCH] fix shellcheck --- examples/command-default-force/README.md | 2 +- examples/command-default/README.md | 32 +++++++++ examples/conflicts/README.md | 3 + examples/needs/README.md | 86 +++++++++++++++--------- examples/needs/src/bashly.yml | 2 +- examples/render-mandoc/README.md | 2 +- lib/bashly/views/flag/needs.gtx | 31 ++++++--- 7 files changed, 113 insertions(+), 45 deletions(-) diff --git a/examples/command-default-force/README.md b/examples/command-default-force/README.md index c65df87a4..371ef9fea 100644 --- a/examples/command-default-force/README.md +++ b/examples/command-default-force/README.md @@ -93,7 +93,7 @@ args: none tester all - Run all tests Usage: - tester all + tester [all] tester all --help | -h Options: diff --git a/examples/command-default/README.md b/examples/command-default/README.md index f77f94800..1e4b37615 100644 --- a/examples/command-default/README.md +++ b/examples/command-default/README.md @@ -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` diff --git a/examples/conflicts/README.md b/examples/conflicts/README.md index f18b4807e..ef215eeea 100644 --- a/examples/conflicts/README.md +++ b/examples/conflicts/README.md @@ -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 diff --git a/examples/needs/README.md b/examples/needs/README.md index 8b2b2fc61..a3ff0b50e 100644 --- a/examples/needs/README.md +++ b/examples/needs/README.md @@ -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 @@ -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 ```` diff --git a/examples/needs/src/bashly.yml b/examples/needs/src/bashly.yml index 03b8f1726..c45f1ab68 100644 --- a/examples/needs/src/bashly.yml +++ b/examples/needs/src/bashly.yml @@ -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: diff --git a/examples/render-mandoc/README.md b/examples/render-mandoc/README.md index 5462306d2..08109e37c 100644 --- a/examples/render-mandoc/README.md +++ b/examples/render-mandoc/README.md @@ -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) ```` diff --git a/lib/bashly/views/flag/needs.gtx b/lib/bashly/views/flag/needs.gtx index f57ff23c7..2f5b92aa7 100644 --- a/lib/bashly/views/flag/needs.gtx +++ b/lib/bashly/views/flag/needs.gtx @@ -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 -> \ No newline at end of file + = 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 \ No newline at end of file