bashly 0.7.1 → 0.7.5
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 +4 -4
- data/lib/bashly/commands/generate.rb +3 -5
- data/lib/bashly/concerns/command_scopes.rb +68 -0
- data/lib/bashly/config.rb +3 -1
- data/lib/bashly/config_validator.rb +8 -0
- data/lib/bashly/libraries/completions.rb +1 -1
- data/lib/bashly/script/base.rb +3 -2
- data/lib/bashly/script/catch_all.rb +49 -0
- data/lib/bashly/script/command.rb +5 -96
- data/lib/bashly/version.rb +1 -1
- data/lib/bashly/views/command/catch_all_filter.erb +2 -2
- data/lib/bashly/views/command/default_root_script.erb +1 -1
- data/lib/bashly/views/command/parse_requirements.erb +1 -0
- data/lib/bashly/views/command/parse_requirements_case.erb +2 -2
- data/lib/bashly/views/command/parse_requirements_while.erb +2 -2
- data/lib/bashly/views/command/root_command.erb +1 -1
- data/lib/bashly/views/command/usage.erb +1 -1
- data/lib/bashly/views/command/usage_args.erb +3 -3
- data/lib/bashly/views/command/user_filter.erb +11 -0
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 701ac68c31b0dc916b212886b694c8aef4994aabdd703cfffe5bd592a91d1989
|
4
|
+
data.tar.gz: c9968bd61faf7ffc1f52e9eefc65fa54a88ee09326238618809eb66e65a17fb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd50a1a52f24a5a7989266090827f21fa4265856d9319ab1eff288bab8e3bd2b0256efec8462387fe992f2adba175bbb50b2dd9b59e580e5b4a97f2aba9849dd
|
7
|
+
data.tar.gz: f40b18e9876e6297a1bcb8e14d9b364a88cb05f8db1fbaff31e3746f96961db581dbda6bd33a5a9147767c62afaab7caf7541fdde02167403d17ef4ec48933ff
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module Bashly
|
2
2
|
module Commands
|
3
3
|
class Generate < Base
|
4
|
-
using ComposeRefinements
|
5
|
-
|
6
4
|
help "Generate the bash script and required files"
|
7
5
|
|
8
6
|
usage "bashly generate [--force --quiet --upgrade --wrap FUNCTION]"
|
@@ -82,7 +80,7 @@ module Bashly
|
|
82
80
|
end
|
83
81
|
|
84
82
|
def create_root_command_file
|
85
|
-
create_file "#{Settings.source_dir}
|
83
|
+
create_file "#{Settings.source_dir}/#{command.filename}", command.render(:default_root_script)
|
86
84
|
end
|
87
85
|
|
88
86
|
def create_all_command_files
|
@@ -98,7 +96,7 @@ module Bashly
|
|
98
96
|
if File.exist? file and !args['--force']
|
99
97
|
quiet_say "!txtblu!skipped!txtrst! #{file} (exists)"
|
100
98
|
else
|
101
|
-
File.
|
99
|
+
File.deep_write file, content
|
102
100
|
quiet_say "!txtgrn!created!txtrst! #{file}"
|
103
101
|
end
|
104
102
|
end
|
@@ -118,7 +116,7 @@ module Bashly
|
|
118
116
|
end
|
119
117
|
|
120
118
|
def config
|
121
|
-
@config ||= Config.new
|
119
|
+
@config ||= Config.new "#{Settings.source_dir}/bashly.yml"
|
122
120
|
end
|
123
121
|
|
124
122
|
def command
|
@@ -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
|
data/lib/bashly/config.rb
CHANGED
@@ -4,11 +4,13 @@ module Bashly
|
|
4
4
|
# A convenience class to use either a hash or a filename as a configuration
|
5
5
|
# source
|
6
6
|
class Config
|
7
|
+
using ComposeRefinements
|
8
|
+
|
7
9
|
attr_reader :config
|
8
10
|
|
9
11
|
def self.new(config)
|
10
12
|
if config.is_a? String
|
11
|
-
YAML.load_file
|
13
|
+
YAML.load_file(config).compose
|
12
14
|
else
|
13
15
|
config
|
14
16
|
end
|
@@ -81,6 +81,8 @@ module Bashly
|
|
81
81
|
assert_boolean "#{key}.required", value['required']
|
82
82
|
|
83
83
|
assert_array "#{key}.allowed", value['allowed'], of: :string
|
84
|
+
|
85
|
+
refute value['name'].match(/^-/), "#{key}.name must not start with '-'"
|
84
86
|
end
|
85
87
|
|
86
88
|
def assert_flag(key, value)
|
@@ -96,6 +98,10 @@ module Bashly
|
|
96
98
|
|
97
99
|
assert_boolean "#{key}.required", value['required']
|
98
100
|
assert_array "#{key}.allowed", value['allowed'], of: :string
|
101
|
+
|
102
|
+
assert value['long'].match(/^--[a-zA-Z0-9_\-]+$/), "#{key}.long must be in the form of '--name'" if value['long']
|
103
|
+
assert value['short'].match(/^-[a-zA-Z0-9]$/), "#{key}.short must be in the form of '-n'" if value['short']
|
104
|
+
refute value['arg'].match(/^-/), "#{key}.arg must not start with '-'" if value['arg']
|
99
105
|
end
|
100
106
|
|
101
107
|
def assert_env_var(key, value)
|
@@ -117,6 +123,7 @@ module Bashly
|
|
117
123
|
assert_optional_string "#{key}.help", value['help']
|
118
124
|
assert_optional_string "#{key}.footer", value['footer']
|
119
125
|
assert_optional_string "#{key}.group", value['group']
|
126
|
+
assert_optional_string "#{key}.filename", value['filename']
|
120
127
|
|
121
128
|
assert_boolean "#{key}.default", value['default']
|
122
129
|
assert_version "#{key}.version", value['version']
|
@@ -128,6 +135,7 @@ module Bashly
|
|
128
135
|
assert_array "#{key}.commands", value['commands'], of: :command
|
129
136
|
assert_array "#{key}.completions", value['completions'], of: :string
|
130
137
|
assert_array "#{key}.dependencies", value['dependencies'], of: :string
|
138
|
+
assert_array "#{key}.filters", value['filters'], of: :string
|
131
139
|
assert_array "#{key}.environment_variables", value['environment_variables'], of: :env_var
|
132
140
|
assert_array "#{key}.examples", value['examples'], of: :string
|
133
141
|
end
|
data/lib/bashly/script/base.rb
CHANGED
@@ -16,6 +16,7 @@ module Bashly
|
|
16
16
|
environment_variables
|
17
17
|
examples
|
18
18
|
extensible
|
19
|
+
filters
|
19
20
|
flags
|
20
21
|
footer
|
21
22
|
group
|
@@ -53,9 +54,9 @@ module Bashly
|
|
53
54
|
respond_to?(method_name) ? options[key] : super
|
54
55
|
end
|
55
56
|
|
56
|
-
def
|
57
|
+
def respond_to_missing?(method_name, include_private = false)
|
57
58
|
OPTION_KEYS.include?(method_name) || super
|
58
59
|
end
|
59
60
|
end
|
60
61
|
end
|
61
|
-
end
|
62
|
+
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
|
-
|
34
|
-
|
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"]
|
@@ -121,7 +55,7 @@ module Bashly
|
|
121
55
|
# Returns the bash filename that is expected to hold the user code
|
122
56
|
# for this command
|
123
57
|
def filename
|
124
|
-
"#{action_name.to_underscore}_command.sh"
|
58
|
+
options["filename"] || "#{action_name.to_underscore}_command.sh"
|
125
59
|
end
|
126
60
|
|
127
61
|
# Returns an array of Flags
|
@@ -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 <<
|
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
|
data/lib/bashly/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# :command.catch_all_filter
|
2
|
-
% if
|
2
|
+
% if catch_all.required?
|
3
3
|
if [[ ${#other_args[@]} -eq 0 ]]; then
|
4
|
-
printf "<%= strings[:missing_required_argument] % { arg:
|
4
|
+
printf "<%= strings[:missing_required_argument] % { arg: catch_all.label, usage: usage_string } %>\n"
|
5
5
|
exit 1
|
6
6
|
fi
|
7
7
|
% end
|
@@ -7,6 +7,7 @@ parse_requirements() {
|
|
7
7
|
<%= render(:fixed_flags_filter).indent 2 %>
|
8
8
|
<%= render(:environment_variables_filter).indent 2 %>
|
9
9
|
<%= render(:dependencies_filter).indent 2 %>
|
10
|
+
<%= render(:user_filter).indent 2 %>
|
10
11
|
<%= render(:command_filter).indent 2 %>
|
11
12
|
<%= render(:parse_requirements_while).indent 2 %>
|
12
13
|
<%= render(:required_args_filter).indent 2 %>
|
@@ -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
|
@@ -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
|
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
|
9
|
+
% if catch_all.help
|
10
10
|
|
11
|
-
echo " <%=
|
12
|
-
printf "<%=
|
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.
|
4
|
+
version: 0.7.5
|
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:
|
11
|
+
date: 2022-02-14 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.
|
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.
|
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
|
@@ -153,6 +155,7 @@ files:
|
|
153
155
|
- lib/bashly/views/command/usage_examples.erb
|
154
156
|
- lib/bashly/views/command/usage_fixed_flags.erb
|
155
157
|
- lib/bashly/views/command/usage_flags.erb
|
158
|
+
- lib/bashly/views/command/user_filter.erb
|
156
159
|
- lib/bashly/views/command/user_lib.erb
|
157
160
|
- lib/bashly/views/command/version_command.erb
|
158
161
|
- lib/bashly/views/command/whitelist_filter.erb
|
@@ -186,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
189
|
- !ruby/object:Gem::Version
|
187
190
|
version: '0'
|
188
191
|
requirements: []
|
189
|
-
rubygems_version: 3.
|
192
|
+
rubygems_version: 3.3.7
|
190
193
|
signing_key:
|
191
194
|
specification_version: 4
|
192
195
|
summary: Bash Command Line Tool Generator
|