bashly 0.9.3 → 0.9.4

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: 310bcfcf9a37601cdf37bd37f81c96fc8e33e4e38e601a4d496a2b8fed20e319
4
- data.tar.gz: 72c4644b4051c9a290192c4d497bdcb80c8bdc5d473fe3c7bb01c40209f62a3d
3
+ metadata.gz: 810dfb8f0b25029420a1479aa38d682a79787716112d9b5f9c816533fc3e97ea
4
+ data.tar.gz: c6782bd0bf01a475b137487dcdec634645484c877386b1ccaaa8432d53831595
5
5
  SHA512:
6
- metadata.gz: 8b655051b58edb3182e022405484e006ef1ac6a7a0815fe6be77f38cbe57a5f9bf90adfa45be713719d718221451f9ab88087e4253fb7356651ff03f7ddc5b61
7
- data.tar.gz: 992d1f15fdb7649375b2c1f8f09054b73dc7aef92c7e980995b7fd4c28671b42c9635078617ff10bba81a49836852b53151ef5559b53a55cf7070197a5937a01
6
+ metadata.gz: 3c6cb7413b619b50cd76ecfa66d704623780f05f3316e1e9bcb9e7a3c02a4a3b9a9215759e928e32e4d6492993fb5b5cbcb6ba0379bd0fe638f6ab1182b791a4
7
+ data.tar.gz: e83491e2a1ab364701351a74bbef05377bbe479521fe907b8f9b1dc3fa567be4f5b53f87c4f4d4dd4313e9fff16ab84e07dd5cbfae5ed7ff0f4c2d44b98d69bd
@@ -69,7 +69,7 @@ module Bashly
69
69
  result = raw_data.select { |k, _v| k.include? args['SEARCH'] }
70
70
  return result if result.any?
71
71
 
72
- raise Error, "No match"
72
+ raise Error, 'No match'
73
73
  end
74
74
 
75
75
  def raw_data
@@ -1,3 +1,5 @@
1
+ require 'lp'
2
+
1
3
  module Bashly
2
4
  module Commands
3
5
  class Validate < Base
@@ -37,4 +37,12 @@ class String
37
37
  "\t" * (::Regexp.last_match(1).size / tabstop)
38
38
  end
39
39
  end
