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/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..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=() @@ -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..c65fae3 --- /dev/null +++ b/tests/unit/arg.sh @@ -0,0 +1,18 @@ +#!/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" +}