Skip to content

Commit

Permalink
Work around gnu grep attempt #1
Browse files Browse the repository at this point in the history
Signed-off-by: dubo-dubon-duponey <[email protected]>
  • Loading branch information
dubo-dubon-duponey committed Dec 3, 2018
1 parent 7e1176d commit 1cbaea9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
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
13 changes: 11 additions & 2 deletions source/core/commander.sh
Original file line number Diff line number Diff line change
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
14 changes: 14 additions & 0 deletions tests/unit/arg.sh
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 1cbaea9

Please sign in to comment.