From f962483ff662b86b8410c994159677195b24348b Mon Sep 17 00:00:00 2001 From: dubo-dubon-duponey Date: Sat, 1 Dec 2018 22:00:15 -0800 Subject: [PATCH 1/3] Work around gnu grep attempt #1 Signed-off-by: dubo-dubon-duponey --- source/core/abash.sh | 8 ++++++++ source/core/commander.sh | 13 +++++++++++-- tests/unit/arg.sh | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 tests/unit/arg.sh diff --git a/source/core/abash.sh b/source/core/abash.sh index bcaf9a1..0d480d8 100644 --- a/source/core/abash.sh +++ b/source/core/abash.sh @@ -17,3 +17,11 @@ _have_bash(){ } _have_bash + +_gnu_grep(){ + if grep --version | grep -q gnu; then + readonly _GNUGREP="true" + fi +} + +_gnu_grep diff --git a/source/core/commander.sh b/source/core/commander.sh index edaded8..1912752 100644 --- a/source/core/commander.sh +++ b/source/core/commander.sh @@ -72,7 +72,11 @@ dc::commander::declare::arg(){ local optional="$3" local fancy="$4" local description="$5" - local gf="${6:--Ei}" + if [ "$_GNUGREP" ]; then + gf="${6:--Pi}" + else + gf="${6:--Ei}" + fi local var="DC_PARGV_$number" local varexist="DC_PARGE_$number" @@ -122,7 +126,12 @@ dc::commander::declare::flag(){ local optional="$3" local description="$4" local alias="$5" - local gf="${6:--Ei}" + local gf + if [ "$_GNUGREP" ]; then + gf="${6:--Pi}" + else + gf="${6:--Ei}" + fi local display="--$name" local long="--$name" diff --git a/tests/unit/arg.sh b/tests/unit/arg.sh new file mode 100644 index 0000000..7927756 --- /dev/null +++ b/tests/unit/arg.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +testArgGrep() { + DC_PARGV_1=foobar + DC_PARGE_1=true + local result + result="$(dc::commander::declare::arg 1 "^foo(?:bar)?$" "" "a flag" "a flag")" + local exit=$? + dc-tools::assert::equal "$exit" "0" + + result="$(dc::commander::declare::arg 1 "^foo(?:abar)?$" "" "another flag" "another flag")" + local exit=$? + dc-tools::assert::equal "$exit" "$ERROR_ARGUMENT_INVALID" +} From 45494c03eb14360a6f7a9153cd0d9374379f6257 Mon Sep 17 00:00:00 2001 From: dubo-dubon-duponey Date: Mon, 3 Dec 2018 16:05:29 -0800 Subject: [PATCH 2/3] Capitalization and other minor cleanup Signed-off-by: dubo-dubon-duponey --- Makefile | 12 ++++++------ source/cli-tooling/build/base-build.sh | 2 +- source/cli/http/cmd.sh | 9 +++------ source/core/commander.sh | 2 +- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 32f1abe..91cac62 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ $(DC_MAKEFILE_DIR)/bin/bootstrap/builder: $(DC_MAKEFILE_DIR)/bootstrap # Then build the cli tools, using the bootstrapper $(DC_PREFIX)/bin/dc-tooling-%: $(DC_MAKEFILE_DIR)/source/core/*.sh $(DC_MAKEFILE_DIR)/source/cli-tooling/% $(call title, $@) - $(DC_MAKEFILE_DIR)/bin/bootstrap/builder --destination="$(shell dirname $@)" --name="$(shell basename $@)" --license="MIT license" --author="dubo-dubon-duponey" --description="another fancy (tooling) piece of shcript" --with-git-info $^ + $(DC_MAKEFILE_DIR)/bin/bootstrap/builder --destination="$(shell dirname $@)" --name="$(shell basename $@)" --license="MIT License" --author="dubo-dubon-duponey" --description="another fancy (tooling) piece of shcript" --with-git-info $^ ####################################################### # Base building tasks @@ -51,22 +51,22 @@ $(DC_PREFIX)/bin/dc-tooling-%: $(DC_MAKEFILE_DIR)/source/core/*.sh $(DC_MAKEFILE # Builds the main library $(DC_PREFIX)/lib/dc-sh-art: $(DC_MAKEFILE_DIR)/source/core/*.sh $(call title, $@) - $(DC_PREFIX)/bin/dc-tooling-build --destination="$(shell dirname $@)" --name="$(shell basename $@)" --license="MIT license" --author="dubo-dubon-duponey" --description="the library version" --with-git-info $^ + $(DC_PREFIX)/bin/dc-tooling-build --destination="$(shell dirname $@)" --name="$(shell basename $@)" --license="MIT License" --author="dubo-dubon-duponey" --description="the library version" --with-git-info $^ # Builds the extensions $(DC_PREFIX)/lib/dc-sh-art-extensions: $(DC_MAKEFILE_DIR)/source/extensions/**/*.sh $(call title, $@) - $(DC_PREFIX)/bin/dc-tooling-build --destination="$(shell dirname $@)" --name="$(shell basename $@)" --license="MIT license" --author="dubo-dubon-duponey" --description="extensions" $^ + $(DC_PREFIX)/bin/dc-tooling-build --destination="$(shell dirname $@)" --name="$(shell basename $@)" --license="MIT License" --author="dubo-dubon-duponey" --description="extensions" $^ # Builds all the CLIs that depend just on the main library $(DC_PREFIX)/bin/dc-%: $(DC_PREFIX)/lib/dc-sh-art $(DC_MAKEFILE_DIR)/source/cli/% $(call title, $@) - $(DC_PREFIX)/bin/dc-tooling-build --destination="$(shell dirname $@)" --name="$(shell basename $@)" --license="MIT license" --author="dubo-dubon-duponey" --description="another fancy piece of shcript" $^ + $(DC_PREFIX)/bin/dc-tooling-build --destination="$(shell dirname $@)" --name="$(shell basename $@)" --license="MIT License" --author="dubo-dubon-duponey" --description="another fancy piece of shcript" $^ # Builds all the CLIs that depend on the main library and extensions $(DC_PREFIX)/bin/dc-%: $(DC_PREFIX)/lib/dc-sh-art $(DC_PREFIX)/lib/dc-sh-art-extensions $(DC_MAKEFILE_DIR)/source/cli-ext/% $(call title, $@) - $(DC_PREFIX)/bin/dc-tooling-build --destination="$(shell dirname $@)" --name="$(shell basename $@)" --license="MIT license" --author="dubo-dubon-duponey" --description="another fancy piece of shcript" $^ + $(DC_PREFIX)/bin/dc-tooling-build --destination="$(shell dirname $@)" --name="$(shell basename $@)" --license="MIT License" --author="dubo-dubon-duponey" --description="another fancy piece of shcript" $^ ####################################################### # Tasks to be called on @@ -89,7 +89,7 @@ lint-signed: $(DC_MAKEFILE_DIR)/bin/bootstrap/builder $(DC_PREFIX)/bin/dc-toolin # Linter # XXX broken for now $(DC_PREFIX)/bin/dc-tooling-lint $(DC_PREFIX)/bin -lint-code: $(DC_MAKEFILE_DIR)/bin/bootstrap/builder $(DC_PREFIX)/bin/dc-tooling-lint build-library +lint-code: $(DC_MAKEFILE_DIR)/bin/bootstrap/builder $(DC_PREFIX)/bin/dc-tooling-lint build-library build-binaries $(call title, $@) $(DC_PREFIX)/bin/dc-tooling-lint $(DC_MAKEFILE_DIR)/bootstrap $(DC_PREFIX)/bin/dc-tooling-lint $(DC_MAKEFILE_DIR)/source diff --git a/source/cli-tooling/build/base-build.sh b/source/cli-tooling/build/base-build.sh index df613b3..d67b383 100644 --- a/source/cli-tooling/build/base-build.sh +++ b/source/cli-tooling/build/base-build.sh @@ -21,7 +21,7 @@ dc-tools::build::append(){ dc-tools::build::header(){ local destination="$1" local shortdesc="${2:-another fancy piece of shcript}" - local license="${3:-MIT license}" + local license="${3:-MIT License}" local owner="${4-dubo-dubon-duponey}" local name name="$(basename "$1")" diff --git a/source/cli/http/cmd.sh b/source/cli/http/cmd.sh index 53b6f3a..8e0b077 100644 --- a/source/cli/http/cmd.sh +++ b/source/cli/http/cmd.sh @@ -1,16 +1,13 @@ #!/usr/bin/env bash -readonly CLI_VERSION="0.0.1" -readonly CLI_LICENSE="MIT License" readonly CLI_DESC="like curl, in a nicer json-way" -readonly CLI_USAGE="[-s] [--insecure] url [method] [payload] [...headers]" # Initialize dc::commander::initialize -dc::commander::declare::arg 1 ".+" "" "url" "url..." -dc::commander::declare::arg 2 ".+" "optional" "method" "http method" +dc::commander::declare::arg 1 ".+" "" "url" "url to query" +dc::commander::declare::arg 2 ".+" "optional" "method" "http method (default to GET)" dc::commander::declare::arg 3 ".+" "optional" "payload" "payload to post" -dc::commander::declare::arg 4 ".+" "optional" "[...headers]" "optional additional headers to be passed" +dc::commander::declare::arg 4 ".+" "optional" "[...headers]" "additional headers to be passed" # Start commander dc::commander::boot diff --git a/source/core/commander.sh b/source/core/commander.sh index 1912752..e1b2e88 100644 --- a/source/core/commander.sh +++ b/source/core/commander.sh @@ -10,7 +10,7 @@ readonly DC_CLI_NAME=$(basename "$0") readonly DC_CLI_VERSION="$DC_VERSION (core script)" -readonly DC_CLI_LICENSE="MIT license" +readonly DC_CLI_LICENSE="MIT License" readonly DC_CLI_DESC="A fancy piece of shcript" export DC_CLI_USAGE="" export DC_CLI_OPTS=() From 643c0b9fc9bae682beec492e3e44efaf09c6b911 Mon Sep 17 00:00:00 2001 From: dubo-dubon-duponey Date: Mon, 3 Dec 2018 16:12:26 -0800 Subject: [PATCH 3/3] Make lint happy Signed-off-by: dubo-dubon-duponey --- tests/unit/arg.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/unit/arg.sh b/tests/unit/arg.sh index 7927756..c65fae3 100644 --- a/tests/unit/arg.sh +++ b/tests/unit/arg.sh @@ -1,13 +1,17 @@ #!/usr/bin/env bash testArgGrep() { + # shellcheck disable=SC2034 DC_PARGV_1=foobar + # shellcheck disable=SC2034 DC_PARGE_1=true local result + # shellcheck disable=SC2034 result="$(dc::commander::declare::arg 1 "^foo(?:bar)?$" "" "a flag" "a flag")" local exit=$? dc-tools::assert::equal "$exit" "0" + # shellcheck disable=SC2034 result="$(dc::commander::declare::arg 1 "^foo(?:abar)?$" "" "another flag" "another flag")" local exit=$? dc-tools::assert::equal "$exit" "$ERROR_ARGUMENT_INVALID"