Skip to content

Commit a320ae8

Browse files
committed
- Add default option for environment variables
1 parent f60ef78 commit a320ae8

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

lib/bashly/models/command.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ def default_command
9292
commands.find { |c| c.default }
9393
end
9494

95+
# Returns an array of all the default Environment Variables
96+
def default_environment_variables
97+
environment_variables.select &:default
98+
end
99+
95100
# Returns an array of all the default Flags
96101
def default_flags
97102
flags.select &:default

lib/bashly/views/command/environment_variables_filter.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# :command.environment_variables_filter
2+
<%- if default_environment_variables.any? -%>
3+
<%- default_environment_variables.each do |env_var| -%>
4+
export <%= env_var.name.upcase %>="${<%= env_var.name.upcase %>:-<%= env_var.default %>}"
5+
<%- end -%>
6+
<%- end -%>
27
<%- if required_environment_variables.any? -%>
38
<%- required_environment_variables.each do |env_var| -%>
49
if [[ -z "$<%= env_var.name.upcase %>" ]]; then
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# :environment_variable.usage
22
echo " <%= usage_string extended: true %>"
33
printf "<%= help.wrap(76).indent(4).sanitize_for_print %>\n"
4+
<%- if default -%>
5+
printf " <%= strings[:default] % { value: default } -%>\n"
6+
<%- end -%>
47
echo

0 commit comments

Comments
 (0)