Skip to content

Commit b5d39cc

Browse files
authored
Merge pull request #294 from DannyBen/fix/multi-global-flags
Fix multiple global flags
2 parents 6d41735 + 3853b1e commit b5d39cc

File tree

7 files changed

+105
-4
lines changed

7 files changed

+105
-4
lines changed

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ source 'https://rubygems.org'
22

33
gem 'byebug'
44
gem 'lp'
5-
gem 'rentacop'
65
gem 'rspec'
76
gem 'rspec_approvals'
87
gem 'runfile'

lib/bashly/views/command/fixed_flags_filter.gtx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
= view_marker
22

3-
> case "${1:-}" in
3+
> while [[ $# -gt 0 ]]; do
4+
> case "${1:-}" in
45

56
if root_command?
67
= short_flag_exist?("-v") ? "--version )" : "--version | -v )"
@@ -19,9 +20,14 @@ end
1920

2021
if global_flags?
2122
flags.each do |flag|
22-
= flag.render(:case)
23+
= flag.render(:case).indent(2)
2324
end
2425
end
2526

26-
> esac
27+
> * )
28+
> break
29+
> ;;
30+
>
31+
> esac
32+
> done
2733
>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
+ bundle exec bashly generate
2+
creating user files in src
3+
created src/initialize.sh
4+
created src/show_command.sh
5+
created ./flags
6+
run ./flags --help to test your bash script
7+
+ ./flags -h
8+
flags - Verifies multiple global flags work as expected
9+
10+
Usage:
11+
flags [OPTIONS] COMMAND
12+
flags [COMMAND] --help | -h
13+
flags --version | -v
14+
15+
Commands:
16+
show
17+
18+
Options:
19+
--help, -h
20+
Show this help
21+
22+
--version, -v
23+
Show version number
24+
25+
--alpha, -a
26+
Alpha
27+
28+
--bravo, -b
29+
Bravo
30+
31+
--charlie, -c NAME (required)
32+
Charlie
33+
Allowed: chaplin
34+
35+
+ ./flags show
36+
missing required flag: --charlie, -c NAME
37+
+ ./flags -c clark show
38+
--charlie must be one of: chaplin
39+
+ ./flags -c chaplin show
40+
# this file is located in 'src/show_command.sh'
41+
# code for 'flags show' goes here
42+
# you can edit it freely and regenerate (it will not be overwritten)
43+
args:
44+
- ${args[--charlie]} = chaplin
45+
+ ./flags -c chaplin -ab show
46+
# this file is located in 'src/show_command.sh'
47+
# code for 'flags show' goes here
48+
# you can edit it freely and regenerate (it will not be overwritten)
49+
args:
50+
- ${args[--alpha]} = 1
51+
- ${args[--bravo]} = 1
52+
- ${args[--charlie]} = chaplin
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
flags
2+
src/*.sh
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This fixture tests the global flags feature, and specifically, that it works
2+
with multiple flags.
3+
4+
Reference issue: https://github.com/DannyBen/bashly/issues/293
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: flags
2+
help: Verifies multiple global flags work as expected
3+
version: 0.1.0
4+
5+
flags:
6+
- long: --alpha
7+
short: -a
8+
help: Alpha
9+
- long: --bravo
10+
short: -b
11+
help: Bravo
12+
- long: --charlie
13+
short: -c
14+
help: Charlie
15+
arg: name
16+
required: true
17+
allowed: [chaplin]
18+
19+
commands:
20+
- name: show
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
# This fixture tests the global flags feature, and specifically, that it works
4+
# with multiple flags.
5+
# Reference issue: https://github.com/DannyBen/bashly/issues/293
6+
7+
rm -f ./src/*.sh
8+
rm -f ./flags
9+
10+
set -x
11+
12+
bundle exec bashly generate
13+
14+
./flags -h
15+
./flags show
16+
./flags -c clark show
17+
./flags -c chaplin show
18+
./flags -c chaplin -ab show

0 commit comments

Comments
 (0)