-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from hattan/parse_v2
Parse v2
- Loading branch information
Showing
14 changed files
with
646 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
source scripts/shArg.sh | ||
|
||
declare MESSAGE | ||
|
||
messageHook() { | ||
local message=$1 | ||
|
||
echo "message hooked invoked with $message" | ||
echo "Global variable is still available $MESSAGE" | ||
} | ||
|
||
# register arguments | ||
shArgs.arg "MESSAGE" -m --message PARAMETER true messageHook | ||
|
||
# parse inputs | ||
shArgs.parse $@ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
|
||
source scripts/shArg.sh | ||
|
||
declare IPS | ||
shArgs.arg "IPS" -i --ips PARAMETER true | ||
shArgs.parse $@ | ||
|
||
for ip in $IPS | ||
do | ||
echo "ip: $ip" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
|
||
run_file() { | ||
local file=$1 | ||
local input=$2 | ||
output=$(bash $file $input) | ||
echo $output | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
# load shArg | ||
source scripts/shArg.sh | ||
|
||
declare MESSAGE | ||
declare DEBUG | ||
|
||
# register arguments | ||
shArgs.arg "MESSAGE" -m --message PARAMETER true | ||
shArgs.arg "DEBUG" -d --debug FLAG true | ||
|
||
# parse inputs | ||
shArgs.parse $@ | ||
|
||
echo "The message is $MESSAGE" | ||
|
||
if [ "$DEBUG" == true ]; then | ||
echo "DEBUG is true!" | ||
else | ||
echo "DEBUG is false" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Describe 'shArg' | ||
Include spec/integration/harness/runner.sh | ||
|
||
Context "Simple Script Tests" | ||
It 'should parse a csv parameter' | ||
When call run_file "spec/integration/harness/hook.sh" "-m great123" | ||
The output should equal "message hooked invoked with great123 Global variable is still available great123" | ||
End | ||
|
||
End | ||
End |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Describe 'shArg' | ||
Include spec/integration/harness/runner.sh | ||
|
||
Context "Simple Script Tests" | ||
It 'should parse a csv parameter' | ||
When call run_file "spec/integration/harness/list.sh" "-i 123,456" | ||
The output should equal "ip: 123 ip: 456" | ||
End | ||
|
||
It 'should parse a space delimited parameter' | ||
When call run_file "spec/integration/harness/list.sh" "-i 888 777" | ||
The output should equal "ip: 888 ip: 777" | ||
End | ||
|
||
End | ||
End |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
Describe 'shArg' | ||
Include spec/integration/harness/runner.sh | ||
|
||
Context "Simple Script Tests" | ||
It 'should parse a parameter with short name and no quotes' | ||
When call run_file "spec/integration/harness/simple.sh" "-m hello" | ||
The output should equal "The message is hello DEBUG is false" | ||
End | ||
|
||
It 'should parse a parameter with short name, no quotes and equals assignment' | ||
When call run_file "spec/integration/harness/simple.sh" "-m=hello" | ||
The output should equal "The message is hello DEBUG is false" | ||
End | ||
|
||
It 'should parse a parameter with short name and double quotes' | ||
When call run_file "spec/integration/harness/simple.sh" "-m \"world\"" | ||
The output should equal "The message is world DEBUG is false" | ||
End | ||
|
||
It 'should parse a parameter with short name, double quotes and equals assignment' | ||
When call run_file "spec/integration/harness/simple.sh" '-m="hello"' | ||
The output should equal "The message is hello DEBUG is false" | ||
End | ||
|
||
It 'should parse a parameter with short name and single quotes' | ||
When call run_file "spec/integration/harness/simple.sh" "-m 'world'" | ||
The output should equal "The message is world DEBUG is false" | ||
End | ||
|
||
It 'should parse a parameter with short name, single quotes and equals assignment' | ||
When call run_file "spec/integration/harness/simple.sh" "-m='hello'" | ||
The output should equal "The message is hello DEBUG is false" | ||
End | ||
|
||
It 'should parse a parameter with long name and no quotes' | ||
When call run_file "spec/integration/harness/simple.sh" "--message hello" | ||
The output should equal "The message is hello DEBUG is false" | ||
End | ||
|
||
It 'should parse a parameter with long name, no quotes and equals assignment' | ||
When call run_file "spec/integration/harness/simple.sh" "--message=hello" | ||
The output should equal "The message is hello DEBUG is false" | ||
End | ||
|
||
It 'should parse a parameter with long name and double quotes' | ||
When call run_file "spec/integration/harness/simple.sh" "--message \"world\"" | ||
The output should equal "The message is world DEBUG is false" | ||
End | ||
|
||
It 'should parse a parameter with long name, double quotes and equals assignment' | ||
When call run_file "spec/integration/harness/simple.sh" '--message="hello"' | ||
The output should equal "The message is hello DEBUG is false" | ||
End | ||
|
||
It 'should parse a parameter with long name and single quotes' | ||
When call run_file "spec/integration/harness/simple.sh" "--message 'world'" | ||
The output should equal "The message is world DEBUG is false" | ||
End | ||
|
||
It 'should parse a parameter with long name, single quotes and equals assignment' | ||
When call run_file "spec/integration/harness/simple.sh" "--message='hello'" | ||
The output should equal "The message is hello DEBUG is false" | ||
End | ||
|
||
It 'should parse a parameter with long name and spaces. Single param only' | ||
When call run_file "spec/integration/harness/simple.sh" "--message=hi there" | ||
The output should equal "The message is hi there DEBUG is false" | ||
End | ||
|
||
It 'should parse a parameter with long name and spaces. Multiple params' | ||
When call run_file "spec/integration/harness/simple.sh" "--message=hi there -d" | ||
The output should equal "The message is hi there DEBUG is true!" | ||
End | ||
|
||
It 'should parse a parameter with short name and spaces. Equals assignment. Single param only' | ||
When call run_file "spec/integration/harness/simple.sh" "-m=hi there" | ||
The output should equal "The message is hi there DEBUG is false" | ||
End | ||
|
||
It 'should parse a parameter with long name and spaces. Equals assignment. Multiple params' | ||
When call run_file "spec/integration/harness/simple.sh" "-m=hi there -d" | ||
The output should equal "The message is hi there DEBUG is true!" | ||
End | ||
|
||
It 'should parse a parameter with short name and spaces. Positional assignment. Single param only' | ||
When call run_file "spec/integration/harness/simple.sh" "-m hi there" | ||
The output should equal "The message is hi there DEBUG is false" | ||
End | ||
|
||
It 'should parse a parameter with long name and spaces. Positional assignment. Multiple params' | ||
When call run_file "spec/integration/harness/simple.sh" "-m hi there -d" | ||
The output should equal "The message is hi there DEBUG is true!" | ||
End | ||
End | ||
End |
Oops, something went wrong.