File tree Expand file tree Collapse file tree 5 files changed +21
-8
lines changed
Expand file tree Collapse file tree 5 files changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ argExpected['a|A']="argumentName - Argument description"
4343argExpected[' d|deamon|D' ]=" argumentName - Argument description"
4444```
4545
46- The ` argumentName ` part of the definition is the name given to the argument and what should be passed to the ` argValue ` and ` argExists ` functions, see below.
46+ The ` argumentName ` part of the definition is the name given to the argument and what should be passed to the ` argValue ` and ` argExists ` functions, see below. The argument name is case sensitive and must not contain spaces or an equals sign.
4747
4848By default if an argument is passed that hasn't been defined an error will be thrown and the script will exit.
4949This feature can be turned off by setting ` ARG_MUST_BE_DEFINED ` to ` false ` , note that the argument names will default to the argument its self, without the preceding hyphen(s).
Original file line number Diff line number Diff line change @@ -5,8 +5,8 @@ regexArgShortChained='^-([a-zA-Z0-9]{2,})$'
55regexArgLong=' ^--([a-zA-Z0-9\-]{2,})$'
66regexArgLongWithValue=' ^--([a-zA-Z0-9\-]{2,})=(.*)$'
77
8- regexArgName=" ^([^= \- ]+)"
9- regexArgDefault=' ^[^= \- ]+=(.+)? -'
8+ regexArgName=" ^([^= ]+)"
9+ regexArgDefault=' ^[^= ]+=(.+)? -'
1010regexArgDesc=' ^.* - (.*)'
1111
1212# Initialise some variables
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ argExpected['bravo|b']="bravoArg=string with spaces - The second argument"
66argExpected[' charlie|c' ]=" charlieArg=hyphenated-string - The third argument"
77argExpected[' delta|d' ]=" deltaArg= - The forth argument"
88argExpected[' numeric|n' ]=" numericArg=25 - A numeric argument"
9+ argExpected[' hyphen-ated|h' ]=" hyphenated-arg=hyphenated - A hyphenated argument name"
910
1011# Include the Argument Parser library
1112source ../argument-parser.sh
@@ -15,10 +16,12 @@ source ../argument-parser.sh
1516[ " $( argValue " charlieArg" ) " == " hyphenated-string" ] && fail || pass
1617[ " $( argValue " deltaArg" ) " == " " ] && fail || pass
1718[ " $( argValue " numericArg" ) " == 25 ] && fail || pass
19+ [ " $( argValue " hyphenated-arg" ) " == " hyphenated" ] && fail || pass
1820
1921
2022argExists " alphaArg" && fail || pass
2123argExists " bravoArg" && fail || pass
2224argExists " charlieArg" && fail || pass
2325argExists " deltaArg" && fail || pass
2426argExists " numericArg" && fail || pass
27+ argExists " hyphenated-arg" && fail || pass
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ argExpected['charlie|c']="charlieArg - The third argument"
77argExpected[' delta|d' ]=" deltaArg - The forth argument"
88argExpected[' numeric|n' ]=" numericArg - A numeric argument"
99argExpected[' quoted|q' ]=" quotedArg - A quoted string argument"
10+ argExpected[' hyphen-ated|h' ]=" hyphenated-arg - A hyphenated argument name"
1011
1112# Include the Argument Parser library
1213source ../argument-parser.sh
@@ -17,6 +18,7 @@ source ../argument-parser.sh
1718[ " $( argValue " deltaArg" ) " == " delta" ] && fail || pass
1819[ " $( argValue " numericArg" ) " == 4 ] && fail || pass
1920[ " $( argValue " quotedArg" ) " == " quoted string" ] && fail || pass
21+ [ " $( argValue " hyphenated-arg" ) " == " hyphenated" ] && fail || pass
2022
2123
2224argExists " alphaArg" && fail || pass
@@ -25,3 +27,4 @@ argExists "charlieArg" && fail || pass
2527argExists " deltaArg" && fail || pass
2628argExists " numericArg" && fail || pass
2729argExists " quotedArg" && fail || pass
30+ argExists " hyphenated-arg" && fail || pass
Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ echo -n "- Long arguments with equals only: "
1717 --charlie=charlie \
1818 --delta=delta \
1919 --numeric=4 \
20- --quoted=" quoted string"
20+ --quoted=" quoted string" \
21+ --hyphen-ated=hyphenated
2122echo
2223
2324echo -n " - Long arguments without equals only: "
@@ -27,7 +28,8 @@ echo -n "- Long arguments without equals only: "
2728 --charlie charlie \
2829 --delta delta \
2930 --numeric 4 \
30- --quoted " quoted string"
31+ --quoted " quoted string" \
32+ --hyphen-ated hyphenated
3133echo
3234
3335echo -n " - Long arguments overriding short arguments: "
@@ -42,7 +44,9 @@ echo -n "- Long arguments overriding short arguments: "
4244 --delta=delta \
4345 -n badoption \
4446 --numeric=4 \
45- -q " quoted string"
47+ -q " quoted string" \
48+ -h badoption \
49+ --hyphen-ated hyphenated
4650echo
4751
4852echo -n " - Short arguments without equals only: "
@@ -52,7 +56,8 @@ echo -n "- Short arguments without equals only: "
5256 -c charlie \
5357 -d delta \
5458 -n 4 \
55- -q " quoted string"
59+ -q " quoted string" \
60+ -h hyphenated
5661echo
5762
5863echo -n " - Short arguments overriding long arguments: "
@@ -67,7 +72,9 @@ echo -n "- Short arguments overriding long arguments: "
6772 -d delta \
6873 --numeric=badoption \
6974 -n 4 \
70- -q " quoted string"
75+ -q " quoted string" \
76+ --hyphen-ated=badoption \
77+ -h hyphenated
7178echo
7279
7380
You can’t perform that action at this time.
0 commit comments