Skip to content

Commit 2b767cc

Browse files
committed
BREAKING CHANGE: Update command name and options usage
1 parent 2087e87 commit 2b767cc

File tree

12 files changed

+73
-47
lines changed

12 files changed

+73
-47
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ A cute little Bash library for blazing fast argument parsing
1414
STATUS: IN DEVELOPMENT!
1515

1616
```sh
17-
# With Basher
18-
basher install eankeen/args
17+
# With bpm (recommended)
18+
bpm install eankeen/args
1919

2020
# With Git
21-
git clone "https://github.com/eankeen/args" ~/.args
21+
git clone "https://github.com/eankeen/args" "$HOME/.bash-args"
22+
export PATH="$HOME/.bash-args/pkg/bin:$PATH"
2223
```
2324

2425
## Usage
@@ -29,7 +30,7 @@ declare -A args=()
2930

3031
# Pass through your command line arguments to 'args'
3132
# Pass your argument specification through stdin (see more examples below)
32-
source bash-args parse "$@" <<-"EOF"
33+
source bash-args parse parse "$@" <<-"EOF"
3334
@flag [port.p] {3000} - The port to open on
3435
EOF
3536

@@ -49,7 +50,7 @@ echo "argsHelpText: $argsHelpText"
4950

5051
### Argument Specification
5152

52-
The following are valid lines and their explanations to pass as stdin to `args.parse`
53+
The following are valid lines and their explanations to pass as stdin to `bash-args`
5354

5455
#### `@flag [verbose] - Enable verbose logging`
5556

docs/reference.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Variables
44

5-
Available variables after calling `args.parse`. If the values of the variables appear to be blank, you may have to declare the variable before calling `args.parse`
5+
Available variables after calling `bash-args`. If the values of the variables appear to be blank, you may have to declare the variable before calling `bash-args`
66

77
### `argsPostHyphen`
88

@@ -11,7 +11,7 @@ An array that contains every argument or flag after the first `--`
1111
```sh
1212
declare -a argsPostHyphen=()
1313

14-
source args.parse --port 3005 -- ls -L --color=always /lib <<-'EOF'
14+
source bash-args parse --port 3005 -- ls -L --color=always /lib <<-'EOF'
1515
@flag [port] {3000} - The port to open on
1616
EOF
1717

@@ -21,12 +21,12 @@ echo "${argsPostHyphen[*]}"
2121

2222
### `argsRawSpec`
2323

24-
A string that is a copy of standard input to `args.parse`
24+
A string that is a copy of standard input to `bash-args`
2525

2626
```sh
2727
declare argsRawSpec=
2828

29-
source args.parse --port 3005 <<-'EOF'
29+
source bash-args parse --port 3005 <<-'EOF'
3030
@flag [port] {3000} - The port to open on
3131
@flag [version.v] - Prints program version
3232
EOF
@@ -43,14 +43,14 @@ An associative array that contains the values of arguments
4343
```sh
4444
declare -A args=()
4545

46-
source args.parse --port 3005 <<-'EOF'
46+
source bash-args parse --port 3005 <<-'EOF'
4747
@flag [port.p] {3000} - The port to open on
4848
EOF
4949

5050
echo "${args[port]} ${args[p]}"
5151
# 3005 3005
5252

53-
source args.parse -p 3005 <<-'EOF'
53+
source bash-args parse -p 3005 <<-'EOF'
5454
@flag [port.p] {3000} - The port to open on
5555
EOF
5656

@@ -65,7 +65,7 @@ An array contaning all the commands supplied
6565
```sh
6666
declare -a argsCommands=()
6767

68-
source args.parse --port 3005 serve --user admin now --enable-security <<-'EOF'
68+
source bash-args parse --port 3005 serve --user admin now --enable-security <<-'EOF'
6969
@flag [port.p] {3000} - The port to open on
7070
EOF
7171

@@ -77,4 +77,15 @@ echo "${argsCommands[*]}"
7777

7878
The full generated help text
7979

