Skip to content

Commit e9e2d20

Browse files
authored
Merge pull request #34 from DannyBen/next
Add flag.needs
2 parents 0425430 + f9b88b5 commit e9e2d20

File tree

6 files changed

+93
-4
lines changed

6 files changed

+93
-4
lines changed

src/advanced/validations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ order: 80
55

66
# Custom Validations
77

8-
Bashly supports custom validation functions for your arguments, and flag
9-
arguments. This is how it works:
8+
Bashly supports custom validation functions for your arguments, flag
9+
arguments, and environment variables. This is how it works:
1010

1111
1. In your bashly configuration file, arguments and flags (with arguments)
1212
may have a `validate: function_name` option.

src/configuration/command.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,9 @@ as a "last resort" mechanism to help in solving more complex scenarios.
345345

346346
Setting this to `true` on any command, will hide it from the command list.
347347

348+
!!!success Tip
349+
To allow users to see private commands, see
350+
[Settings :icon-chevron-right: private_reveal_key](/usage/settings/#private_reveal_key)
351+
!!!
352+
348353
[!button variant="primary" icon="code-review" text="Private Command Example"](https://github.com/DannyBen/bashly/tree/master/examples/command-private#readme)

src/configuration/environment-variable.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ environment variable is optional.
7171
Setting this to `true` on any environment variable, will hide it from the help
7272
text.
7373

74+
!!!success Tip
75+
To allow users to see private environment variables, see
76+
[Settings :icon-chevron-right: private_reveal_key](/usage/settings/#private_reveal_key)
77+
!!!
78+
7479
### required
7580

7681
[!badge Boolean]
@@ -85,3 +90,11 @@ Specify if this variable is required.
8590

8691
Limit the allowed values to a specified whitelist. Can be used in conjunction
8792
with [`default`](#default) or [`required`](#required).
93+
94+
### validate
95+
96+
[!badge String]
97+
98+
Apply a custom validation function.
99+
100+
[!ref](/advanced/validations)

src/configuration/flag.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Remember to set the [`arg`](#arg) name when using this option.
142142
[!badge Array of Strings]
143143

144144
Specify that this flag is mutually exclusive with one or more other flags.
145-
The values of this array should be the long versions of the flags:
145+
The values of this array should be the long versions of the flags:
146146
`conflicts: [--other, --another]`
147147

148148
!!! Note
@@ -163,12 +163,33 @@ Remember to set the [`arg`](#arg) name when using this option.
163163

164164
[!ref](/advanced/bash-completion.md)
165165

166+
167+
### needs
168+
169+
[!badge Array of Strings]
170+
171+
Specify that this flag needs one or more other flags when executed.
172+
The values of this array should be the long versions of the flags:
173+
`needs: [--other, --another]`
174+
175+
!!! Note
176+
This option should be specified on both sides of the requirement.
177+
!!!
178+
179+
[!button variant="primary" icon="code-review" text="Needy Flags Example"](https://github.com/DannyBen/bashly/tree/master/examples/needs#readme)
180+
181+
166182
### private
167183

168184
[!badge Boolean]
169185

170186
Setting this to `true` on any flag, will hide it from the help text.
171187

188+
!!!success Tip
189+
To allow users to see private flags, see
190+
[Settings :icon-chevron-right: private_reveal_key](/usage/settings/#private_reveal_key)
191+
!!!
192+
172193
### repeatable
173194

174195
[!badge Boolean]

src/examples.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ All examples are listed below for convenience.
4444
- [repeatable-flag](https://github.com/DannyBen/bashly/tree/master/examples/repeatable-flag#readme) - allowing flags to be provided multiple times
4545
- [reusable-flags](https://github.com/DannyBen/bashly/tree/master/examples/reusable-flags#readme) - reuse flag definition for multiple commands
4646
- [conflicts](https://github.com/DannyBen/bashly/tree/master/examples/conflicts#readme) - defining mutually exclusive flags
47+
- [needs](https://github.com/DannyBen/bashly/tree/master/examples/needs#readme) - defining flags that need other flags
4748
- [command-private](https://github.com/DannyBen/bashly/tree/master/examples/command-private#readme) - hiding commands from the command list
4849
- [stdin](https://github.com/DannyBen/bashly/tree/master/examples/stdin#readme) - reading input from stdin
4950
- [filters](https://github.com/DannyBen/bashly/tree/master/examples/filters#readme) - preventing commands from running unless custom conditions are met
@@ -71,7 +72,7 @@ All examples are listed below for convenience.
7172
- [yaml](https://github.com/DannyBen/bashly/tree/master/examples/yaml#readme) - using the YAML reading functions
7273
- [colors](https://github.com/DannyBen/bashly/tree/master/examples/colors#readme) - using the color print feature
7374
- [completions](https://github.com/DannyBen/bashly/tree/master/examples/completions#readme) - adding bash completion functionality
74-
- [validations](https://github.com/DannyBen/bashly/tree/master/examples/validations#readme) - adding argument validation functions
75+
- [validations](https://github.com/DannyBen/bashly/tree/master/examples/validations#readme) - adding validation functions for arguments, flags or environment variables
7576
- [hooks](https://github.com/DannyBen/bashly/tree/master/examples/hooks#readme) - adding before/after hooks
7677

7778
## Real-world-like examples

src/usage/settings.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ When setting environment variables, you can use:
4848
### `source_dir`
4949

5050
```yaml
51+
# default
5152
source_dir: src
5253
```
5354
@@ -56,6 +57,7 @@ Set the path containing the bashly source files.
5657
### `config_path`
5758

5859
```yaml
60+
# default
5961
config_path: "%{source_dir}/bashly.yml"
6062
```
6163

@@ -65,6 +67,7 @@ reference the value of the `source_dir` option.
6567
### `target_dir`
6668

6769
```yaml
70+
# default
6871
target_dir: .
6972
```
7073

@@ -73,6 +76,7 @@ Set the path to use for creating the final bash script.
7376
### `lib_dir`
7477

7578
```yaml
79+
# default
7680
lib_dir: lib
7781
```
7882

@@ -81,7 +85,11 @@ Set the path to use for common library files, relative to `source_dir`.
8185
### `commands_dir`
8286

8387
```yaml
88+
# default
8489
commands_dir: ~
90+
91+
# example
92+
commands_dir: commands
8593
```
8694

8795
Set the path to use for command files, relative to `source_dir`.
@@ -99,7 +107,13 @@ recommended to enable this by setting it to something like
99107
### `strict`
100108

101109
```yaml
110+
# default
102111
strict: false
112+
113+
# examples
114+
strict: true
115+
strict: ''
116+
strict: set -o pipefail
103117
```
104118

105119
Specify which bash options to apply on initialization.
@@ -113,6 +127,7 @@ Specify which bash options to apply on initialization.
113127
### `tab_indent`
114128

115129
```yaml
130+
# default
116131
tab_indent: false
117132
```
118133

@@ -125,6 +140,7 @@ Specify the indentation style of the generated script.
125140
### `compact_short_flags`
126141

127142
```yaml
143+
# default
128144
compact_short_flags: true
129145
```
130146

@@ -136,6 +152,7 @@ Specify how the generated script should treat flags in the form of `-abc`
136152
### `conjoined_flag_args`
137153

138154
```yaml
155+
# default
139156
conjoined_flag_args: true
140157
```
141158

@@ -148,6 +165,7 @@ or `-f=value`
148165
### `env`
149166

150167
```yaml
168+
# default
151169
env: development
152170
```
153171

@@ -166,7 +184,11 @@ user's partial code files.
166184
### `partials_extension`
167185

168186
```yaml
187+
# default
169188
partials_extension: sh
189+
190+
# example
191+
partials_extension: bash
170192
```
171193

172194
Set the extension to use when reading/writing partial script snippets.
@@ -175,6 +197,7 @@ Set the extension to use when reading/writing partial script snippets.
175197
### `show_examples_on_error`
176198

177199
```yaml
200+
# default
178201
show_examples_on_error: false
179202
```
180203

@@ -185,15 +208,41 @@ provide the required arguments.
185208
[!button variant="primary" icon="code-review" text="Show Examples on Error Example"](https://github.com/DannyBen/bashly/tree/master/examples/command-examples-on-error#readme)
186209

187210

211+
### `private_reveal_key`
212+
213+
```yaml
214+
# default
215+
private_reveal_key: ~
216+
217+
# example
218+
private_reveal_key: ADVANCED_FEATURES
219+
```
220+
221+
When using private commands, flags, or environment variables, you may set
222+
this option to a name of an environment variable that, if set, will reveal
223+
all the private elements in the usage texts, as if they were public.
224+
225+
[!button variant="primary" icon="code-review" text="Private Reveal Example"](https://github.com/DannyBen/bashly/tree/master/examples/private-reveal#readme)
226+
227+
188228
### `usage_colors`
189229

190230
```yaml
231+
# default
191232
usage_colors:
192233
caption: ~
193234
command: ~
194235
arg: ~
195236
flag: ~
196237
environment_variable: ~
238+
239+
# example
240+
usage_colors:
241+
caption: bold
242+
command: green_underlined
243+
arg: blue
244+
flag: magenta
245+
environment_variable: cyan_bold
197246
```
198247

199248
Enable color output for several aspects of the help message of the generated

0 commit comments

Comments
 (0)