bashly 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/bashly/models/base.rb +2 -1
- data/lib/bashly/models/command.rb +10 -0
- data/lib/bashly/templates/strings.yml +3 -0
- data/lib/bashly/version.rb +1 -1
- data/lib/bashly/views/argument/usage.erb +3 -0
- data/lib/bashly/views/command/parse_requirements.erb +1 -0
- data/lib/bashly/views/command/run.erb +1 -6
- data/lib/bashly/views/command/whitelist_filter.erb +13 -0
- data/lib/bashly/views/flag/usage.erb +3 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d486637f9d7ec6604d0495aec9f2396f69153f8cd193c126d51bc7dbc329a62
|
4
|
+
data.tar.gz: 5c58b05ad9ccb84d432c42228b7594e678b033555e55ea275948d4e70be118c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02fd6e6c50c5d370dde3d50047b0b6d317454c3d48531222711c6341c6e93d263cafa6a7d541bb939ff44a36b6025c9c8411e8f3820157c41e476312f4c64781
|
7
|
+
data.tar.gz: 031ea1db4c68fb6b780f01862b216178804cdc44f2e86fc66bc11f2910fff6d03ed250d7a01dd1c566d74c8f002ae6e9441bb13292f3e74620db455c993029e2
|
data/README.md
CHANGED
@@ -223,6 +223,7 @@ bash function.
|
|
223
223
|
`help` | The message to display when using `--help`. Can have multiple lines.
|
224
224
|
`required` | Specify if this argument is required. Note that once you define an optional argument (without required: true) then you cannot define required arguments after it.
|
225
225
|
`default` | The value to use in case it is not provided by the user. Implies that this argument is optional.
|
226
|
+
`allowed` | Limit the allowed values by providing an array.
|
226
227
|
|
227
228
|
### Flag options
|
228
229
|
|
@@ -238,6 +239,7 @@ short form).
|
|
238
239
|
`arg` | If the flag requires an argument, specify its name here.
|
239
240
|
`required` | Specify if this flag is required.
|
240
241
|
`default` | The value to use in case it is not provided by the user. Implies that this flag is optional, and only makes sense when the flag has an argument.
|
242
|
+
`allowed` | For flags with an argument, you can limit the allowed values by providing an array.
|
241
243
|
|
242
244
|
#### Special handling for -v and -h
|
243
245
|
|
data/lib/bashly/models/base.rb
CHANGED
@@ -175,6 +175,16 @@ module Bashly
|
|
175
175
|
verify_commands if commands.any?
|
176
176
|
end
|
177
177
|
|
178
|
+
# Returns an array of all the args with a whitelist
|
179
|
+
def whitelisted_args
|
180
|
+
args.select &:allowed
|
181
|
+
end
|
182
|
+
|
183
|
+
# Returns an array of all the flags with a whitelist arg
|
184
|
+
def whitelisted_flags
|
185
|
+
flags.select &:allowed
|
186
|
+
end
|
187
|
+
|
178
188
|
private
|
179
189
|
|
180
190
|
def verify_commands
|
@@ -15,6 +15,7 @@ command_shortcut: "Shortcut: %{short}"
|
|
15
15
|
default_command_summary: "%{summary} (default)"
|
16
16
|
required: "(required)"
|
17
17
|
default: "Default: %{value}"
|
18
|
+
allowed: "Allowed: %{values}"
|
18
19
|
|
19
20
|
# Fixed flags help text
|
20
21
|
help_flag_text: Show this help
|
@@ -28,3 +29,5 @@ missing_required_argument: "missing required argument: %{arg}\\nusage: %{usage}"
|
|
28
29
|
missing_required_flag: "missing required flag: %{usage}"
|
29
30
|
missing_required_environment_variable: "missing required environment variable: %{var}"
|
30
31
|
missing_dependency: "missing dependency: %{dependency}"
|
32
|
+
disallowed_flag: "%{name} must be one of: %{allowed}"
|
33
|
+
disallowed_argument: "%{name} must be one of: %{allowed}"
|
data/lib/bashly/version.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# :argument.usage
|
2
2
|
echo " <%= name.upcase %>"
|
3
3
|
printf "<%= help.wrap(76).indent(4).sanitize_for_print %>\n"
|
4
|
+
<%- if allowed -%>
|
5
|
+
printf " <%= strings[:allowed] % { values: allowed.join(', ') } -%>\n"
|
6
|
+
<%- end -%>
|
4
7
|
<%- if default -%>
|
5
8
|
printf " <%= strings[:default] % { value: default } -%>\n"
|
6
9
|
<%- end -%>
|
@@ -12,6 +12,7 @@ parse_requirements() {
|
|
12
12
|
<%= render(:required_flags_filter).indent 2 %>
|
13
13
|
<%= render(:parse_requirements_while).indent 2 %>
|
14
14
|
<%= render(:default_assignments).indent 2 %>
|
15
|
+
<%= render(:whitelist_filter).indent 2 %>
|
15
16
|
}
|
16
17
|
|
17
18
|
<%- commands.each do |command| %>
|
@@ -14,12 +14,7 @@ run() {
|
|
14
14
|
fi
|
15
15
|
<% condition = "elif" %>
|
16
16
|
<%- end -%>
|
17
|
-
<%= condition %> [[ $
|
18
|
-
version_command
|
19
|
-
elif [[ ${args[--help]} ]]; then
|
20
|
-
long_usage=yes
|
21
|
-
<%= name %>_usage
|
22
|
-
elif [[ $action == "root" ]]; then
|
17
|
+
<%= condition %> [[ $action == "root" ]]; then
|
23
18
|
root_command
|
24
19
|
fi
|
25
20
|
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# :command.whitelist_filter
|
2
|
+
<%- whitelisted_args.each do |arg| -%>
|
3
|
+
if [[ ! ${args[<%= arg.name %>]} =~ ^(<%= arg.allowed.join '|' %>)$ ]]; then
|
4
|
+
printf "%s\n" "<%= strings[:disallowed_argument] % { name: arg.name, allowed: arg.allowed.join(', ') } %>"
|
5
|
+
exit 1
|
6
|
+
fi
|
7
|
+
<%- end -%>
|
8
|
+
<%- whitelisted_flags.each do |flag| -%>
|
9
|
+
if [[ ! ${args[<%= flag.name %>]} =~ ^(<%= flag.allowed.join '|' %>)$ ]]; then
|
10
|
+
printf "%s\n" "<%= strings[:disallowed_flag] % { name: flag.name, allowed: flag.allowed.join(', ') } %>"
|
11
|
+
exit 1
|
12
|
+
fi
|
13
|
+
<%- end -%>
|
@@ -1,6 +1,9 @@
|
|
1
1
|
# :flag.usage
|
2
2
|
echo " <%= usage_string extended: true %>"
|
3
3
|
printf "<%= help.wrap(76).indent(4).sanitize_for_print %>\n"
|
4
|
+
<%- if allowed -%>
|
5
|
+
printf " <%= strings[:allowed] % { values: allowed.join(', ') } -%>\n"
|
6
|
+
<%- end -%>
|
4
7
|
<%- if default -%>
|
5
8
|
printf " <%= strings[:default] % { value: default } -%>\n"
|
6
9
|
<%- end -%>
|
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: 0.4.
|
4
|
+
version: 0.4.2
|
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: 2021-
|
11
|
+
date: 2021-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- lib/bashly/views/command/usage_flags.erb
|
122
122
|
- lib/bashly/views/command/user_lib.erb
|
123
123
|
- lib/bashly/views/command/version_command.erb
|
124
|
+
- lib/bashly/views/command/whitelist_filter.erb
|
124
125
|
- lib/bashly/views/environment_variable/usage.erb
|
125
126
|
- lib/bashly/views/flag/case.erb
|
126
127
|
- lib/bashly/views/flag/usage.erb
|