|
1 | 1 | # BASH Argument Parser |
2 | 2 |
|
3 | | -Takes arguments passed in nearly any format to a bash script and allows easy access to them and their values |
| 3 | +Takes arguments passed to a bash script in nearly any format and allows easy access to them and their values |
4 | 4 |
|
5 | 5 | ## Use |
6 | 6 |
|
7 | 7 | ### How To Use |
8 | 8 |
|
9 | | -Just include the library in the head of script, define all the arguments you need and call the parser function |
| 9 | +Just define all the arguments you need and include the library in the head of script, that's it. |
10 | 10 |
|
11 | 11 | ```bash |
12 | | -# Include the Argument Parser library |
13 | | -source ./my/lib/path/argument-parser.sh |
14 | | - |
15 | 12 | # Define the expected arguments |
| 13 | +declare -A argExpected |
16 | 14 | argExpected['test']="argName - This is a short description of the argument and what it does" |
17 | 15 | argExpected['R']="secondArgName - This is another argument that can be passed" |
18 | 16 |
|
19 | | -# Parse any arguments |
20 | | -argParse |
| 17 | +# Include and run the Argument Parser library |
| 18 | +source ./my/lib/path/argument-parser.sh |
21 | 19 | ``` |
22 | 20 |
|
23 | 21 | ### Defining Expected Arguments |
24 | 22 |
|
25 | | -The argument parser can take an array of arguments to expect, it has the following format: |
| 23 | +The argument parser takes an array of arguments to expect, it has the following format: |
26 | 24 |
|
27 | 25 | ```bash |
| 26 | +# Define argExpected as an associative array |
| 27 | +# This must occur once before you build the array of argument definitions |
| 28 | +declare -A argExpected |
| 29 | + |
28 | 30 | # Define the -r argument |
29 | 31 | argExpected['r']="argumentName - Argument description" |
30 | 32 |
|
@@ -186,7 +188,7 @@ The order the arguments are passed on the command line makes a difference |
186 | 188 |
|
187 | 189 | ## Debug Mode |
188 | 190 |
|
189 | | -There is a debug mode that can be enabled by setting the `ARG_DEBUG` variable to `true` right before calling `argParse`. |
| 191 | +There is a debug mode that can be enabled by setting the `ARG_DEBUG` variable to `true` right before including the library. |
190 | 192 | This will cause the script to dump out information about which flags it finds and of what kind etc |
191 | 193 |
|
192 | 194 | ## Testing |
|
0 commit comments