40
+
41
+ def color(marker)
42
+ color = Bashly::Settings.usage_colors[marker.to_s]
43
+ return self unless color
44
+
45
+ text, spaces = match(/(.*?)(\s*)$/).captures
46
+ %[$(#{color} "#{text}")#{spaces}]
47
+ end
40
48
  end
@@ -4,7 +4,7 @@ module Bashly
4
4
  include AssetHelper
5
5
 
6
6
  attr_writer :compact_short_flags, :lib_dir, :partials_extension,
7
- :source_dir, :strict, :tab_indent, :target_dir
7
+ :source_dir, :strict, :tab_indent, :target_dir, :usage_colors
8
8
 
9
9
  def compact_short_flags
10
10
  @compact_short_flags ||= get :compact_short_flags
@@ -50,6 +50,10 @@ module Bashly
50
50
  @target_dir ||= get :target_dir
51
51
  end
52
52
 
53
+ def usage_colors
54
+ @usage_colors ||= get :usage_colors
55
+ end
56
+
53
57
  private
54
58
 
55
59
  def get(key)
@@ -33,3 +33,15 @@ env: development
33
33
 
34
34
  # The extension to use when reading/writing partial script snippets.
35
35
  partials_extension: sh
36
+
37
+ # Display various usage elements in color by providing the name of the color
38
+ # function. The value for each property is a name of a function that is
39
+ # available in your script, for example: `green` or `bold`.
40
+ # You can run `bashly add colors` to add a standard colors library.
41
+ # This option cannot be set via environment variables.
42
+ usage_colors:
43
+ caption: ~
44
+ command: ~
45
+ arg: ~
46
+ flag: ~
47
+ environment_variable: ~
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = '0.9.3'
2
+ VERSION = '0.9.4'
3
3
  end
@@ -1,6 +1,6 @@
1
1
  = view_marker
2
2
 
3
- > echo " {{ label }}"
3
+ > printf " %s\n" "{{ label.color(:arg) }}"
4
4
  > printf "{{ help.wrap(76).indent(4).sanitize_for_print }}\n"
5
5
 
6
6
  if allowed
@@ -1,7 +1,7 @@
1
1
  = view_marker
2
2
 
3
3
  > if [[ -n $long_usage ]]; then
4
- > printf "{{ strings[:options] }}\n"
4
+ > printf "%s\n" "{{ strings[:options].color(:caption) }}"
5
5
  >
6
6
  = render(:usage_fixed_flags).indent 2
7
7
  = render(:usage_flags).indent 2 if flags.any?
@@ -25,7 +25,7 @@ if alt&.any?
25
25
  end
26
26
 
27
27
  >
28
- > printf "{{ strings[:usage] }}\n"
28
+ > printf "%s\n" "{{ strings[:usage].color(:caption) }}"
29
29
  > printf " {{ usage_string }}\n"
30
30
 
31
31
  if commands.any?
@@ -1,6 +1,6 @@
1
1
  = view_marker
2
2
 
3
- > printf "{{ strings[:arguments] }}\n"
3
+ > printf "%s\n" "{{ strings[:arguments].color(:caption) }}"
4
4
 
5
5
  if args.any?
6
6
  >
@@ -3,13 +3,13 @@
3
3
  maxlen = command_help_data.values.map(&:keys).flatten.map(&:size).max
4
4
 
5
5
  command_help_data.each do |group, commands|
6
- > printf "{{ group }}\n"
6
+ > printf "%s\n" "{{ group.color(:caption) }}"
7
7
 
8
8
  commands.each do |command, info|
9
9
  if info[:help_only]
10
- > [[ -n $long_usage ]] && echo " {{ command.ljust maxlen }} {{ info[:summary] }}"
10
+ > [[ -n $long_usage ]] && printf " %s {{ info[:summary] }}\n" "{{ command.ljust(maxlen).color(:command) }}"
11
11
  else
12
- > echo " {{ command.ljust maxlen }} {{ info[:summary] }}"
12
+ > printf " %s {{ info[:summary] }}\n" "{{ command.ljust(maxlen).color(:command) }}"
13
13
  end
14
14
  end
15
15
 
@@ -1,6 +1,6 @@
1
1
  = view_marker
2
2
 
3
- > printf "{{ strings[:environment_variables] }}\n"
3
+ > printf "%s\n" "{{ strings[:environment_variables].color(:caption) }}"
4
4
  >
5
5
 
6
6
  environment_variables.reject(&:private).each do |env_var|
@@ -1,6 +1,6 @@
1
1
  = view_marker
2
2
 
3
- > printf "{{ strings[:examples] }}\n"
3
+ > printf "%s\n" "{{ strings[:examples].color(:caption) }}"
4
4
 
5
5
  examples.each do |example|
6
6
  > printf "{{ example.wrap(78).indent(2).sanitize_for_print }}\n"
@@ -1,11 +1,20 @@
1
1
  = view_marker
2
2
 
3
- = short_flag_exist?("-h") ? 'echo " --help"' : 'echo " --help, -h"'
3
+ if short_flag_exist?("-h")
4
+ > printf " %s\n" "{{ '--help'.color(:flag) }}"
5
+ else
6
+ > printf " %s\n" "{{ '--help, -h'.color(:flag) }}"
7
+ end
8
+
4
9
  > printf " {{ strings[:help_flag_text] }}\n"
5
10
  > echo
6
11
 
7
12
  if root_command?
8
- = short_flag_exist?("-v") ? 'echo " --version"' : 'echo " --version, -v"'
13
+ if short_flag_exist?("-v")
14
+ > printf " %s\n" "{{ '--version'.color(:flag) }}"
15
+ else
16
+ > printf " %s\n" "{{ '--version, -v'.color(:flag) }}"
17
+ end
9
18
  > printf " {{ strings[:version_flag_text] }}\n"
10
19
  > echo
11
20
  end
@@ -1,6 +1,6 @@
1
1
  = view_marker
2
2
 
3
- > echo " {{ usage_string extended: true }}"
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
6
  if default
@@ -1,6 +1,6 @@
1
1
  = view_marker
2
2
 
3
- > echo " {{ usage_string extended: true }}"
3
+ > printf " %s\n" "{{ usage_string(extended: true).color(:flag) }}"
4
4
  > printf "{{ help.wrap(76).indent(4).sanitize_for_print }}\n"
5
5
 
6
6
  if allowed
data/lib/bashly.rb CHANGED
@@ -6,7 +6,6 @@ if ENV['BYEBUG']
6
6
  end
7
7
 
8
8
  requires 'bashly/concerns'
9
-
10
9
  requires 'bashly/extensions'
11
10
  requires 'bashly/settings'
12
11
  requires 'bashly/exceptions'
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.9.3
4
+ version: 0.9.4
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: 2022-12-24 00:00:00.000000000 Z
11
+ date: 2022-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: completely
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0.2'
103
+ version: '1.0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0.2'
110
+ version: '1.0'
111
111
  description: Generate bash command line tools using YAML configuration
112
112
  email: db@dannyben.com
113
113
  executables: