Skip to content

Commit a304f69

Browse files
authored
Merge pull request #304 from DannyBen/add/private-env-var
Add ability to define a private environment variable
2 parents 4f1053d + 5a7634f commit a304f69

File tree

7 files changed

+25
-3
lines changed

7 files changed

+25
-3
lines changed

lib/bashly/config_validator.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ def assert_env_var(key, value)
124124
assert_optional_string "#{key}.help", value['help']
125125
assert_optional_string "#{key}.default", value['default']
126126
assert_boolean "#{key}.required", value['required']
127+
assert_boolean "#{key}.private", value['private']
128+
129+
if value['private']
130+
assert value['default'], "#{key}.private makes no sense without default"
131+
end
127132
end
128133

129134
def assert_command(key, value)

lib/bashly/script/environment_variable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Script
33
class EnvironmentVariable < Base
44
class << self
55
def option_keys
6-
@option_keys ||= %i[default help name required]
6+
@option_keys ||= %i[default help name required private]
77
end
88
end
99

lib/bashly/views/command/usage_environment_variables.gtx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
> printf "{{ strings[:environment_variables] }}\n"
44
>
55

6-
environment_variables.each do |env_var|
6+
environment_variables.reject(&:private).each do |env_var|
77
= env_var.render :usage
88
end
99

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<Bashly::ConfigurationError: root.environment_variables[0].private must be a boolean>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<Bashly::ConfigurationError: root.environment_variables[0].private makes no sense without default>

spec/fixtures/script/validations.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,28 @@
132132
- name: sub
133133
default: true
134134

135-
:env_var:
135+
:env_var_required:
136136
name: invalid
137137
help: env_var.required should be a boolean
138138
environment_variables:
139139
- name: api_key
140140
required: 1
141141

142+
:env_var_private:
143+
name: invalid
144+
help: env_var.private should be a boolean
145+
environment_variables:
146+
- name: server_env
147+
default: development
148+
private: 1
149+
150+
:env_var_private_without_default:
151+
name: invalid
152+
help: env_var.private makes no sense without default
153+
environment_variables:
154+
- name: server_env
155+
private: true
156+
142157
:flag_long:
143158
name: invalid
144159
help: the long flag is not in the form of --force

0 commit comments

Comments
 (0)