bashly 1.1.9 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57e204b6791653f135c34bdf18a2b882d180087bbec57044db09540e342d81f0
4
- data.tar.gz: ef1bc1015e325d227b3bc32d537a51fc369ea7833972f6f9a15e592d79ddc131
3
+ metadata.gz: 5000e81ecf047c31547832097355e0d1b5de630041ef2533a80ce70f146e8282
4
+ data.tar.gz: 9c03b8ef9215a317ebfd75333304065c271e77296a55753de65e612f9d1a8432
5
5
  SHA512:
6
- metadata.gz: 4947a104aa165d0e216a53a07908b72c290ff8e905e96acde044025bccefbab783ed5c87f3c217b674bdfb57db21c5d149827a9d8383065fef78eaac701826c0
7
- data.tar.gz: 99eb5313b587980c540f22596cc8e99794cf7ed24cb0f62e06c4179a64399e80099c6cbc7d2803fe96827cdbf5734bbb9fc7364533979da45cd44973d0511748
6
+ metadata.gz: c6dc6b49075f6e250aec3204f6b9ff2bd6e4236da1bcc5229691565dcc8a4ff4c1d1c06a139c092eae33c61123753cdb542583a69596caf299f87c6ccf3d4f07
7
+ data.tar.gz: ab9d9fc13a779bfd4d71adbae49e66961c697a46e5cb386875dac1d9e1b021828a2821332f2687d16b87b3fb820cdc006b61d86e7425dd6fdb37ac7aceb12b33
@@ -1,6 +1,6 @@
1
1
  class String
2
2
  def sanitize_for_print
3
- gsub("\n", '\\n').gsub('"', '\"').gsub('`', '\\\\`')
3
+ gsub("\n", '\\n').gsub('"', '\"').gsub('`', '\\\\`').gsub('%', '%%')
4
4
  end
5
5
 
6
6
  def for_markdown
@@ -42,6 +42,11 @@ tab_indent: false
42
42
  # `-abc` as if it is `-a -b -c`.
43
43
  compact_short_flags: true
44
44
 
45
+ # When true, the generated script will consider any argument in the form of
46
+ # `--flag=value` and `-f=value` as if it is `--flag value` and `-f value`
47
+ # respectively.
48
+ conjoined_flag_args: true
49
+
45
50
  # Set to 'production' or 'development':
46
51
  # env: production Generate a smaller script, without file markers
47
52
  # env: development Generate with file markers
@@ -50,6 +55,10 @@ env: development
50
55
  # The extension to use when reading/writing partial script snippets
51
56
  partials_extension: sh
52
57
 
58
+ # Show command examples (if any) whenever the user does not provide the
59
+ # required arguments
60
+ show_examples_on_error: false
61
+
53
62
  # Display various usage elements in color by providing the name of the color
54
63
  # function. The value for each property is a name of a function that is
55
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}"
@@ -29,7 +29,7 @@ module Bashly
29
29
  options['help'] ||= ''
30
30
  end
31
31
 
32
- def method_missing(method_name, *arguments, &block)
32
+ def method_missing(method_name, *arguments, &)
33
33
  key = method_name.to_s
34
34
  respond_to?(method_name) ? options[key] : super
35
35
  end
@@ -48,7 +48,7 @@ module Bashly
48
48
  def usage_string
49
49
  return nil unless enabled?
50
50
 
51
- required? ? label : "[#{label}]"
51
+ required? ? "[--] #{label}" : "[--] [#{label}]"
52
52
  end
53
53
  end
54
54
  end
