Skip to content

Commit af15e64

Browse files
authored
Merge pull request #550 from DannyBen/refactor/private-commands
Allow ad-hoc revealing of private commands, flags, and environment variables
2 parents 1b104a5 + f789858 commit af15e64

34 files changed

+571
-40
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*.gem
22
/.yardoc
33
/coverage
4+
/spec/coverage
45
/dev
56
/doc
67
/Gemfile.lock

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Each of these examples demonstrates one aspect or feature of bashly.
3535
- [conflicts](conflicts#readme) - defining mutually exclusive flags
3636
- [needs](needs#readme) - defining flags that need other flags
3737
- [command-private](command-private#readme) - hiding commands from the command list
38+
- [private-reveal](private-reveal#readme) - allowing users to reveal private commands, flags or environment variables
3839
- [stdin](stdin#readme) - reading input from stdin
3940
- [filters](filters#readme) - preventing commands from running unless custom conditions are met
4041
- [commands-expose](commands-expose#readme) - showing sub-commands in the parent's help

examples/private-reveal/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cli

examples/private-reveal/README.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# Private Reveal Example
2+
3+
Demonstrates how to allow users to reveal any private commands, flags and
4+
environment variables.
5+
6+
This example was generated with:
7+
8+
```bash
9+
$ bashly init
10+
$ bashly add settings
11+
# ... now edit settings.yml to match the example ...
12+
# ... now edit src/bashly.yml to match the example ...
13+
$ bashly generate
14+
```
15+
16+
<!-- include: settings.yml -->
17+
18+
-----
19+
20+
## `bashly.yml`
21+
22+
````yaml
23+
name: cli
24+
help: Sample application
25+
version: 0.1.0
26+
27+
# All elements with `private: true` in this configuration will be hidden
28+
# unless the environment variable SHOW_PELASE is set (as defined
29+
# in ../settings.yml)
30+
31+
environment_variables:
32+
- name: secret
33+
help: Set secret key
34+
private: true
35+
36+
flags:
37+
- long: --debug
38+
help: Enable debug mode
39+
private: true
40+
41+
commands:
42+
- name: admin
43+
help: Admin operations
44+
expose: true
45+
46+
commands:
47+
- name: list
48+
help: List connected devices
49+
- name: reboot
50+
help: Reboot
51+
private: true
52+
````
53+
54+
## `settings.yml`
55+
56+
````yaml
57+
# When using private commands, flags, or environment variables, you may set
58+
# this option to a name of an environment variable that, if set, will reveal
59+
# all the private elements in the usage texts, as if they were public.
60+
private_reveal_key: SHOW_PLEASE
61+
````
62+
63+
64+
## Output
65+
66+
### `$ ./cli`
67+
68+
````shell
69+
cli - Sample application
70+
71+
Usage:
72+
cli [OPTIONS] COMMAND
73+
cli [COMMAND] --help | -h
74+
cli --version | -v
75+
76+
Commands:
77+
admin Admin operations
78+
79+
80+
81+
````
82+
83+
### `$ ./cli -h`
84+
85+
````shell
86+
cli - Sample application
87+
88+
Usage:
89+
cli [OPTIONS] COMMAND
90+
cli [COMMAND] --help | -h
91+
cli --version | -v
92+
93+
Commands:
94+
admin Admin operations
95+
admin list List connected devices
96+
97+
Global Options:
98+
--help, -h
99+
Show this help
100+
101+
--version, -v
102+
Show version number
103+
104+
105+
106+
````
107+
108+
### `$ ./cli admin -h`
109+
110+
````shell
111+
cli admin - Admin operations
112+
113+
Usage:
114+
cli admin COMMAND
115+
cli admin [COMMAND] --help | -h
116+
117+
Commands:
118+
list List connected devices
119+
120+
Options:
121+
--help, -h
122+
Show this help
123+
124+
125+
126+
````
127+
128+
### `$ export SHOW_PLEASE=1`
129+
130+
````shell
131+
132+
133+
````
134+
135+
### `$ ./cli -h`
136+
137+
````shell
138+
cli - Sample application
139+
140+
Usage:
141+
cli [OPTIONS] COMMAND
142+
cli [COMMAND] --help | -h
143+
cli --version | -v
144+
145+
Commands:
146+
admin Admin operations
147+
admin list List connected devices
148+
149+
Global Options:
150+
--help, -h
151+
Show this help
152+
153+
--version, -v
154+
Show version number
155+
156+
157+
158+
````
159+
160+
### `$ ./cli admin -h`
161+
162+
````shell
163+
cli admin - Admin operations
164+
165+
Usage:
166+
cli admin COMMAND
167+
cli admin [COMMAND] --help | -h
168+
169+
Commands:
170+
list List connected devices
171+
172+
Options:
173+
--help, -h
174+
Show this help
175+
176+
177+
178+
````
179+
180+
181+

examples/private-reveal/settings.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# When using private commands, flags, or environment variables, you may set
2+
# this option to a name of an environment variable that, if set, will reveal
3+
# all the private elements in the usage texts, as if they were public.
4+
private_reveal_key: SHOW_PLEASE
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
echo "# this file is located in 'src/admin_list_command.sh'"
2+
echo "# code for 'cli admin list' goes here"
3+
echo "# you can edit it freely and regenerate (it will not be overwritten)"
4+
inspect_args
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
echo "# this file is located in 'src/admin_reboot_command.sh'"
2+
echo "# code for 'cli admin reboot' goes here"
3+
echo "# you can edit it freely and regenerate (it will not be overwritten)"
4+
inspect_args
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: cli
2+
help: Sample application
3+
version: 0.1.0
4+
5+
# All elements with `private: true` in this configuration will be hidden
6+
# unless the environment variable SHOW_PELASE is set (as defined
7+
# in ../settings.yml)
8+
9+
environment_variables:
10+
- name: secret
11+
help: Set secret key
12+
private: true
13+
14+
flags:
15+
- long: --debug
16+
help: Enable debug mode
17+
private: true
18+
19+
commands:
20+
- name: admin
21+
help: Admin operations
22+
expose: true
23+
24+
commands:
25+
- name: list
26+
help: List connected devices
27+
- name: reboot
28+
help: Reboot
29+
private: true

examples/private-reveal/test.sh

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+
rm -f ./src/*.sh
4+
5+
set -x
6+
7+
bashly generate
8+
9+
### Try Me ###
10+
11+
./cli
12+
./cli -h
13+
./cli admin -h
14+
15+
export SHOW_PLEASE=1
16+
17+
./cli -h
18+
./cli admin -h

lib/bashly.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module Script
2828
module Introspection
2929
autoloads 'bashly/script/introspection', %i[
3030
Arguments Commands Dependencies EnvironmentVariables Examples Flags
31+
Visibility
3132
]
3233
end
3334
end

0 commit comments

Comments
 (0)