Skip to content

Commit 9b55da5

Browse files
committed
- Fix environment variables caption to not show if all are private
1 parent a4a824d commit 9b55da5

File tree

8 files changed

+55
-2
lines changed

8 files changed

+55
-2
lines changed

lib/bashly/script/command.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ def public_commands
217217
commands.reject(&:private)
218218
end
219219

220+
# Returns only environment variables that are not private
221+
def public_environment_variables
222+
environment_variables.reject(&:private)
223+
end
224+
220225
# Returns true if one of the args is repeatable
221226
def repeatable_arg_exist?
222227
args.select(&:repeatable).any?

lib/bashly/views/command/long_usage.gtx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
= render(:usage_flags).indent 2 if flags.any?
77
= render(:usage_fixed_flags).indent 2
88
= render(:usage_args).indent 2 if args.any? or catch_all.help
9-
= render(:usage_environment_variables).indent 2 if environment_variables.any?
9+
= render(:usage_environment_variables).indent 2 if public_environment_variables.any?
1010
= render(:usage_examples).indent 2 if examples
1111
= render(:footer).indent 2 if footer
1212
>

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 "%s\n" "{{ strings[:environment_variables].color(:caption) }}"
44
>
55

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
creating user files in src
2+
created src/initialize.sh
3+
created src/root_command.sh
4+
created ./cli
5+
run ./cli --help to test your bash script
6+
+ ./cli --help
7+
cli
8+
9+
Usage:
10+
cli
11+
cli --help | -h
12+
cli --version | -v
13+
14+
Options:
15+
--help, -h
16+
Show this help
17+
18+
--version, -v
19+
Show version number
20+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cli
2+
src/*.sh
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This fixture tests that there is no group caption if all env vars are private
2+
3+
Reference issue: https://github.com/DannyBen/bashly/issues/331
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: cli
2+
version: 0.1.0
3+
4+
environment_variables:
5+
- name: example
6+
default: value
7+
private: true
8+
help: A help message for EXAMPLE
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
# This fixture tests that default values for environment variables exist in
4+
# the initialize function, and that required environment variables are NOT
5+
# blocking --help.
6+
# Reference issue: https://github.com/DannyBen/bashly/issues/265
7+
8+
rm -f ./src/*.sh
9+
rm -f ./cli
10+
11+
bundle exec bashly generate
12+
13+
set -x
14+
15+
./cli --help

0 commit comments

Comments
 (0)