bashly 0.7.1 → 0.7.2

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: 53a5744ae1746cdd47de191ea91539ab7336aca894f583384ef0b170c03a746e
4
- data.tar.gz: 0e1e9bc417d3947bcce84c3c6f44df87521dfeeae2329cc736a53816cb66cba3
3
+ metadata.gz: f0f901e6eab10987e6daf0042b18e097b172f3d54babc286b9fb2f5e83452612
4
+ data.tar.gz: 4dc2043674ce9c5d1c3be9bfd8ec72f2cf0f18ac121b909e939dc9dd4ca3ea79
5
5
  SHA512:
6
- metadata.gz: 72154aafdc3c3787b4d23a2935192a92c21b94b830d7fb01c22057ed839d30120d8a31a8962b7b075110551d034b2c971b92010e55c88a17d4e9041ecb309ad7
7
- data.tar.gz: a02638101b685d5e9de575fe4537991c558c462dc030355b5e8ab6ffe4f32b8018c510afb516f51c02d4412a20c21a3703b5dc5872a0f377baa343345f045605
6
+ metadata.gz: f00b5c1afcb6349e7fdcc3e60adc23d2d6aa3d22a31b6375c3a2129adcb4434b9e2885449fdd8ede13dca7d56b0c1b6387681b6428db6028da0208cea82fe0a2
7
+ data.tar.gz: 5350aa76e39d2cee1d3ef2eb722e22f10e3d28772917d6b66cd5d11b0fb331a45e6fa2dd006f1096468b6189735ccffbf2650c27cb8a6a8d70b92c9c63803625
@@ -0,0 +1,68 @@
1
+ module Bashly
2
+ # This is a `Command` concern responsible for providing additional scopes.
3
+ module CommandScopes
4
+ # Returns only the names of the Commands
5
+ def command_names
6
+ commands.map &:name
7
+ end
8
+
9
+ # Returns a flat array containing all the commands in this tree.
10
+ # This includes self + children + grandchildres + ...
11
+ def deep_commands
12
+ result = []
13
+ commands.each do |command|
14
+ result << command
15
+ if command.commands.any?
16
+ result += command.deep_commands
17
+ end
18
+ end
19
+ result
20
+ end
21
+
22
+ # If any of this command's subcommands has the default option set to
23
+ # true, this default command will be returned, nil otherwise.
24
+ def default_command
25
+ commands.find { |c| c.default }
26
+ end
27
+
28
+ # Returns an array of all the default Args
29
+ def default_args
30
+ args.select &:default
31
+ end
32
+
33
+ # Returns an array of all the default Environment Variables
34
+ def default_environment_variables
35
+ environment_variables.select &:default
36
+ end
37
+
38
+ # Returns an array of all the default Flags
39
+ def default_flags
40
+ flags.select &:default
41
+ end
42
+
43
+ # Returns an array of all the required Arguments
44
+ def required_args
45
+ args.select &:required
46
+ end
47
+
48
+ # Returns an array of all the required EnvironmentVariables
49
+ def required_environment_variables
50
+ environment_variables.select &:required
51
+ end
52
+
53
+ # Returns an array of all the required Flags
54
+ def required_flags
55
+ flags.select &:required
56
+ end
57
+
58
+ # Returns an array of all the args with a whitelist
59
+ def whitelisted_args
60
+ args.select &:allowed
61
+ end
62
+
63
+ # Returns an array of all the flags with a whitelist arg
64
+ def whitelisted_flags
65
+ flags.select &:allowed
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,49 @@
1
+ module Bashly
2
+ module Script
3
+ class CatchAll
4
+ class << self
5
+ def from_config(config)
6
+ options = case config
7
+ when nil
8
+ { enabled: false }
9
+ when String
10
+ { label: config }
11
+ when Hash
12
+ { label: config['label'], help: config['help'], required: config['required'] }
13
+ else
14
+ {}
15
+ end
16
+
17
+ new **options
18
+ end
19
+ end
20
+
21
+ def initialize(label: nil, help: nil, required: false, enabled: true)
22
+ @label, @help, @required, @enabled = label, help, required, enabled
23
+ end
24
+
25
+ def enabled?
26
+ @enabled
27
+ end
28
+
29
+ def label
30
+ enabled? ? "#{@label&.upcase}..." : nil
31
+ end
32
+
33
+ def help
34
+ enabled? ? @help : nil
35
+ end
36
+
37
+ def required?
38
+ @required
39
+ end
40
+
41
+ def usage_string
42
+ return nil unless enabled?
43
+ required? ? label : "[#{label}]"
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+
@@ -2,6 +2,7 @@ module Bashly
2
2
  module Script
