Skip to content

Commit ce303a6

Browse files
authored
Merge branch 'master' into fix/env-var
2 parents 2c5b4f7 + 2f88a77 commit ce303a6

File tree

10 files changed

+69
-3
lines changed

10 files changed

+69
-3
lines changed

lib/bashly/config_validator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def assert_flag(key, value)
9999
assert_optional_string "#{key}.default", value['default']
100100
assert_optional_string "#{key}.validate", value['validate']
101101

102+
assert_boolean "#{key}.private", value['private']
102103
assert_boolean "#{key}.repeatable", value['repeatable']
103104
assert_boolean "#{key}.required", value['required']
104105
assert_array "#{key}.allowed", value['allowed'], of: :string

lib/bashly/script/command.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ def public_commands
220220
# Returns only environment variables that are not private
221221
def public_environment_variables
222222
environment_variables.reject(&:private)
223+
224+
# Returns only flags that are not private
225+
def public_flags
226+
flags.reject(&:private)
223227
end
224228

225229
# Returns true if one of the args is repeatable

lib/bashly/script/flag.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class << self
77
def option_keys
88
@option_keys ||= %i[
99
allowed arg completions conflicts default help long repeatable
10-
required short validate
10+
required short validate private
1111
]
1212
end
1313
end

lib/bashly/views/command/long_usage.gtx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
> if [[ -n $long_usage ]]; then
44
> printf "%s\n" "{{ strings[:options].color(:caption) }}"
55
>
6-
= render(:usage_flags).indent 2 if flags.any?
6+
= render(:usage_flags).indent 2 if public_flags.any?
77
= render(:usage_fixed_flags).indent 2
88
= render(:usage_args).indent 2 if args.any? or catch_all.help
99
= render(:usage_environment_variables).indent 2 if public_environment_variables.any?

lib/bashly/views/command/usage_flags.gtx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
= view_marker
22

3-
flags.each do |flag|
3+
public_flags.each do |flag|
44
= flag.render :usage
55
end
66

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
+ bundle exec bashly generate
2+
creating user files in src
3+
created src/initialize.sh
4+
created src/root_command.sh
5+
created ./cli
6+
run ./cli --help to test your bash script
7+
+ ./cli
8+
# this file is located in 'src/root_command.sh'
9+
# you can edit it freely and regenerate (it will not be overwritten)
10+
args:
11+
- ${args[--log]} = 3
12+
+ ./cli --help
13+
cli
14+
15+
Usage:
16+
cli [OPTIONS]
17+
cli --help | -h
18+
cli --version | -v
19+
20+
Options:
21+
--force, -f
22+
Overwrite existing files
23+
24+
--help, -h
25+
Show this help
26+
27+
--version, -v
28+
Show version number
29+
30+
+ ./cli --log 5
31+
# this file is located in 'src/root_command.sh'
32+
# you can edit it freely and regenerate (it will not be overwritten)
33+
args:
34+
- ${args[--log]} = 5
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Validate private flags
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: cli
2+
3+
flags:
4+
- long: --log
5+
short: -l
6+
arg: level
7+
help: Log level
8+
private: true
9+
default: '3'
10+
- long: --force
11+
short: -f
12+
help: Overwrite existing files
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
rm -f ./src/*.sh
4+
rm -f ./cli
5+
6+
set -x
7+
8+
bundle exec bashly generate
9+
10+
./cli
11+
./cli --help
12+
./cli --log 5

0 commit comments

Comments
 (0)