Skip to content

Commit 8c94042

Browse files
committed
- Add private-reveal example
1 parent beb0c02 commit 8c94042

File tree

9 files changed

+340
-0
lines changed

9 files changed

+340
-0
lines changed

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: 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/libraries/settings/settings.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ partials_extension: sh
5959
# required arguments
6060
show_examples_on_error: false
6161

62+
# When using private commands, flags, or environment variables, you may set
63+
# this option to a name of an environment variable that, if set, will reveal
64+
# all the private elements in the usage texts, as if they were public.
65+
private_reveal_key: ~
66+
6267
# Display various usage elements in color by providing the name of the color
6368
# function. The value for each property is a name of a function that is
6469
# available in your script, for example: `green` or `bold`.

schemas/settings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,19 @@
136136
"minLength": 1,
137137
"default": "sh"
138138
},
139+
"private_reveal_key": {
140+
"title": "private reveal key",
141+
"description": "The name of the environment variable (case sensitive) that, if set, will reveal private commands, flags and environment variables\nhttps://bashly.dannyb.co/usage/settings/#private_reveal_key",
142+
"oneOf": [
143+
{
144+
"type": "string",
145+
"minLength": 1
146+
},
147+
{
148+
"type": "null"
149+
}
150+
]
151+
},
139152
"usage_colors": {
140153
"title": "usage colors",
141154
"description": "Enable and configure colorful output for --help\nhttps://bashly.dannyb.co/usage/settings/#usage_colors",
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
+ ./cli
2+
cli - Sample application
3+
4+
Usage:
5+
cli [OPTIONS] COMMAND
6+
cli [COMMAND] --help | -h
7+
cli --version | -v
8+
9+
Commands:
10+
admin Admin operations
11+
12+
+ ./cli -h
13+
cli - Sample application
14+
15+
Usage:
16+
cli [OPTIONS] COMMAND
17+
cli [COMMAND] --help | -h
18+
cli --version | -v
19+
20+
Commands:
21+
admin Admin operations
22+
admin list List connected devices
23+
24+
Global Options:
25+
--help, -h
26+
Show this help
27+
28+
--version, -v
29+
Show version number
30+
31+
+ ./cli admin -h
32+
cli admin - Admin operations
33+
34+
Usage:
35+
cli admin COMMAND
36+
cli admin [COMMAND] --help | -h
37+
38+
Commands:
39+
list List connected devices
40+
41+
Options:
42+
--help, -h
43+
Show this help
44+
45+
+ export SHOW_PLEASE=1
46+
+ SHOW_PLEASE=1
47+
+ ./cli -h
48+
cli - Sample application
49+
50+
Usage:
51+
cli [OPTIONS] COMMAND
52+
cli [COMMAND] --help | -h
53+
cli --version | -v
54+
55+
Commands:
56+
admin Admin operations
57+
admin list List connected devices
58+
admin reboot Reboot
59+
60+
Global Options:
61+
--debug
62+
Enable debug mode
63+
64+
--help, -h
65+
Show this help
66+
67+
--version, -v
68+
Show version number
69+
70+
Environment Variables:
71+
SECRET
72+
Set secret key
73+
74+
+ ./cli admin -h
75+
cli admin - Admin operations
76+
77+
Usage:
78+
cli admin COMMAND
79+
cli admin [COMMAND] --help | -h
80+
81+
Commands:
82+
list List connected devices
83+
reboot Reboot
84+
85+
Options:
86+
--help, -h
87+
Show this help
88+

0 commit comments

Comments
 (0)