Skip to content

Commit f405b44

Browse files
committed
Renamed argExists to argPassed to make it clearer what it's actually testing for now there are default values
1 parent 1fa7e70 commit f405b44

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ argExpected['a|A']="argumentName - Argument description"
4343
argExpected['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. The argument name is case sensitive and must not contain spaces or an equals sign.
46+
The `argumentName` part of the definition is the name given to the argument and what should be passed to the `argValue` and `argPassed` functions, see below. The argument name is case sensitive and must not contain spaces or an equals sign.
4747

4848
By default if an argument is passed that hasn't been defined an error will be thrown and the script will exit.
4949
This 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).
@@ -101,32 +101,32 @@ esac
101101

102102
### Check If An Argument Has Been Passed
103103

104-
There is a helper function named `argExists()` which takes the name of
104+
There is a helper function named `argPassed` which takes the name of
105105
an argument as its only parameter and returns a boolean.
106106

107-
`argExist` will return false if the argument has fallen back to its default value*
107+
`argPassed` will return false if the argument has fallen back to its default value*
108108

109109
```bash
110110
# -v
111-
if argExists 'v'; then
111+
if argPassed 'v'; then
112112
echo "The -v argument has been passed"
113113
fi
114114

115115
# -rMd
116-
argExists 'r' && echo "The -r argument was passed"
116+
argPassed 'r' && echo "The -r argument was passed"
117117

118118
# --long-argument-name
119-
if argExists 'long-argument-name'; then
119+
if argPassed 'long-argument-name'; then
120120
# Do something awesome
121121
fi
122122

123123
# --protocol=HTTP
124-
if argExists 'protocol'; then
124+
if argPassed 'protocol'; then
125125
# Do something awesome
126126
fi
127127

128128
# -O 43
129-
argExists 'O' && echo "Found the -O argument"
129+
argPassed 'O' && echo "Found the -O argument"
130130
```
131131

132132
## Supported Argument Formats

argument-parser.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ argUnexpected() {
125125
echo "UNEXPECTED ARGUMENT $1"
126126
}
127127

128-
argExists() {
128+
argPassed() {
129129
if [ -z ${argv["$1"]+abc} ]; then
130130
return 1 # false
131131
else
@@ -142,7 +142,7 @@ argHasDefault() {
142142
}
143143

144144
argValue() {
145-
if argExists "$1"; then
145+
if argPassed "$1"; then
146146
echo "${argv["$1"]}"
147147
exit 0
148148
fi

tests/default.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ source ../argument-parser.sh
1919
[ "$(argValue "hyphenated-arg")" == "hyphenated" ] && pass || fail
2020

2121

22-
argExists "alphaArg" && fail || pass
23-
argExists "bravoArg" && fail || pass
24-
argExists "charlieArg" && fail || pass
25-
argExists "deltaArg" && fail || pass
26-
argExists "numericArg" && fail || pass
27-
argExists "hyphenated-arg" && fail || pass
22+
argPassed "alphaArg" && fail || pass
23+
argPassed "bravoArg" && fail || pass
24+
argPassed "charlieArg" && fail || pass
25+
argPassed "deltaArg" && fail || pass
26+
argPassed "numericArg" && fail || pass
27+
argPassed "hyphenated-arg" && fail || pass

tests/simple.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ source ../argument-parser.sh
2121
[ "$(argValue "hyphenated-arg")" == "hyphenated" ] && pass || fail
2222

2323

24-
argExists "alphaArg" && pass || fail
25-
argExists "bravoArg" && pass || fail
26-
argExists "charlieArg" && pass || fail
27-
argExists "deltaArg" && pass || fail
28-
argExists "numericArg" && pass || fail
29-
argExists "quotedArg" && pass || fail
30-
argExists "hyphenated-arg" && pass || fail
24+
argPassed "alphaArg" && pass || fail
25+
argPassed "bravoArg" && pass || fail
26+
argPassed "charlieArg" && pass || fail
27+
argPassed "deltaArg" && pass || fail
28+
argPassed "numericArg" && pass || fail
29+
argPassed "quotedArg" && pass || fail
30+
argPassed "hyphenated-arg" && pass || fail

0 commit comments

Comments
 (0)