@@ -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 = [full_name]
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]', 'COMMAND']
314
- when :commands then ['COMMAND']
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
@@ -6,9 +6,11 @@ module Bashly
6
6
  attr_writer(
7
7
  :commands_dir,
8
8
  :compact_short_flags,
9
+ :conjoined_flag_args,
9
10
  :config_path,
10
11
  :lib_dir,
11
12
  :partials_extension,
13
+ :show_examples_on_error,
12
14
  :source_dir,
13
15
  :strict,
14
16
  :tab_indent,
@@ -24,6 +26,10 @@ module Bashly
24
26
  @compact_short_flags ||= get :compact_short_flags
25
27
  end
26
28
 
29
+ def conjoined_flag_args
30
+ @conjoined_flag_args ||= get :conjoined_flag_args
31
+ end
32
+
27
33
  def config_path
28
34
  @config_path ||= get(:config_path) % { source_dir: source_dir }
29
35
  end
@@ -52,6 +58,10 @@ module Bashly
52
58
  env == :production
53
59
  end
54
60
 
61
+ def show_examples_on_error
62
+ @show_examples_on_error ||= get :show_examples_on_error
63
+ end
64
+
55
65
  def source_dir
56
66
  @source_dir ||= get :source_dir
57
67
  end
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = '1.1.9'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -0,0 +1,8 @@
1
+ if Settings.show_examples_on_error && examples
2
+ = view_marker
3
+
4
+ > printf "{{ strings[:examples_caption_on_error] }}\n" >&2
5
+ examples.each do |example|
6
+ > printf "{{ example.wrap(78).indent(2).sanitize_for_print }}\n" >&2
7
+ end
8
+ end
@@ -1,7 +1,8 @@
1
1
  = view_marker
2
2
 
3
3
  > if [[ -n $long_usage ]]; then
4
- > printf "%s\n" "{{ strings[:options].color(:caption) }}"
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
@@ -1,30 +1,7 @@
1
1
  = view_marker
2
2
 
3
- > normalize_input() {
4
- > local arg flags
5
- >
6
- > while [[ $# -gt 0 ]]; do
7
- > arg="$1"
8
- > if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then
9
- > input+=("${BASH_REMATCH[1]}")
10
- > input+=("${BASH_REMATCH[2]}")
11
- > elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then
12
- > input+=("${BASH_REMATCH[1]}")
13
- > input+=("${BASH_REMATCH[2]}")
14
-
15
- if Settings.compact_short_flags
16
- > elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then
17
- > flags="${BASH_REMATCH[1]}"
18
- > for ((i = 0; i < ${#flags}; i++)); do
19
- > input+=("-${flags:i:1}")
20
- > done
3
+ if Settings.compact_short_flags || Settings.conjoined_flag_args
4
+ = render :normalize_input_function
5
+ else
6
+ = render :normalize_input_simple
21
7
  end
22
-
23
- > else
24
- > input+=("$arg")
25
- > fi
26
- >
27
- > shift
28
- > done
29
- > }
30
- >
@@ -0,0 +1,39 @@
1
+ = view_marker
2
+
3
+ > normalize_input() {
4
+ > local arg flags passthru
5
+ > passthru=false
6
+ >
7
+ > while [[ $# -gt 0 ]]; do
8
+ > arg="$1"
9
+ > if [[ $passthru == true ]]; then
10
+ > input+=("$arg")
11
+
12
+ if Settings.conjoined_flag_args
13
+ > elif [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then
14
+ > input+=("${BASH_REMATCH[1]}")
15
+ > input+=("${BASH_REMATCH[2]}")
16
+ > elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then
17
+ > input+=("${BASH_REMATCH[1]}")
18
+ > input+=("${BASH_REMATCH[2]}")
19
+ end
20
+
21
+ if Settings.compact_short_flags
22
+ > elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then
23
+ > flags="${BASH_REMATCH[1]}"
24
+ > for ((i = 0; i < ${#flags}; i++)); do
25
+ > input+=("-${flags:i:1}")
26
+ > done
27
+ end
28
+
29
+ > elif [[ "$arg" == "--" ]]; then
30
+ > passthru=true
31
+ > input+=("$arg")
32
+ > else
33
+ > input+=("$arg")
34
+ > fi
35
+ >
36
+ > shift
37
+ > done
38
+ > }
39
+ >
@@ -0,0 +1,6 @@
1
+ = view_marker
2
+
3
+ > normalize_input() {
4
+ > input=("$@")
5
+ > }
6
+ >
@@ -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
- > printf "{{ caption_string.sanitize_for_print }}\n"
8
- > echo
5
+ > printf "{{ caption_string.sanitize_for_print }}\n\n"
9
6
  else
10
- > printf "{{ full_name }}\n"
11
- > echo
12
- > printf "{{ help.wrap(78).indent(2).sanitize_for_print }}\n"
13
- > echo
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
+
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.9
4
+ version: 1.2.0
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-03-20 00:00:00.000000000 Z
11
+ date: 2024-07-05 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
@@ -248,6 +249,8 @@ files:
248
249
  - lib/bashly/views/command/long_usage.gtx
249
250
  - lib/bashly/views/command/master_script.gtx
250
251
  - lib/bashly/views/command/normalize_input.gtx
252
+ - lib/bashly/views/command/normalize_input_function.gtx
253
+ - lib/bashly/views/command/normalize_input_simple.gtx
251
254
  - lib/bashly/views/command/parse_requirements.gtx
252
255
  - lib/bashly/views/command/parse_requirements_case.gtx
253
256
  - lib/bashly/views/command/parse_requirements_case_catch_all.gtx
@@ -298,14 +301,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
298
301
  requirements:
299
302
  - - ">="
300
303
  - !ruby/object:Gem::Version
301
- version: '3.0'
304
+ version: '3.1'
302
305
  required_rubygems_version: !ruby/object:Gem::Requirement
303
306
  requirements:
304
307
  - - ">="
305
308
  - !ruby/object:Gem::Version
306
309
  version: '0'
307
310
  requirements: []
308
- rubygems_version: 3.5.6
311
+ rubygems_version: 3.5.14
309
312
  signing_key:
310
313
  specification_version: 4
311
314
  summary: Bash Command Line Tool Generator