Skip to content

Commit

Permalink
Merge pull request #23 from dubo-dubon-duponey/work
Browse files Browse the repository at this point in the history
Work around gnu grep attempt #1
  • Loading branch information
dubo-dubon-duponey authored Dec 4, 2018
2 parents 374f6f0 + 643c0b9 commit d0972b4
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 16 deletions.
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion source/cli-tooling/build/base-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")"
Expand Down
9 changes: 3 additions & 6 deletions source/cli/http/cmd.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 8 additions & 0 deletions source/core/abash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ _have_bash(){
}

_have_bash

_gnu_grep(){
if grep --version | grep -q gnu; then
readonly _GNUGREP="true"
fi
}

_gnu_grep
15 changes: 12 additions & 3 deletions source/core/commander.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=()
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/arg.sh
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit d0972b4

Please sign in to comment.