bashly 1.1.10 → 1.2.1
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/shell.rb +1 -1
- data/lib/bashly/config_validator.rb +4 -0
- data/lib/bashly/extensions/array.rb +6 -0
- data/lib/bashly/libraries/settings/settings.yml +4 -0
- data/lib/bashly/libraries/strings/strings.yml +2 -0
- data/lib/bashly/script/command.rb +9 -3
- data/lib/bashly/settings.rb +5 -0
- data/lib/bashly/version.rb +1 -1
- data/lib/bashly/views/argument/validations.gtx +1 -0
- data/lib/bashly/views/command/command_filter.gtx +3 -1
- data/lib/bashly/views/command/examples_on_error.gtx +8 -0
- data/lib/bashly/views/command/long_usage.gtx +2 -1
- data/lib/bashly/views/command/normalize_input_function.gtx +5 -1
- data/lib/bashly/views/command/required_args_filter.gtx +2 -2
- data/lib/bashly/views/command/usage.gtx +9 -14
- data/lib/bashly/views/command/whitelist_filter.gtx +2 -0
- data/lib/bashly/views/flag/validations.gtx +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36c0868dbf2a0e4d5d2fecdc5854aac4e1bea8f7953a07712ccc985289c89b57
|
4
|
+
data.tar.gz: 63df3d720e1b36ce7ab658224fde796fb9460c92c7946bd867204c0e0caea304
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39e367d86e8bf21ae076c35887157234e7d39d003f17a596aa4711a02a87c6b3856ac27b0f1c73c30837b2589358e479c069dba4cff657431fdca98f44116718
|
7
|
+
data.tar.gz: eceaabeafea2e93a9cf7c9d7c2f999a2303c0d9172ddd7799bb0d1f9eafe62166ee9512d8688ad9cc6547dd28e20b7c8925ca489cb2639fd3cd2456517461e7a
|
@@ -231,6 +231,10 @@ module Bashly
|
|
231
231
|
assert value['args'].last['repeatable'],
|
232
232
|
"#{key}.args cannot contain a repeatable arg unless it is the last one"
|
233
233
|
end
|
234
|
+
|
235
|
+
required_order = value['args'].map { |x| x['required'] ? true : false }
|
236
|
+
refute required_order.include_sequence?(false, true),
|
237
|
+
"#{key}.args cannot contain required arg after optional arg"
|
234
238
|
end
|
235
239
|
|
236
240
|
if value['expose']
|
@@ -55,6 +55,10 @@ env: development
|
|
55
55
|
# The extension to use when reading/writing partial script snippets
|
56
56
|
partials_extension: sh
|
57
57
|
|
58
|
+
# Show command examples (if any) whenever the user does not provide the
|
59
|
+
# required arguments
|
60
|
+
show_examples_on_error: false
|
61
|
+
|
58
62
|
# Display various usage elements in color by providing the name of the color
|
59
63
|
# function. The value for each property is a name of a function that is
|
60
64
|
# available in your script, for example: `green` or `bold`.
|
@@ -4,6 +4,7 @@
|
|
4
4
|
# Usage captions
|
5
5
|
usage: "Usage:"
|
6
6
|
options: "Options:"
|
7
|
+
global_options: "Global Options:"
|
7
8
|
arguments: "Arguments:"
|
8
9
|
commands: "Commands:"
|
9
10
|
examples: "Examples:"
|
@@ -32,6 +33,7 @@ missing_required_argument: "missing required argument: %{arg}\\nusage: %{usage}"
|
|
32
33
|
missing_required_flag: "missing required flag: %{usage}"
|
33
34
|
missing_required_environment_variable: "missing required environment variable: %{var}"
|
34
35
|
missing_dependency: "missing dependency: %{dependency}"
|
36
|
+
examples_caption_on_error: 'examples:'
|
35
37
|
disallowed_flag: "%{name} must be one of: %{allowed}"
|
36
38
|
disallowed_argument: "%{name} must be one of: %{allowed}"
|
37
39
|
disallowed_environment_variable: "%{name} environment variable must be one of: %{allowed}"
|
@@ -307,11 +307,12 @@ module Bashly
|
|
307
307
|
|
308
308
|
# Returns a constructed string suitable for Usage pattern
|
309
309
|
def usage_string
|
310
|
-
result = [
|
310
|
+
result = [base_usage_pattern]
|
311
|
+
command_string = default_command&.default == 'force' ? '[COMMAND]' : 'COMMAND'
|
311
312
|
|
312
313
|
result.push case mode
|
313
|
-
when :global_flags then ['[OPTIONS]',
|
314
|
-
when :commands then [
|
314
|
+
when :global_flags then ['[OPTIONS]', command_string]
|
315
|
+
when :commands then [command_string]
|
315
316
|
when :args_and_flags then usage_string_args + ['[OPTIONS]']
|
316
317
|
when :args then usage_string_args
|
317
318
|
when :flags then ['[OPTIONS]']
|
@@ -326,6 +327,11 @@ module Bashly
|
|
326
327
|
args.map(&:usage_string)
|
327
328
|
end
|
328
329
|
|
330
|
+
def base_usage_pattern
|
331
|
+
usage_pattern = default ? "[#{name}]" : name
|
332
|
+
parents.any? ? (parents + [usage_pattern]).join(' ') : usage_pattern
|
333
|
+
end
|
334
|
+
|
329
335
|
# Returns an array of files to include as is inside the script
|
330
336
|
# This is meant to provide the user with the ability to add custom
|
331
337
|
# functions
|
data/lib/bashly/settings.rb
CHANGED
@@ -10,6 +10,7 @@ module Bashly
|
|
10
10
|
:config_path,
|
11
11
|
:lib_dir,
|
12
12
|
:partials_extension,
|
13
|
+
:show_examples_on_error,
|
13
14
|
:source_dir,
|
14
15
|
:strict,
|
15
16
|
:tab_indent,
|
@@ -57,6 +58,10 @@ module Bashly
|
|
57
58
|
env == :production
|
58
59
|
end
|
59
60
|
|
61
|
+
def show_examples_on_error
|
62
|
+
@show_examples_on_error ||= get :show_examples_on_error
|
63
|
+
end
|
64
|
+
|
60
65
|
def source_dir
|
61
66
|
@source_dir ||= get :source_dir
|
62
67
|
end
|
data/lib/bashly/version.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
= view_marker
|
2
2
|
|
3
3
|
> if [[ -n $long_usage ]]; then
|
4
|
-
|
4
|
+
options_caption = public_commands.any? && public_flags.any? ? strings[:global_options] : strings[:options]
|
5
|
+
> printf "%s\n" "{{ options_caption.color(:caption) }}"
|
5
6
|
>
|
6
7
|
= render(:usage_flags).indent 2 if public_flags.any?
|
7
8
|
= render(:usage_fixed_flags).indent 2
|
@@ -4,10 +4,10 @@ if required_args.any?
|
|
4
4
|
required_args.each do |arg|
|
5
5
|
> if [[ -z ${args['{{ arg.name }}']+x} ]]; then
|
6
6
|
> printf "{{ strings[:missing_required_argument] % { arg: arg.name.upcase, usage: usage_string } }}\n" >&2
|
7
|
+
= render(:examples_on_error).indent 2
|
7
8
|
> exit 1
|
8
9
|
> fi
|
9
10
|
end
|
10
11
|
|
11
12
|
>
|
12
|
-
|
13
|
-
end
|
13
|
+
end
|
@@ -1,24 +1,17 @@
|
|
1
1
|
= view_marker
|
2
2
|
|
3
3
|
> {{ function_name }}_usage() {
|
4
|
-
> if [[ -n $long_usage ]]; then
|
5
|
-
|
6
4
|
if summary == help
|
7
|
-
>
|
8
|
-
> echo
|
5
|
+
> printf "{{ caption_string.sanitize_for_print }}\n\n"
|
9
6
|
else
|
10
|
-
>
|
11
|
-
>
|
12
|
-
> printf "{{ help.wrap(78).indent(2).sanitize_for_print }}\n"
|
13
|
-
>
|
7
|
+
> if [[ -n $long_usage ]]; then
|
8
|
+
> printf "{{ full_name }}\n\n"
|
9
|
+
> printf "{{ help.wrap(78).indent(2).sanitize_for_print }}\n\n"
|
10
|
+
> else
|
11
|
+
> printf "{{ caption_string.sanitize_for_print }}\n\n"
|
12
|
+
> fi
|
14
13
|
end
|
15
14
|
|
16
|
-
> else
|
17
|
-
> printf "{{ caption_string.sanitize_for_print }}\n"
|
18
|
-
> echo
|
19
|
-
> fi
|
20
|
-
>
|
21
|
-
|
22
15
|
if alt&.any?
|
23
16
|
> printf "{{ strings[:command_alias] % { alias: alt.join(', ') } }}\n"
|
24
17
|
> echo
|
@@ -48,3 +41,5 @@ end
|
|
48
41
|
commands.each do |command|
|
49
42
|
= command.render 'usage'
|
50
43
|
end
|
44
|
+
|
45
|
+
|
@@ -3,6 +3,7 @@ if whitelisted_args.any? or whitelisted_flags.any?
|
|
3
3
|
|
4
4
|
whitelisted_args.each do |arg|
|
5
5
|
if arg.repeatable
|
6
|
+
> input_array=''
|
6
7
|
> eval "input_array=(${args[{{ arg.name }}]})"
|
7
8
|
> for i in "${input_array[@]}"; do
|
8
9
|
> if [[ ! $i =~ ^({{ arg.allowed.join '|' }})$ ]]; then
|
@@ -22,6 +23,7 @@ if whitelisted_args.any? or whitelisted_flags.any?
|
|
22
23
|
|
23
24
|
whitelisted_flags.each do |flag|
|
24
25
|
if flag.repeatable
|
26
|
+
> input_array=''
|
25
27
|
> eval "input_array=(${args[{{ flag.name }}]})"
|
26
28
|
> for i in "${input_array[@]}"; do
|
27
29
|
> if [[ ! $i =~ ^({{ flag.allowed.join '|' }})$ ]]; then
|
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.2.1
|
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: 2024-
|
11
|
+
date: 2024-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -240,6 +240,7 @@ files:
|
|
240
240
|
- lib/bashly/views/command/dependencies_filter.gtx
|
241
241
|
- lib/bashly/views/command/environment_variables_default.gtx
|
242
242
|
- lib/bashly/views/command/environment_variables_filter.gtx
|
243
|
+
- lib/bashly/views/command/examples_on_error.gtx
|
243
244
|
- lib/bashly/views/command/fixed_flags_filter.gtx
|
244
245
|
- lib/bashly/views/command/footer.gtx
|
245
246
|
- lib/bashly/views/command/function.gtx
|
@@ -307,7 +308,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
307
308
|
- !ruby/object:Gem::Version
|
308
309
|
version: '0'
|
309
310
|
requirements: []
|
310
|
-
rubygems_version: 3.5.
|
311
|
+
rubygems_version: 3.5.14
|
311
312
|
signing_key:
|
312
313
|
specification_version: 4
|
313
314
|
summary: Bash Command Line Tool Generator
|