3
3
  class Command < Base
4
4
  include Completions
5
+ include CommandScopes
5
6
 
6
7
  # Returns the name to be used as an action.
7
8
  # - If it is the root command, the action is "root"
@@ -30,41 +31,8 @@ module Bashly
30
31
  help ? "#{full_name} - #{summary}" : full_name
31
32
  end
32
33
 
33
- # Returns a label for the catch_all directive
34
- def catch_all_label
35
- case catch_all
36
- when nil then nil
37
- when String then "#{catch_all.upcase}..."
38
- when Hash then "#{catch_all['label'].upcase}..."
39
- else "..."
40
- end
41
- end
42
-
43
- # Returns a user defined help string for the catch_all directive
44
- def catch_all_help
45
- return nil unless catch_all
46
-
47
- if catch_all.is_a?(Hash) and catch_all['help'].is_a?(String)
48
- catch_all['help']
49
- else
50
- nil
51
- end
52
- end
53
-
54
- # Returns true if catch_all is required
55
- def catch_all_required?
56
- catch_all.is_a?(Hash) and catch_all['required']
57
- end
58
-
59
- # Returns a string suitable for catch_all Usage pattern
60
- def catch_all_usage
61
- return nil unless catch_all
62
- catch_all_required? ? catch_all_label : "[#{catch_all_label}]"
63
- end
64
-
65
- # Returns only the names of the Commands
66
- def command_names
67
- commands.map &:name
34
+ def catch_all
35
+ @catch_all ||= CatchAll.from_config options['catch_all']
68
36
  end
69
37
 
70
38
  # Returns an array of the Commands
@@ -76,40 +44,6 @@ module Bashly
76
44
  end
77
45
  end
78
46
 
79
- # Returns a flat array containing all the commands in this tree.
80
- # This includes self + children + grandchildres + ...
81
- def deep_commands
82
- result = []
83
- commands.each do |command|
84
- result << command
85
- if command.commands.any?
86
- result += command.deep_commands
87
- end
88
- end
89
- result
90
- end
91
-
92
- # Returns an array of all the default Args
93
- def default_args
94
- args.select &:default
95
- end
96
-
97
- # If any of this command's subcommands has the default option set to
98
- # true, this default command will be returned, nil otherwise.
99
- def default_command
100
- commands.find { |c| c.default }
101
- end
102
-
103
- # Returns an array of all the default Environment Variables
104
- def default_environment_variables
105
- environment_variables.select &:default
106
- end
107
-
108
- # Returns an array of all the default Flags
109
- def default_flags
110
- flags.select &:default
111
- end
112
-
113
47
  # Returns an array of EnvironmentVariables
114
48
  def environment_variables
115
49
  return [] unless options["environment_variables"]
@@ -165,21 +99,6 @@ module Bashly
165
99
  options['parents'] || []
166
100
  end
167
101
 
168
- # Returns an array of all the required Arguments
169
- def required_args
170
- args.select &:required
171
- end
172
-
173
- # Returns an array of all the required EnvironmentVariables
174
- def required_environment_variables
175
- environment_variables.select &:required
176
- end
177
-
178
- # Returns an array of all the required Flags
179
- def required_flags
180
- flags.select &:required
181
- end
182
-
183
102
  # Returns trus if this is the root command (no parents)
184
103
  def root_command?
185
104
  parents.empty?
@@ -198,7 +117,7 @@ module Bashly
198
117
  result << arg.usage_string
199
118
  end
200
119
  result << "[options]" unless flags.empty?
201
- result << catch_all_usage if catch_all
120
+ result << catch_all.usage_string if catch_all.enabled?
202
121
  result.join " "
203
122
  end
204
123
 
@@ -215,16 +134,6 @@ module Bashly
215
134
  Bashly::ConfigValidator.new(options).validate
216
135
  end
217
136
 
