bashly 1.1.4 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bashly/commands/render.rb +1 -1
- data/lib/bashly/concerns/validation_helpers.rb +1 -1
- data/lib/bashly/config_validator.rb +15 -3
- data/lib/bashly/libraries/strings/strings.yml +1 -0
- data/lib/bashly/render_context.rb +1 -1
- data/lib/bashly/script/argument.rb +12 -0
- data/lib/bashly/script/command.rb +5 -0
- data/lib/bashly/script/environment_variable.rb +1 -1
- data/lib/bashly/script/flag.rb +10 -0
- data/lib/bashly/version.rb +1 -1
- data/lib/bashly/views/argument/usage.gtx +5 -1
- data/lib/bashly/views/command/default_assignments.gtx +2 -2
- data/lib/bashly/views/command/environment_variables_filter.gtx +23 -10
- data/lib/bashly/views/command/inspect_args.gtx +14 -2
- data/lib/bashly/views/command/run.gtx +1 -0
- data/lib/bashly/views/environment_variable/usage.gtx +4 -0
- data/lib/bashly/views/flag/usage.gtx +6 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17cea196efbe1bc65a6639258fe902503b75656c6a759ea5434a12d6a53d4529
|
4
|
+
data.tar.gz: 5e86d08e594250889bc351d5d6113bcfc40f8ec04ba39f72a7f19eec8329c7af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ade5312408fc08533dc6992673744920e941e142c09c9f05e58e66a08a6dfccfab100707cee319cb2ec388e60f9a73ae8ff735e8217c8f91820fc5e2e22af886
|
7
|
+
data.tar.gz: cf7f6da0438551ba2a10ed5c224d7ad6ac6b02d8675dca57c8ac01eb465e705a19bd2c3d1812b61b54ab52a433b5ce228b7f3b579e9de24f71c6f512caad1202
|
@@ -4,7 +4,7 @@ require 'tty-markdown'
|
|
4
4
|
module Bashly
|
5
5
|
module Commands
|
6
6
|
class Render < Base
|
7
|
-
help 'Render the bashly data structure using
|
7
|
+
help 'Render the bashly data structure using custom templates'
|
8
8
|
|
9
9
|
usage 'bashly render SOURCE TARGET [--watch --show PATH]'
|
10
10
|
usage 'bashly render SOURCE --about'
|
@@ -91,7 +91,7 @@ module Bashly
|
|
91
91
|
assert_hash key, value, keys: Script::Argument.option_keys
|
92
92
|
assert_string "#{key}.name", value['name']
|
93
93
|
assert_optional_string "#{key}.help", value['help']
|
94
|
-
|
94
|
+
assert_string_or_array "#{key}.default", value['default']
|
95
95
|
assert_optional_string "#{key}.validate", value['validate']
|
96
96
|
assert_boolean "#{key}.required", value['required']
|
97
97
|
assert_boolean "#{key}.repeatable", value['repeatable']
|
@@ -106,6 +106,10 @@ module Bashly
|
|
106
106
|
if value['unique']
|
107
107
|
assert value['repeatable'], "#{key}.unique does not make sense without nub`repeatable`"
|
108
108
|
end
|
109
|
+
|
110
|
+
if value['default'].is_a? Array
|
111
|
+
assert value['repeatable'], "#{key}.default array does not make sense without nub`repeatable`"
|
112
|
+
end
|
109
113
|
end
|
110
114
|
|
111
115
|
def assert_flag(key, value)
|
@@ -118,7 +122,7 @@ module Bashly
|
|
118
122
|
assert_optional_string "#{key}.short", value['short']
|
119
123
|
assert_optional_string "#{key}.help", value['help']
|
120
124
|
assert_optional_string "#{key}.arg", value['arg']
|
121
|
-
|
125
|
+
assert_string_or_array "#{key}.default", value['default']
|
122
126
|
assert_optional_string "#{key}.validate", value['validate']
|
123
127
|
|
124
128
|
assert_boolean "#{key}.private", value['private']
|
@@ -148,7 +152,12 @@ module Bashly
|
|
148
152
|
end
|
149
153
|
|
150
154
|
if value['unique']
|
151
|
-
assert value['arg'] && value['repeatable'],
|
155
|
+
assert value['arg'] && value['repeatable'],
|
156
|
+
"#{key}.unique does not make sense without nub`arg` and nub`repeatable`"
|
157
|
+
end
|
158
|
+
|
159
|
+
if value['default'].is_a? Array
|
160
|
+
assert value['repeatable'], "#{key}.default array does not make sense without nub`repeatable`"
|
152
161
|
end
|
153
162
|
end
|
154
163
|
|
@@ -159,6 +168,9 @@ module Bashly
|
|
159
168
|
assert_optional_string "#{key}.default", value['default']
|
160
169
|
assert_boolean "#{key}.required", value['required']
|
161
170
|
assert_boolean "#{key}.private", value['private']
|
171
|
+
assert_array "#{key}.allowed", value['allowed'], of: :string
|
172
|
+
|
173
|
+
refute value['required'] && value['default'], "#{key} cannot have both nub`required` and nub`default`"
|
162
174
|
end
|
163
175
|
|
164
176
|
def assert_command(key, value)
|
@@ -34,5 +34,6 @@ missing_required_environment_variable: "missing required environment variable: %
|
|
34
34
|
missing_dependency: "missing dependency: %{dependency}"
|
35
35
|
disallowed_flag: "%{name} must be one of: %{allowed}"
|
36
36
|
disallowed_argument: "%{name} must be one of: %{allowed}"
|
37
|
+
disallowed_environment_variable: "%{name} environment variable must be one of: %{allowed}"
|
37
38
|
unsupported_bash_version: "bash version 4 or higher is required"
|
38
39
|
validation_error: "validation error in %s:\\n%s"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'shellwords'
|
2
|
+
|
1
3
|
module Bashly
|
2
4
|
module Script
|
3
5
|
class Argument < Base
|
@@ -9,6 +11,16 @@ module Bashly
|
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
14
|
+
def default_string
|
15
|
+
if default.is_a?(Array)
|
16
|
+
Shellwords.shelljoin default
|
17
|
+
elsif default.is_a?(String) && repeatable
|
18
|
+
Shellwords.shellescape default
|
19
|
+
else
|
20
|
+
default
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
12
24
|
def usage_string
|
13
25
|
required ? label : "[#{label}]"
|
14
26
|
end
|
@@ -327,6 +327,11 @@ module Bashly
|
|
327
327
|
args.select(&:allowed)
|
328
328
|
end
|
329
329
|
|
330
|
+
# Returns an array of all the environemnt_variables with a whitelist arg
|
331
|
+
def whitelisted_environment_variables
|
332
|
+
environment_variables.select(&:allowed)
|
333
|
+
end
|
334
|
+
|
330
335
|
# Returns an array of all the flags with a whitelist arg
|
331
336
|
def whitelisted_flags
|
332
337
|
flags.select(&:allowed)
|
data/lib/bashly/script/flag.rb
CHANGED
@@ -22,6 +22,16 @@ module Bashly
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
def default_string
|
26
|
+
if default.is_a?(Array)
|
27
|
+
Shellwords.shelljoin default
|
28
|
+
elsif default.is_a?(String) && repeatable
|
29
|
+
Shellwords.shellescape default
|
30
|
+
else
|
31
|
+
default
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
25
35
|
def name
|
26
36
|
long || short
|
27
37
|
end
|
data/lib/bashly/version.rb
CHANGED
@@ -8,7 +8,11 @@ if allowed
|
|
8
8
|
end
|
9
9
|
|
10
10
|
if default
|
11
|
-
|
11
|
+
if default.is_a? Array
|
12
|
+
> printf " {{ strings[:default] % { value: default.join(', ') } }}\n"
|
13
|
+
else
|
14
|
+
> printf " {{ strings[:default] % { value: default } }}\n"
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
18
|
> echo
|
@@ -2,11 +2,11 @@ if default_args.any? or default_flags.any?
|
|
2
2
|
= view_marker
|
3
3
|
|
4
4
|
default_args.each do |arg|
|
5
|
-
> [[ -n ${args['{{ arg.name }}']:-} ]] || args['{{ arg.name }}']="{{ arg.
|
5
|
+
> [[ -n ${args['{{ arg.name }}']:-} ]] || args['{{ arg.name }}']="{{ arg.default_string }}"
|
6
6
|
end
|
7
7
|
|
8
8
|
default_flags.each do |flag|
|
9
|
-
> [[ -n ${args['{{ flag.name }}']:-} ]] || args['{{ flag.name }}']="{{ flag.
|
9
|
+
> [[ -n ${args['{{ flag.name }}']:-} ]] || args['{{ flag.name }}']="{{ flag.default_string }}"
|
10
10
|
end
|
11
11
|
|
12
12
|
>
|
@@ -1,13 +1,26 @@
|
|
1
|
-
if
|
2
|
-
= view_marker
|
1
|
+
if environment_variables.any?
|
2
|
+
= view_marker
|
3
3
|
= render(:environment_variables_default)
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
> if [[ -z "${<%= env_var.name.upcase %>:-}" ]]; then
|
8
|
-
> printf "{{ strings[:missing_required_environment_variable] % { var: env_var.name.upcase } }}\n" >&2
|
9
|
-
> exit 1
|
10
|
-
> fi
|
11
|
-
end
|
5
|
+
environment_variables.each do |env_var|
|
6
|
+
> env_var_names+=("{{ env_var.name.upcase }}")
|
12
7
|
end
|
13
|
-
end
|
8
|
+
end
|
9
|
+
|
10
|
+
if required_environment_variables.any?
|
11
|
+
required_environment_variables.each do |env_var|
|
12
|
+
> if [[ -z "${<%= env_var.name.upcase %>:-}" ]]; then
|
13
|
+
> printf "{{ strings[:missing_required_environment_variable] % { var: env_var.name.upcase } }}\n" >&2
|
14
|
+
> exit 1
|
15
|
+
> fi
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
if whitelisted_environment_variables.any?
|
20
|
+
whitelisted_environment_variables.each do |env_var|
|
21
|
+
> if [[ -n "${<%= env_var.name.upcase %>:-}" ]] && [[ ! ${<%= env_var.name.upcase %>:-} =~ ^({{ env_var.allowed.join '|' }})$ ]]; then
|
22
|
+
> printf "%s\n" "{{ strings[:disallowed_environment_variable] % { name: env_var.name.upcase, allowed: env_var.allowed.join(', ') } }}" >&2
|
23
|
+
> exit 1
|
24
|
+
> fi
|
25
|
+
end
|
26
|
+
end
|
@@ -4,7 +4,9 @@
|
|
4
4
|
> if ((${#args[@]})); then
|
5
5
|
> readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)
|
6
6
|
> echo args:
|
7
|
-
> for k in "${sorted_keys[@]}"; do
|
7
|
+
> for k in "${sorted_keys[@]}"; do
|
8
|
+
> echo "- \${args[$k]} = ${args[$k]}"
|
9
|
+
> done
|
8
10
|
> else
|
9
11
|
> echo args: none
|
10
12
|
> fi
|
@@ -22,8 +24,18 @@
|
|
22
24
|
> readarray -t sorted_keys < <(printf '%s\n' "${!deps[@]}" | sort)
|
23
25
|
> echo
|
24
26
|
> echo deps:
|
25
|
-
> for k in "${sorted_keys[@]}"; do
|
27
|
+
> for k in "${sorted_keys[@]}"; do
|
28
|
+
> echo "- \${deps[$k]} = ${deps[$k]}"
|
29
|
+
> done
|
26
30
|
> fi
|
27
31
|
>
|
32
|
+
> if ((${#env_var_names[@]})); then
|
33
|
+
> readarray -t sorted_names < <(printf '%s\n' "${env_var_names[@]}" | sort)
|
34
|
+
> echo
|
35
|
+
> echo "environment variables:"
|
36
|
+
> for k in "${sorted_names[@]}"; do
|
37
|
+
> echo "- \$$k = ${!k:-}"
|
38
|
+
> done
|
39
|
+
> fi
|
28
40
|
> }
|
29
41
|
>
|
@@ -3,6 +3,10 @@
|
|
3
3
|
> printf " %s\n" "{{ usage_string(extended: true).color(:environment_variable) }}"
|
4
4
|
> printf "{{ help.wrap(76).indent(4).sanitize_for_print }}\n"
|
5
5
|
|
6
|
+
if allowed
|
7
|
+
> printf " {{ strings[:allowed] % { values: allowed.join(', ') } }}\n"
|
8
|
+
end
|
9
|
+
|
6
10
|
if default
|
7
11
|
> printf " {{ strings[:default] % { value: default } }}\n"
|
8
12
|
end
|
@@ -4,11 +4,15 @@
|
|
4
4
|
> printf "{{ help.wrap(76).indent(4).sanitize_for_print }}\n"
|
5
5
|
|
6
6
|
if allowed
|
7
|
-
> printf " {{ strings[:allowed] % { values: allowed.join(', ') } }}\n"
|
7
|
+
> printf " {{ strings[:allowed] % { values: allowed.join(', ') } }}\n"
|
8
8
|
end
|
9
9
|
|
10
10
|
if default
|
11
|
-
|
11
|
+
if default.is_a? Array
|
12
|
+
> printf " {{ strings[:default] % { value: default.join(', ') } }}\n"
|
13
|
+
else
|
14
|
+
> printf " {{ strings[:default] % { value: default } }}\n"
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
18
|
> echo
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bashly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|