80-
// TODO
80+
```sh
81+
source bash-args parse parse "$@" <<-"EOF"
82+
@flag [port.p] {3000} - The port to open on
83+
EOF
84+
85+
echo "$argsHelpText"
86+
# Usage:
87+
# stdin [flags] <arguments>
88+
89+
# Flags:
90+
# p, port (Default: 3000)
91+
```

docs/troubleshooting.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ If you are receiving opaque errors, the following may help
44

55
## `bash: /usr/lib/jvm/default/bin: syntax error: operand expected (error token is "/usr/lib/jvm/default/bin")`
66

7-
Ensure `args` exists as an associate array and NOT an index array. Create it _before_ calling out to `args.parse`
7+
Ensure `args` exists as an associate array and NOT an index array. Create it _before_ calling out to `bash-args`
88

99

1010
```sh
@@ -15,12 +15,24 @@ declare -a args
1515
declare -A args
1616
```
1717

18-
## Not sourcing `args.parse`
18+
## Not sourcing `bash-args`
1919

20-
// TODO
20+
If you do not source `bash-args` the variables that it sets will not be available to your current shell execution context
21+
22+
```sh
23+
# Wrong
24+
bash-args parse "$@" <<-"EOF"
25+
@flag [port.p] {3000} - The port to open on
26+
EOF
27+
28+
# Correct
29+
source bash-args parse parse "$@" <<-"EOF"
30+
@flag [port.p] {3000} - The port to open on
31+
EOF
32+
```
2133

2234
## Not declaring variables
2335

2436
TODO: test this
2537

26-
If you wish to use a variable, please declare it before invoking `args.parse`. If your shell context has `set -u` enabled, you may have to declare it for variables that you do not use
38+
If you wish to use a variable, please declare it before invoking `bash-args`. If your shell context has `set -u` enabled, you may have to declare it for variables that you do not use

examples/bashblog.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# https://github.com/cfenollosa/bashblog
44

5-
source args.parse <<"EOF"
5+
source bash-args parse <<"EOF"
66
@arg post - insert a new blog post, or the filename of a draft to continue editing it. it tries to use markdown by default, and falls back to HTML if it's not available. use '-html' to override it and edit the post as HTML even when markdown is available
77
@arg edit - edit an already published .html or .md file. **NEVER** edit manually a published .html file, always use this function as it keeps internal data and rebuilds the blog. use '-n' to give the file a new name, if title was changed. use '-f' to edit full html file, instead of just text part (also preserves name)
88
@arg delete - deletes the post and rebuilds the blog

examples/basher.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
# https://github.com/basherpm/basher
44

5-
source args.parse <<"EOF"
5+
source bash-args parse parse <<"EOF"
66
@arg help - Display help for a command
77
@arg commands - List all available basher commands
88
@arg init - Configure the shell environment for basher
99
EOF
10+
11+
echo "$argsHelpText"

examples/bats.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# https://github.com/bats-core/bats-core
44

5-
source args.parse -- <<"EOF"
5+
source bash-args parse -- <<"EOF"
66
@flag [count.c] - Count test cases without running any tests
77
@flag [filter.f] {} - Only run tests that match the regular expression
88
@flag [formatter.F] {pretty} - Swithc between formatters: pretty (default), tap (default w/o term), tap13, junit

examples/json.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# https://github.com/dominictarr/JSON.sh
44

5-
source args.parse -- <<"EOF"
5+
source bash-args parse -- <<"EOF"
66
@flag [.p] - Prune empty. Exclude fields with empty values.
77
@flag [.l] - Leaf only. Only show leaf nodes, which stops data duplication.
88
@flag [.b] - Brief. Combines 'Leaf only' and 'Prune empty' options.