218
- # Returns an array of all the args with a whitelist
219
- def whitelisted_args
220
- args.select &:allowed
221
- end
222
-
223
- # Returns an array of all the flags with a whitelist arg
224
- def whitelisted_flags
225
- flags.select &:allowed
226
- end
227
-
228
137
  end
229
138
  end
230
139
  end
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  # :command.catch_all_filter
2
- % if catch_all_required?
2
+ % if catch_all.required?
3
3
  if [[ ${#other_args[@]} -eq 0 ]]; then
4
- printf "<%= strings[:missing_required_argument] % { arg: catch_all_label, usage: usage_string } %>\n"
4
+ printf "<%= strings[:missing_required_argument] % { arg: catch_all.label, usage: usage_string } %>\n"
5
5
  exit 1
6
6
  fi
7
7
  % end
@@ -9,7 +9,7 @@
9
9
  % condition = "elif"
10
10
  % end
11
11
  else
12
- % if catch_all
12
+ % if catch_all.enabled?
13
13
  other_args+=("$1")
14
14
  shift
15
15
  % else
@@ -17,7 +17,7 @@ else
17
17
  exit 1
18
18
  % end
19
19
  fi
20
- % elsif catch_all
20
+ % elsif catch_all.enabled?
21
21
  other_args+=("$1")
22
22
  shift
23
23
  % else
@@ -7,8 +7,8 @@ while [[ $# -gt 0 ]]; do
7
7
 
8
8
  % end
9
9
 
10
- -* )
11
- % if catch_all
10
+ -?* )
11
+ % if catch_all.enabled?
12
12
  other_args+=("$1")
13
13
  shift
14
14
  ;;
@@ -37,7 +37,7 @@
37
37
  printf "<%= strings[:options] %>\n"
38
38
  <%= render(:usage_fixed_flags).indent 4 %>
39
39
  <%= render(:usage_flags).indent 4 if flags.any? %>
40
- <%= render(:usage_args).indent 4 if args.any? or catch_all_help %>
40
+ <%= render(:usage_args).indent 4 if args.any? or catch_all.help %>
41
41
  <%= render(:usage_environment_variables).indent 4 if environment_variables.any? %>
42
42
  <%= render(:usage_examples).indent 4 if examples %>
43
43
  <%= render(:footer).indent 4 if footer %>
@@ -6,9 +6,9 @@ printf "<%= strings[:arguments] %>\n"
6
6
  <%= arg.render(:usage) %>
7
7
  % end
8
8
  % end
9
- % if catch_all_help
9
+ % if catch_all.help
10
10
 
11
- echo " <%= catch_all_label %>"
12
- printf "<%= catch_all_help.wrap(76).indent(4).sanitize_for_print %>\n"
11
+ echo " <%= catch_all.label %>"
12
+ printf "<%= catch_all.help.wrap(76).indent(4).sanitize_for_print %>\n"
13
13
  echo
14
14
  % 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.7.1
4
+ version: 0.7.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-17 00:00:00.000000000 Z
11
+ date: 2022-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.2'
33
+ version: '0.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.2'
40
+ version: '0.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mister_bin
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -84,6 +84,7 @@ files:
84
84
  - lib/bashly/commands/preview.rb
85
85
  - lib/bashly/commands/validate.rb
86
86
  - lib/bashly/concerns/asset_helper.rb
87
+ - lib/bashly/concerns/command_scopes.rb
87
88
  - lib/bashly/concerns/completions.rb
88
89
  - lib/bashly/concerns/renderable.rb
89
90
  - lib/bashly/config.rb
@@ -103,6 +104,7 @@ files:
103
104
  - lib/bashly/refinements/compose_refinements.rb
104
105
  - lib/bashly/script/argument.rb
105
106
  - lib/bashly/script/base.rb
107
+ - lib/bashly/script/catch_all.rb
106
108
  - lib/bashly/script/command.rb
107
109
  - lib/bashly/script/environment_variable.rb
108
110
  - lib/bashly/script/flag.rb
@@ -186,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
188
  - !ruby/object:Gem::Version
187
189
  version: '0'
188
190
  requirements: []
189
- rubygems_version: 3.2.25
191
+ rubygems_version: 3.2.15
190
192
  signing_key:
191
193
  specification_version: 4
192
194
  summary: Bash Command Line Tool Generator