-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample
More file actions
executable file
·40 lines (36 loc) · 1.54 KB
/
example
File metadata and controls
executable file
·40 lines (36 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash
# An example script calling parseargs.
# Takes the --test, -t flag and is not strict
config="$(jq -n '
{
"options": {
"test": {"type": "string", "short": "t"}
},
"strict": false
}
')"
parseargs --config "$config" -- "$@" | jq .
# calling index.js directly
# ./index.js --config "$config" -- "$@" | jq .
# calling parseargs after running `npm link`
# parses the args to this script. Pretty prints with jq
echo "------ ------"
parseargs --option test=string -- --test one | jq .
echo "------ ------"
parseargs --option test=string,t -- -tthree | jq .
echo "------ ------"
parseargs --option allow=boolean,a --negative -- --no-allow | jq .
echo "------ header format ------"
# print in headers format
parseargs --option test=string,t --positional --format headers -- --test one two three
# pull the value of the test flag from the headers format
parseargs --option test=string,t --positional --format headers -- --test one two three |
awk -F ': ' '/test/ {printf $2}'
# pull the value of all flags
parseargs --option test=string,t --option type=string --positional --format headers -- --tone two three "four five" "six: seven" |
awk -F ': ' 'NF == 2 { printf $0 } /^$/ { exit }'
# pull positionals from the headers format, one argument per line
parseargs --option test=string,t --positional --format headers -- --test one two three "four five" |
awk -v RS='\n\n' 'NR == 2 { printf $0 }'
parseargs --option test=string,t --positional --format headers -- --test one two three "four five" |
awk '/^$/ {found=1;next} found {print $0}'