Skip to content

Commit c6a71f5

Browse files
committed
improve env var example
1 parent 1f85d53 commit c6a71f5

File tree

5 files changed

+54
-37
lines changed

5 files changed

+54
-37
lines changed

examples/environment-variables/README.md

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,30 @@ name: cli
1111
help: Sample application that requires environment variables
1212
version: 0.1.0
1313

14-
# These two variable options add usage text to the help message in the
15-
# generated script.
16-
# In addition, the value of the variable `ENVIRONMENT` will be set to
17-
# `development` if it is not already set by the user.
14+
# This option adds usage text to the help message in the generated script.
1815
environment_variables:
1916
- name: api_key
2017
help: Set your API key
21-
- name: environment
22-
help: One of development, production or test
23-
default: development
2418

2519
commands:
2620
- name: verify
2721
short: v
2822
help: Verify your user
2923

3024
# This option belongs to the `verify` command and will appear in its help
31-
# message. In addition, setting `required: true` will halt the script's
32-
# execution with a friendly error message, unless the variable is set.
25+
# message.
3326
environment_variables:
27+
# Setting `required: true` will halt the script's execution with a
28+
# friendly error message, unless the variable is set.
3429
- name: my_secret
3530
help: Your secret
3631
required: true
32+
33+
# Using the `default: value` option will cause the value to variable to be
34+
# set if it is not provided by the user.
35+
- name: environment
36+
help: One of development, production or test
37+
default: development
3738
```
3839
3940
## Generated script output
@@ -79,10 +80,6 @@ Environment Variables:
7980
API_KEY
8081
Set your API key
8182
82-
ENVIRONMENT
83-
One of development, production or test
84-
Default: development
85-
8683
8784
8885
```
@@ -106,6 +103,10 @@ Environment Variables:
106103
MY_SECRET (required)
107104
Your secret
108105
106+
ENVIRONMENT
107+
One of development, production or test
108+
Default: development
109+
109110
110111
111112
```
@@ -133,10 +134,17 @@ environment:
133134
134135
```
135136

136-
### `$ ENVIRONMENT=production ./cli verify`
137+
### `$ ENVIRONMENT=production MY_SECRET=safe-with-me ./cli verify`
137138

138139
```shell
139-
missing required environment variable: MY_SECRET
140+
# this file is located in 'src/verify_command.sh'
141+
# code for 'cli verify' goes here
142+
# you can edit it freely and regenerate (it will not be overwritten)
143+
args: none
144+
environment:
145+
- API_KEY=
146+
- ENVIRONMENT=production
147+
- MY_SECRET=safe-with-me
140148
141149
142150
```

examples/environment-variables/cli

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ cli_usage() {
4444
echo " API_KEY"
4545
printf " Set your API key\n"
4646
echo
47-
48-
# :environment_variable.usage
49-
echo " ENVIRONMENT"
50-
printf " One of development, production or test\n"
51-
printf " Default: development\n"
52-
echo
5347

5448
fi
5549
}
@@ -86,6 +80,12 @@ cli_verify_usage() {
8680
echo " MY_SECRET (required)"
8781
printf " Your secret\n"
8882
echo
83+
84+
# :environment_variable.usage
85+
echo " ENVIRONMENT"
86+
printf " One of development, production or test\n"
87+
printf " Default: development\n"
88+
echo
8989

9090
fi
9191
}
@@ -142,7 +142,6 @@ parse_requirements() {
142142

143143
esac
144144
# :command.environment_variables_filter
145-
export ENVIRONMENT="${ENVIRONMENT:-development}"
146145
# :command.dependencies_filter
147146
# :command.command_filter
148147
action=$1
@@ -206,6 +205,7 @@ cli_verify_parse_requirements() {
206205

207206
esac
208207
# :command.environment_variables_filter
208+
export ENVIRONMENT="${ENVIRONMENT:-development}"
209209
if [[ -z "$MY_SECRET" ]]; then
210210
printf "missing required environment variable: MY_SECRET\n"
211211
exit 1

examples/environment-variables/src/bashly.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,27 @@ name: cli
22
help: Sample application that requires environment variables
33
version: 0.1.0
44

5-
# These two variable options add usage text to the help message in the
6-
# generated script.
7-
# In addition, the value of the variable `ENVIRONMENT` will be set to
8-
# `development` if it is not already set by the user.
5+
# This option adds usage text to the help message in the generated script.
96
environment_variables:
107
- name: api_key
118
help: Set your API key
12-
- name: environment
13-
help: One of development, production or test
14-
default: development
159

1610
commands:
1711
- name: verify
1812
short: v
1913
help: Verify your user
2014

2115
# This option belongs to the `verify` command and will appear in its help
22-
# message. In addition, setting `required: true` will halt the script's
23-
# execution with a friendly error message, unless the variable is set.
16+
# message.
2417
environment_variables:
18+
# Setting `required: true` will halt the script's execution with a
19+
# friendly error message, unless the variable is set.
2520
- name: my_secret
2621
help: Your secret
2722
required: true
23+
24+
# Using the `default: value` option will cause the value to variable to be
25+
# set if it is not provided by the user.
26+
- name: environment
27+
help: One of development, production or test
28+
default: development

examples/environment-variables/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ bashly generate
1111
./cli verify -h
1212
./cli verify
1313
MY_SECRET="there is no spoon" ./cli verify
14-
ENVIRONMENT=production ./cli verify
14+
ENVIRONMENT=production MY_SECRET=safe-with-me ./cli verify

spec/approvals/examples/environment-variables

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ Environment Variables:
3737
API_KEY
3838
Set your API key
3939

40-
ENVIRONMENT
41-
One of development, production or test
42-
Default: development
43-
4440
+ ./cli verify -h
4541
cli verify - Verify your user
4642

@@ -58,6 +54,10 @@ Environment Variables:
5854
MY_SECRET (required)
5955
Your secret
6056

57+
ENVIRONMENT
58+
One of development, production or test
59+
Default: development
60+
6161
+ ./cli verify
6262
missing required environment variable: MY_SECRET
6363
+ MY_SECRET='there is no spoon'
@@ -71,5 +71,13 @@ environment:
7171
- ENVIRONMENT=development
7272
- MY_SECRET=there is no spoon
7373
+ ENVIRONMENT=production
74+
+ MY_SECRET=safe-with-me
7475
+ ./cli verify
75-
missing required environment variable: MY_SECRET
76+
# this file is located in 'src/verify_command.sh'
77+
# code for 'cli verify' goes here
78+
# you can edit it freely and regenerate (it will not be overwritten)
79+
args: none
80+
environment:
81+
- API_KEY=
82+
- ENVIRONMENT=production
83+
- MY_SECRET=safe-with-me

0 commit comments

Comments
 (0)