pkg/lib/cmd/bash-args.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ bash-args() {
2121
2222
Flags
2323
--version
24-
Show version of 'args.parse'
24+
Show version of 'bash-args'
2525
2626
--help
2727
Show help
@@ -99,12 +99,12 @@ bash-args() {
9999

100100
# Sanity checks
101101
if [ -z "$flagNameOptional" ] && [ -z "$flagNameRequired" ]; then
102-
bash_args.util.die 'args.parse: Must specify either an optional or required flag; neither were specified'
102+
bash_args.util.die 'bash-args: Must specify either an optional or required flag; neither were specified'
103103
return
104104
fi
105105

106106
if [ -n "$flagNameOptional" ] && [ -n "$flagNameRequired" ]; then
107-
bash_args.util.die 'args.parse: Must specify either an optional or required flag; both were specified'
107+
bash_args.util.die 'bash-args: Must specify either an optional or required flag; both were specified'
108108
return
109109
fi
110110

@@ -205,14 +205,14 @@ bash-args() {
205205
# If we did not set flagWasFound=yes, it means it did not find
206206
# the flag. So, if the flag is <required>, we fail right away
207207
if [ "$flagWasFound" = no ]; then
208-
bash_args.util.die "args.parse: You must supply the flag '$currentFlag' with a value"
208+
bash_args.util.die "bash-args: You must supply the flag '$currentFlag' with a value"
209209
return
210210
fi
211211

212212
# If we were supposed to do an immediate break, but didn't actually
213213
# do it, it means we are on the last argument and there is no value
214214
if [ "$flagWasFound" = yes ] && [ "$didImmediateBreak" = no ]; then
215-
bash_args.util.die "args.parse: No value found for flag '$currentFlag'"
215+
bash_args.util.die "bash-args: No value found for flag '$currentFlag'"
216216
return
217217
fi
218218
fi
@@ -245,7 +245,7 @@ bash-args() {
245245
case "$flagValueCli" in
246246
-*)
247247
if [[ -v flagValueDefault ]]; then
248-
bash_args.util.die "args.parse: You must supply a value for '$currentFlag'"
248+
bash_args.util.die "bash-args: You must supply a value for '$currentFlag'"
249249
return
250250
fi
251251
;;
@@ -329,7 +329,7 @@ bash-args() {
329329
printf -v name '%-20s' " $name"
330330
argsHelpArrayArgs+=("${name}${argDescription}"$'\n')
331331
else
332-
bash_args.util.die "args.parse: Pragma must be either @flag or @arg. Received: '$type'"
332+
bash_args.util.die "bash-args: Pragma must be either @flag or @arg. Received: '$type'"
333333
return
334334
fi
335335
done
@@ -384,7 +384,7 @@ bash-args() {
384384
done
385385

386386
if [ "$isValidFlag" = no ]; then
387-
bash_args.util.die "args.parse: Flag '$arg' is not accepted"
387+
bash_args.util.die "bash-args: Flag '$arg' is not accepted"
388388
return
389389
fi
390390
esac

test/args.bats

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -Eeuo pipefail
44
@test "longOption with value" {
55
declare -A args=()
66

7-
source ./bin/args.parse --port 3005 <<-'EOF'
7+
source bash-args parse --port 3005 <<-'EOF'
88
@flag [port] {3000} - The port to open on
99
EOF
1010

@@ -16,7 +16,7 @@ set -Eeuo pipefail
1616
@test "shortOption with value" {
1717
declare -A args=()
1818

19-
source ./bin/args.parse -p 3005 <<-'EOF'
19+
source bash-args parse -p 3005 <<-'EOF'
2020
@flag [.p] {3000} - The port to open on
2121
EOF
2222

@@ -27,7 +27,7 @@ set -Eeuo pipefail
2727
@test "longOption and shortOption with longOption value" {
2828
declare -A args=()
2929

30-
source ./bin/args.parse --port 3005 <<-'EOF'
30+
source bash-args parse --port 3005 <<-'EOF'
3131
@flag [port.p] {3000} - The port to open on
3232
EOF
3333

@@ -41,7 +41,7 @@ set -Eeuo pipefail
4141
@test "longOption and shortOption with shortOption value" {
4242
declare -A args=()
4343

44-
source ./bin/args.parse -p 3005 <<-'EOF'
44+
source bash-args parse -p 3005 <<-'EOF'
4545
@flag [port.p] {3000} - The port to open on
4646
EOF
4747

@@ -58,7 +58,7 @@ set -Eeuo pipefail
5858

5959
declare -A args=()
6060

61-
source ./bin/args.parse --version <<-'EOF'
61+
source bash-args parse --version <<-'EOF'
6262
@flag [version.v] - The port to open on
6363
EOF
6464

@@ -69,7 +69,7 @@ set -Eeuo pipefail
6969
@test "longOption and default" {
7070
declare -A args=()
7171

72-
source ./bin/args.parse <<-'EOF'
72+
source bash-args parse <<-'EOF'
7373
@flag [port] {3000} - The port to open on
7474
EOF
7575

@@ -79,7 +79,7 @@ set -Eeuo pipefail
7979
@test "shortOption and default" {
8080
declare -A args=()
8181

82-
source ./bin/args.parse <<-'EOF'
82+
source bash-args parse <<-'EOF'
8383
@flag [.p] {3000} - The port to open on
8484
EOF
8585

@@ -89,7 +89,7 @@ set -Eeuo pipefail
8989
@test "longOption and shortOption" {
9090
declare -A args=()
9191

92-
source ./bin/args.parse <<-'EOF'
92+
source bash-args parse <<-'EOF'
9393
@flag [port.p] {3000} - The port to open on
9494
EOF
9595

@@ -103,7 +103,7 @@ set -Eeuo pipefail
103103
declare -A args=()
104104

105105
! (
106-
source ./bin/args.parse --port --something nother <<-'EOF'
106+
source bash-args parse --port --something nother <<-'EOF'
107107
@flag <port> {} - The port to open on
108108
EOF
109109
)
@@ -113,7 +113,7 @@ set -Eeuo pipefail
113113
declare -A args=()
114114

115115
(
116-
source ./bin/args.parse --port --something nother <<-'EOF'
116+
source bash-args parse --port --something nother <<-'EOF'
117117
@flag <port> - The port to open on
118118
@flag <something> - something
119119
EOF
@@ -124,7 +124,7 @@ set -Eeuo pipefail
124124
declare -A args=()
125125

126126
! (
127-
source ./bin/args.parse --port - <<-'EOF'
127+
source bash-args parse --port - <<-'EOF'
128128
@flag [port] {} - The port to open on
129129
EOF
130130
)
@@ -134,7 +134,7 @@ set -Eeuo pipefail
134134
declare -A args=()
135135

136136
(
137-
source ./bin/args.parse --port - <<-'EOF'
137+
source bash-args parse --port - <<-'EOF'
138138
@flag [port] - The port to open on
139139
EOF
140140
)
@@ -144,7 +144,7 @@ set -Eeuo pipefail
144144
declare -A args=()
145145

146146
! (
147-
source ./bin/args.parse <<-'EOF'
147+
source bash-args parse <<-'EOF'
148148
@flag <port> The port to open on
149149
EOF
150150
)

test/argsCommands.bats

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -Eeuo pipefail
55
declare -A args
66
declare -a argsCommands=()
77

8-
source ./bin/args.parse alfa bravo <<-'EOF'
8+
source bash-args parse alfa bravo <<-'EOF'
99
@flag [port.p] {3000} - The port to open on
1010
EOF
1111

@@ -19,7 +19,7 @@ set -Eeuo pipefail
1919
declare -A args
2020
declare -a argsCommands=()
2121

22-
source ./bin/args.parse --port 3005 serve --user admin --enable-security now <<-'EOF'
22+
source bash-args parse --port 3005 serve --user admin --enable-security now <<-'EOF'
2323
@flag [port.p] {3000} - The port to open on
2424
@flag [user] {} - User
2525
@flag [enable-security] - Enable security
@@ -34,7 +34,7 @@ set -Eeuo pipefail
3434
declare -A args
3535
declare -a argsCommands=()
3636

37-
source ./bin/args.parse --port 3005 serve now --enable-security last <<-'EOF'
37+
source bash-args parse --port 3005 serve now --enable-security last <<-'EOF'
3838
@flag [port.p] {3000} - The port to open on
3939
@flag [enable-security] - Whether to enable security
4040
EOF

0 commit comments

Comments
 (0)