bashly 0.8.10 → 0.9.1
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/README.md +7 -0
- data/bin/bashly +2 -2
- data/lib/bashly/cli.rb +2 -3
- data/lib/bashly/commands/add.rb +77 -50
- data/lib/bashly/commands/base.rb +4 -3
- data/lib/bashly/commands/generate.rb +43 -36
- data/lib/bashly/commands/init.rb +10 -9
- data/lib/bashly/commands/preview.rb +4 -4
- data/lib/bashly/commands/validate.rb +8 -7
- data/lib/bashly/concerns/asset_helper.rb +1 -1
- data/lib/bashly/concerns/completions.rb +24 -15
- data/lib/bashly/concerns/renderable.rb +5 -5
- data/lib/bashly/concerns/validation_helpers.rb +20 -12
- data/lib/bashly/config.rb +1 -1
- data/lib/bashly/config_validator.rb +53 -27
- data/lib/bashly/deprecation.rb +9 -7
- data/lib/bashly/exceptions.rb +1 -1
- data/lib/bashly/extensions/array.rb +4 -4
- data/lib/bashly/extensions/file.rb +3 -3
- data/lib/bashly/extensions/string.rb +6 -6
- data/lib/bashly/libraries/base.rb +11 -1
- data/lib/bashly/libraries/completions_function.rb +9 -10
- data/lib/bashly/libraries/completions_script.rb +7 -8
- data/lib/bashly/libraries/completions_yaml.rb +7 -8
- data/lib/bashly/libraries/help.rb +36 -0
- data/lib/bashly/libraries.yml +11 -9
- data/lib/bashly/library.rb +8 -5
- data/lib/bashly/message_strings.rb +1 -1
- data/lib/bashly/refinements/compose_refinements.rb +2 -2
- data/lib/bashly/script/argument.rb +1 -1
- data/lib/bashly/script/base.rb +3 -2
- data/lib/bashly/script/catch_all.rb +6 -4
- data/lib/bashly/script/command.rb +48 -54
- data/lib/bashly/script/environment_variable.rb +5 -5
- data/lib/bashly/script/flag.rb +7 -7
- data/lib/bashly/script/wrapper.rb +6 -5
- data/lib/bashly/settings.rb +30 -27
- data/lib/bashly/templates/help/help_command.sh +30 -0
- data/lib/bashly/templates/lib/colors.sh +2 -2
- data/lib/bashly/templates/lib/config.sh +10 -10
- data/lib/bashly/templates/lib/yaml.sh +9 -9
- data/lib/bashly/templates/settings.yml +3 -0
- data/lib/bashly/templates/test/approvals.bash +36 -12
- data/lib/bashly/templates/test/approve +14 -9
- data/lib/bashly/version.rb +2 -2
- data/lib/bashly/views/command/command_fallback.gtx +9 -6
- data/lib/bashly/views/command/command_filter.gtx +8 -9
- data/lib/bashly/views/command/dependencies_filter.gtx +6 -2
- data/lib/bashly/views/command/fixed_flags_filter.gtx +18 -12
- data/lib/bashly/views/command/inspect_args.gtx +2 -2
- data/lib/bashly/views/command/normalize_input.gtx +1 -1
- data/lib/bashly/views/command/parse_requirements_while.gtx +11 -11
- data/lib/bashly/views/command/run.gtx +16 -13
- data/lib/bashly/views/command/usage_environment_variables.gtx +1 -1
- data/lib/bashly/views/flag/case.gtx +1 -1
- data/lib/bashly/views/flag/case_no_arg.gtx +1 -1
- metadata +10 -8
- data/lib/bashly/libraries/completions.rb +0 -14
|
@@ -2,7 +2,6 @@ module Bashly
|
|
|
2
2
|
# This is a `ConfigValidator` concern responsible for providing basic
|
|
3
3
|
# assertion methods.
|
|
4
4
|
module ValidationHelpers
|
|
5
|
-
|
|
6
5
|
def deprecations
|
|
7
6
|
@deprecations ||= []
|
|
8
7
|
end
|
|
@@ -30,34 +29,42 @@ module Bashly
|
|
|
30
29
|
end
|
|
31
30
|
|
|
32
31
|
def assert_boolean(key, value)
|
|
33
|
-
assert [true, false, nil].include?(value), "#{key} must be a boolean"
|
|
32
|
+
assert [true, false, nil].include?(value), "#{key} must be a boolean"
|
|
34
33
|
end
|
|
35
34
|
|
|
36
35
|
def assert_array(key, value, of: nil)
|
|
37
36
|
return unless value
|
|
37
|
+
|
|
38
38
|
assert value.is_a?(Array), "#{key} must be an array"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
return unless of
|
|
40
|
+
|
|
41
|
+
value.each_with_index do |val, i|
|
|
42
|
+
send "assert_#{of}".to_sym, "#{key}[#{i}]", val
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
def assert_hash(key, value,
|
|
46
|
+
def assert_hash(key, value, keys: nil, of: nil)
|
|
47
47
|
assert value.is_a?(Hash), "#{key} must be a hash"
|
|
48
|
-
|
|
49
|
-
if
|
|
50
|
-
invalid_keys = value.keys.map(&:to_sym) -
|
|
51
|
-
assert invalid_keys.empty?, "#{key} contains invalid options: #{invalid_keys.join
|
|
48
|
+
|
|
49
|
+
if keys
|
|
50
|
+
invalid_keys = value.keys.map(&:to_sym) - keys
|
|
51
|
+
assert invalid_keys.empty?, "#{key} contains invalid options: #{invalid_keys.join ', '}"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
return unless of
|
|
55
|
+
|
|
56
|
+
value.each do |k, v|
|
|
57
|
+
send "assert_#{of}".to_sym, "#{key}.#{k}", v
|
|
52
58
|
end
|
|
53
59
|
end
|
|
54
60
|
|
|
55
61
|
def assert_uniq(key, value, array_keys)
|
|
56
62
|
return unless value
|
|
63
|
+
|
|
57
64
|
array_keys = [array_keys] unless array_keys.is_a? Array
|
|
58
65
|
list = []
|
|
59
66
|
array_keys.each do |array_key|
|
|
60
|
-
list += value.
|
|
67
|
+
list += value.filter_map { |c| c[array_key] }.flatten
|
|
61
68
|
end
|
|
62
69
|
|
|
63
70
|
nonuniqs = list.nonuniq
|
|
@@ -66,6 +73,7 @@ module Bashly
|
|
|
66
73
|
|
|
67
74
|
def assert_string_or_array(key, value)
|
|
68
75
|
return unless value
|
|
76
|
+
|
|
69
77
|
assert [Array, String].include?(value.class),
|
|
70
78
|
"#{key} must be a string or an array"
|
|
71
79
|
|
data/lib/bashly/config.rb
CHANGED
|
@@ -9,52 +9,76 @@ module Bashly
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def validate
|
|
12
|
-
assert_command
|
|
12
|
+
assert_command 'root', data
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
private
|
|
16
16
|
|
|
17
17
|
def assert_version(key, value)
|
|
18
18
|
return unless value
|
|
19
|
+
|
|
19
20
|
assert [String, Integer, Float].include?(value.class),
|
|
20
|
-
"#{key} must be a string or a number"
|
|
21
|
+
"#{key} must be a string or a number"
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
def assert_catch_all(key, value)
|
|
24
25
|
return unless value
|
|
26
|
+
|
|
25
27
|
assert [TrueClass, String, Hash].include?(value.class),
|
|
26
|
-
"#{key} must be a boolean, a string or a hash"
|
|
28
|
+
"#{key} must be a boolean, a string or a hash"
|
|
27
29
|
|
|
28
30
|
assert_catch_all_hash key, value if value.is_a? Hash
|
|
29
31
|
end
|
|
30
32
|
|
|
31
33
|
def assert_catch_all_hash(key, value)
|
|
32
|
-
assert_hash key, value, Script::CatchAll.option_keys
|
|
34
|
+
assert_hash key, value, keys: Script::CatchAll.option_keys
|
|
33
35
|
assert_string "#{key}.label", value['label']
|
|
34
36
|
assert_optional_string "#{key}.help", value['help']
|
|
35
37
|
assert_boolean "#{key}.required", value['required']
|
|
36
38
|
end
|
|
37
39
|
|
|
40
|
+
def assert_default_command(key, value)
|
|
41
|
+
return unless value
|
|
42
|
+
|
|
43
|
+
assert [true, false, nil, 'force'].include?(value), "#{key} must be a boolean, or the string 'force'"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def assert_dependencies(key, value)
|
|
47
|
+
return unless value
|
|
48
|
+
|
|
49
|
+
case value
|
|
50
|
+
when Array
|
|
51
|
+
assert_array key, value, of: :string
|
|
52
|
+
when Hash
|
|
53
|
+
assert_hash key, value, of: :string
|
|
54
|
+
else
|
|
55
|
+
assert [Array, Hash].include?(value.class),
|
|
56
|
+
"#{key} must be an array or a hash"
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
38
60
|
def assert_extensible(key, value)
|
|
39
61
|
return unless value
|
|
62
|
+
|
|
40
63
|
assert [TrueClass, String].include?(value.class),
|
|
41
|
-
"#{key} must be a boolean or a string"
|
|
64
|
+
"#{key} must be a boolean or a string"
|
|
42
65
|
end
|
|
43
66
|
|
|
44
67
|
def assert_expose(key, value)
|
|
45
68
|
return unless value
|
|
46
|
-
|
|
69
|
+
|
|
70
|
+
assert [true, false, nil, 'always'].include?(value), "#{key} must be a boolean, or the string 'always'"
|
|
47
71
|
end
|
|
48
72
|
|
|
49
73
|
def assert_arg(key, value)
|
|
50
|
-
assert_hash key, value, Script::Argument.option_keys
|
|
74
|
+
assert_hash key, value, keys: Script::Argument.option_keys
|
|
51
75
|
assert_string "#{key}.name", value['name']
|
|
52
76
|
assert_optional_string "#{key}.help", value['help']
|
|
53
77
|
assert_optional_string "#{key}.default", value['default']
|
|
54
78
|
assert_optional_string "#{key}.validate", value['validate']
|
|
55
79
|
assert_boolean "#{key}.required", value['required']
|
|
56
80
|
assert_boolean "#{key}.repeatable", value['repeatable']
|
|
57
|
-
|
|
81
|
+
|
|
58
82
|
assert_array "#{key}.allowed", value['allowed'], of: :string
|
|
59
83
|
|
|
60
84
|
refute value['name'].match(/^-/), "#{key}.name must not start with '-'"
|
|
@@ -63,7 +87,7 @@ module Bashly
|
|
|
63
87
|
end
|
|
64
88
|
|
|
65
89
|
def assert_flag(key, value)
|
|
66
|
-
assert_hash key, value, Script::Flag.option_keys
|
|
90
|
+
assert_hash key, value, keys: Script::Flag.option_keys
|
|
67
91
|
assert value['short'] || value['long'], "#{key} must have at least one of long or short name"
|
|
68
92
|
|
|
69
93
|
refute value['allowed'] && value['completions'], "#{key} cannot have both allowed and completions"
|
|
@@ -74,14 +98,14 @@ module Bashly
|
|
|
74
98
|
assert_optional_string "#{key}.arg", value['arg']
|
|
75
99
|
assert_optional_string "#{key}.default", value['default']
|
|
76
100
|
assert_optional_string "#{key}.validate", value['validate']
|
|
77
|
-
|
|
101
|
+
|
|
78
102
|
assert_boolean "#{key}.repeatable", value['repeatable']
|
|
79
103
|
assert_boolean "#{key}.required", value['required']
|
|
80
104
|
assert_array "#{key}.allowed", value['allowed'], of: :string
|
|
81
105
|
assert_array "#{key}.conflicts", value['conflicts'], of: :string
|
|
82
106
|
assert_array "#{key}.completions", value['completions'], of: :string
|
|
83
107
|
|
|
84
|
-
assert value['long'].match(/^--[a-zA-Z0-9_
|
|
108
|
+
assert value['long'].match(/^--[a-zA-Z0-9_-]+$/), "#{key}.long must be in the form of '--name'" if value['long']
|
|
85
109
|
assert value['short'].match(/^-[a-zA-Z0-9]$/), "#{key}.short must be in the form of '-n'" if value['short']
|
|
86
110
|
refute value['arg'].match(/^-/), "#{key}.arg must not start with '-'" if value['arg']
|
|
87
111
|
|
|
@@ -101,15 +125,20 @@ module Bashly
|
|
|
101
125
|
end
|
|
102
126
|
|
|
103
127
|
def assert_env_var(key, value)
|
|
104
|
-
assert_hash key, value, Script::EnvironmentVariable.option_keys
|
|
128
|
+
assert_hash key, value, keys: Script::EnvironmentVariable.option_keys
|
|
105
129
|
assert_string "#{key}.name", value['name']
|
|
106
130
|
assert_optional_string "#{key}.help", value['help']
|
|
107
131
|
assert_optional_string "#{key}.default", value['default']
|
|
108
132
|
assert_boolean "#{key}.required", value['required']
|
|
133
|
+
assert_boolean "#{key}.private", value['private']
|
|
134
|
+
|
|
135
|
+
if value['private']
|
|
136
|
+
assert value['default'], "#{key}.private makes no sense without default"
|
|
137
|
+
end
|
|
109
138
|
end
|
|
110
139
|
|
|
111
140
|
def assert_command(key, value)
|
|
112
|
-
assert_hash key, value, Script::Command.option_keys
|
|
141
|
+
assert_hash key, value, keys: Script::Command.option_keys
|
|
113
142
|
|
|
114
143
|
refute value['commands'] && value['args'], "#{key} cannot have both commands and args"
|
|
115
144
|
refute value['commands'] && value['catch_all'], "#{key} cannot have both commands and catch_all"
|
|
@@ -122,37 +151,34 @@ module Bashly
|
|
|
122
151
|
assert_optional_string "#{key}.function", value['function']
|
|
123
152
|
|
|
124
153
|
assert_boolean "#{key}.private", value['private']
|
|
125
|
-
|
|
154
|
+
assert_default_command "#{key}.default", value['default']
|
|
126
155
|
assert_expose "#{key}.expose", value['expose']
|
|
127
156
|
assert_version "#{key}.version", value['version']
|
|
128
157
|
assert_catch_all "#{key}.catch_all", value['catch_all']
|
|
129
158
|
assert_string_or_array "#{key}.alias", value['alias']
|
|
130
159
|
assert_string_or_array "#{key}.examples", value['examples']
|
|
131
160
|
assert_extensible "#{key}.extensible", value['extensible']
|
|
132
|
-
|
|
161
|
+
assert_dependencies "#{key}.dependencies", value['dependencies']
|
|
162
|
+
|
|
133
163
|
assert_array "#{key}.args", value['args'], of: :arg
|
|
134
|
-
assert_array "#{key}.flags", value['flags']
|
|
164
|
+
assert_array "#{key}.flags", value['flags'], of: :flag
|
|
135
165
|
assert_array "#{key}.commands", value['commands'], of: :command
|
|
136
166
|
assert_array "#{key}.completions", value['completions'], of: :string
|
|
137
|
-
assert_array "#{key}.dependencies", value['dependencies'], of: :string
|
|
138
167
|
assert_array "#{key}.filters", value['filters'], of: :string
|
|
139
168
|
assert_array "#{key}.environment_variables", value['environment_variables'], of: :env_var
|
|
140
169
|
|
|
141
|
-
assert_uniq "#{key}.commands", value['commands'], [
|
|
170
|
+
assert_uniq "#{key}.commands", value['commands'], %w[name alias]
|
|
142
171
|
assert_uniq "#{key}.flags", value['flags'], 'long'
|
|
143
172
|
assert_uniq "#{key}.flags", value['flags'], 'short'
|
|
144
173
|
assert_uniq "#{key}.args", value['args'], 'name'
|
|
145
174
|
|
|
146
175
|
if value['function']
|
|
147
|
-
assert value['function'].match(/^[a-z0-9_]+$/),
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if value['default']
|
|
151
|
-
assert value['args'], "#{key}.default makes no sense without args"
|
|
176
|
+
assert value['function'].match(/^[a-z0-9_]+$/),
|
|
177
|
+
"#{key}.function must contain lowercase alphanumeric characters and underscores only"
|
|
152
178
|
end
|
|
153
179
|
|
|
154
|
-
if value['catch_all']
|
|
155
|
-
repeatable_arg = value['args'].
|
|
180
|
+
if value['catch_all'] && value['args']
|
|
181
|
+
repeatable_arg = value['args'].find { |a| a['repeatable'] }&.dig 'name'
|
|
156
182
|
refute repeatable_arg, "#{key}.catch_all makes no sense with repeatable arg (#{repeatable_arg})"
|
|
157
183
|
end
|
|
158
184
|
|
|
@@ -160,7 +186,7 @@ module Bashly
|
|
|
160
186
|
assert value['commands'], "#{key}.expose makes no sense without commands"
|
|
161
187
|
end
|
|
162
188
|
|
|
163
|
-
if key ==
|
|
189
|
+
if key == 'root'
|
|
164
190
|
refute value['alias'], "#{key}.alias makes no sense"
|
|
165
191
|
refute value['group'], "#{key}.group makes no sense"
|
|
166
192
|
refute value['default'], "#{key}.default makes no sense"
|
|
@@ -173,7 +199,7 @@ module Bashly
|
|
|
173
199
|
|
|
174
200
|
# DEPRECATION 0.8.0
|
|
175
201
|
if value['short']
|
|
176
|
-
deprecate "#{key}.short", replacement:
|
|
202
|
+
deprecate "#{key}.short", replacement: 'alias', reference: 'https://github.com/DannyBen/bashly/pull/220'
|
|
177
203
|
end
|
|
178
204
|
end
|
|
179
205
|
end
|
data/lib/bashly/deprecation.rb
CHANGED
|
@@ -3,23 +3,25 @@ module Bashly
|
|
|
3
3
|
attr_reader :old, :replacement, :reference
|
|
4
4
|
|
|
5
5
|
def initialize(old, replacement: nil, reference: nil)
|
|
6
|
-
@old
|
|
6
|
+
@old = old
|
|
7
|
+
@replacement = replacement
|
|
8
|
+
@reference = reference
|
|
7
9
|
end
|
|
8
10
|
|
|
9
11
|
def message
|
|
10
|
-
result = [
|
|
12
|
+
result = ['Deprecation Warning:', "!txtred!#{old}!txtrst! is deprecated"]
|
|
11
13
|
result.push "use !txtgrn!#{replacement}!txtrst! instead" if replacement
|
|
12
14
|
result.push "see !undblu!#{reference}!txtrst!" if reference
|
|
13
|
-
|
|
14
|
-
result.map { |line| "!txtred!▐!txtrst! #{line}"}.join("\n")
|
|
15
|
+
|
|
16
|
+
result.map { |line| "!txtred!▐!txtrst! #{line}" }.join("\n")
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
def to_h
|
|
18
20
|
{
|
|
19
|
-
old:
|
|
21
|
+
old: old,
|
|
20
22
|
replacement: replacement,
|
|
21
|
-
reference:
|
|
23
|
+
reference: reference,
|
|
22
24
|
}
|
|
23
25
|
end
|
|
24
26
|
end
|
|
25
|
-
end
|
|
27
|
+
end
|
data/lib/bashly/exceptions.rb
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
class Array
|
|
2
2
|
def indent(offset)
|
|
3
|
-
return self unless offset
|
|
4
|
-
|
|
3
|
+
return self unless offset.positive?
|
|
4
|
+
|
|
5
|
+
indentation = ' ' * offset
|
|
5
6
|
map { |line| "#{indentation}#{line}" }
|
|
6
7
|
end
|
|
7
8
|
|
|
8
9
|
def nonuniq
|
|
9
|
-
tally.select { |
|
|
10
|
+
tally.select { |_key, count| count > 1 }.keys
|
|
10
11
|
end
|
|
11
|
-
|
|
12
12
|
end
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'fileutils'
|
|
2
2
|
|
|
3
3
|
class File
|
|
4
4
|
def self.deep_write(file, content)
|
|
5
5
|
dir = File.dirname file
|
|
6
|
-
FileUtils.mkdir_p dir
|
|
6
|
+
FileUtils.mkdir_p dir
|
|
7
7
|
File.write file, content
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def self.append(path, content)
|
|
11
|
-
File.open(path,
|
|
11
|
+
File.open(path, 'a') { |f| f << content }
|
|
12
12
|
end
|
|
13
13
|
end
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
class String
|
|
2
2
|
def sanitize_for_print
|
|
3
|
-
gsub("\n",
|
|
3
|
+
gsub("\n", '\\n').gsub('"', '\"')
|
|
4
4
|
end
|
|
5
5
|
|
|
6
6
|
def indent(offset)
|
|
7
|
-
return self unless offset
|
|
7
|
+
return self unless offset.positive?
|
|
8
|
+
|
|
8
9
|
lines.indent(offset).join
|
|
9
10
|
end
|
|
10
11
|
|
|
11
12
|
def to_underscore
|
|
12
|
-
gsub(/(.)([A-Z])/,'\1_\2').gsub(/[
|
|
13
|
+
gsub(/(.)([A-Z])/, '\1_\2').gsub(/[- ]/, '_').downcase
|
|
13
14
|
end
|
|
14
15
|
|
|
15
16
|
def wrap(length = 80)
|
|
@@ -24,7 +25,7 @@ class String
|
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
def lint
|
|
27
|
-
gsub(/\s+\n/m, "\n\n").lines.
|
|
28
|
+
gsub(/\s+\n/m, "\n\n").lines.grep_v(/^\s*##/).join
|
|
28
29
|
end
|
|
29
30
|
|
|
30
31
|
def remove_front_matter
|
|
@@ -33,8 +34,7 @@ class String
|
|
|
33
34
|
|
|
34
35
|
def expand_tabs(tabstop = 2)
|
|
35
36
|
gsub(/^( {#{tabstop}}+)/) do
|
|
36
|
-
"\t" * (
|
|
37
|
+
"\t" * (::Regexp.last_match(1).size / tabstop)
|
|
37
38
|
end
|
|
38
39
|
end
|
|
39
|
-
|
|
40
40
|
end
|
|
@@ -8,12 +8,22 @@ module Bashly
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def files
|
|
11
|
-
raise NotImplementedError,
|
|
11
|
+
raise NotImplementedError, 'Please implement #files'
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def post_install_message
|
|
15
15
|
nil
|
|
16
16
|
end
|
|
17
|
+
|
|
18
|
+
protected
|
|
19
|
+
|
|
20
|
+
def command
|
|
21
|
+
@command ||= Script::Command.new config
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def config
|
|
25
|
+
@config ||= Config.new "#{Settings.source_dir}/bashly.yml"
|
|
26
|
+
end
|
|
17
27
|
end
|
|
18
28
|
end
|
|
19
29
|
end
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
module Bashly
|
|
2
2
|
module Libraries
|
|
3
|
-
class CompletionsFunction <
|
|
3
|
+
class CompletionsFunction < Base
|
|
4
4
|
def files
|
|
5
5
|
[
|
|
6
6
|
{
|
|
7
|
-
path:
|
|
8
|
-
content: completions_function_code(function_name)
|
|
9
|
-
}
|
|
7
|
+
path: "#{Settings.full_lib_dir}/#{function_name}.#{Settings.partials_extension}",
|
|
8
|
+
content: completions_function_code(function_name),
|
|
9
|
+
},
|
|
10
10
|
]
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def post_install_message
|
|
14
|
-
<<~
|
|
14
|
+
<<~MESSAGE
|
|
15
15
|
In order to enable completions in your script, create a command or a flag (for example: !txtgrn!#{command.name} completions!txtrst! or !txtgrn!#{command.name} --completions!txtrst!) that calls the !txtgrn!#{function_name}!txtrst! function.
|
|
16
16
|
|
|
17
17
|
Your users can then run something like this to enable completions:
|
|
18
18
|
|
|
19
|
-
!txtpur!$ eval
|
|
20
|
-
|
|
19
|
+
!txtpur!$ eval "$(#{command.name} completions)"
|
|
20
|
+
MESSAGE
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
private
|
|
@@ -29,10 +29,9 @@ module Bashly
|
|
|
29
29
|
def completions_function_code(function_name)
|
|
30
30
|
[
|
|
31
31
|
"## [@bashly-upgrade completions #{function_name}]",
|
|
32
|
-
command.completion_function(function_name)
|
|
32
|
+
command.completion_function(function_name),
|
|
33
33
|
].join "\n"
|
|
34
34
|
end
|
|
35
|
-
|
|
36
35
|
end
|
|
37
36
|
end
|
|
38
|
-
end
|
|
37
|
+
end
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
module Bashly
|
|
2
2
|
module Libraries
|
|
3
|
-
class CompletionsScript <
|
|
3
|
+
class CompletionsScript < Base
|
|
4
4
|
def files
|
|
5
5
|
[
|
|
6
6
|
{
|
|
7
|
-
path:
|
|
8
|
-
content: command.completion_script
|
|
9
|
-
}
|
|
7
|
+
path: target_path,
|
|
8
|
+
content: command.completion_script,
|
|
9
|
+
},
|
|
10
10
|
]
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def post_install_message
|
|
14
|
-
<<~
|
|
14
|
+
<<~MESSAGE
|
|
15
15
|
In order to enable completions, run:
|
|
16
16
|
|
|
17
17
|
!txtpur!$ source #{target_path}
|
|
18
|
-
|
|
18
|
+
MESSAGE
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
private
|
|
@@ -23,7 +23,6 @@ module Bashly
|
|
|
23
23
|
def target_path
|
|
24
24
|
@target_path ||= args[0] || "#{Settings.target_dir}/completions.bash"
|
|
25
25
|
end
|
|
26
|
-
|
|
27
26
|
end
|
|
28
27
|
end
|
|
29
|
-
end
|
|
28
|
+
end
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
module Bashly
|
|
2
2
|
module Libraries
|
|
3
|
-
class CompletionsYAML <
|
|
3
|
+
class CompletionsYAML < Base
|
|
4
4
|
def files
|
|
5
5
|
[
|
|
6
6
|
{
|
|
7
|
-
path:
|
|
8
|
-
content: command.completion_data.to_yaml
|
|
9
|
-
}
|
|
7
|
+
path: target_path,
|
|
8
|
+
content: command.completion_data.to_yaml,
|
|
9
|
+
},
|
|
10
10
|
]
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def post_install_message
|
|
14
|
-
<<~
|
|
14
|
+
<<~MESSAGE
|
|
15
15
|
This file can be converted to a completions script using the !txtgrn!completely!txtrst! gem.
|
|
16
|
-
|
|
16
|
+
MESSAGE
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
private
|
|
@@ -21,7 +21,6 @@ module Bashly
|
|
|
21
21
|
def target_path
|
|
22
22
|
@target_path ||= args[0] || "#{Settings.target_dir}/completions.yml"
|
|
23
23
|
end
|
|
24
|
-
|
|
25
24
|
end
|
|
26
25
|
end
|
|
27
|
-
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Bashly
|
|
2
|
+
module Libraries
|
|
3
|
+
class Help < Base
|
|
4
|
+
include AssetHelper
|
|
5
|
+
|
|
6
|
+
def files
|
|
7
|
+
[
|
|
8
|
+
{
|
|
9
|
+
path: "#{Settings.source_dir}/help_command.#{Settings.partials_extension}",
|
|
10
|
+
content: help_command,
|
|
11
|
+
},
|
|
12
|
+
]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def post_install_message
|
|
16
|
+
<<~MESSAGE
|
|
17
|
+
Add this as a command to your bashly.yml:
|
|
18
|
+
|
|
19
|
+
!txtgrn!commands:
|
|
20
|
+
!txtgrn!- name: !txtpur!help
|
|
21
|
+
!txtgrn! help: !txtpur!Show help about a command
|
|
22
|
+
!txtgrn! args:
|
|
23
|
+
!txtgrn!- name: !txtpur!command
|
|
24
|
+
!txtgrn! help: !txtpur!Help subject
|
|
25
|
+
|
|
26
|
+
MESSAGE
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def help_command
|
|
32
|
+
asset_content('templates/help/help_command.sh') % { name: command.name }
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
data/lib/bashly/libraries.yml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
colors:
|
|
2
2
|
files:
|
|
3
3
|
- source: "templates/lib/colors.sh"
|
|
4
|
-
target: "%{user_lib_dir}/colors
|
|
4
|
+
target: "%{user_lib_dir}/colors.%{user_ext}"
|
|
5
5
|
|
|
6
6
|
completions: :CompletionsFunction
|
|
7
7
|
completions_script: :CompletionsScript
|
|
@@ -10,12 +10,14 @@ completions_yaml: :CompletionsYAML
|
|
|
10
10
|
config:
|
|
11
11
|
files:
|
|
12
12
|
- source: "templates/lib/config.sh"
|
|
13
|
-
target: "%{user_lib_dir}/config
|
|
13
|
+
target: "%{user_lib_dir}/config.%{user_ext}"
|
|
14
|
+
|
|
15
|
+
help: :Help
|
|
14
16
|
|
|
15
17
|
lib:
|
|
16
18
|
files:
|
|
17
19
|
- source: "templates/lib/sample_function.sh"
|
|
18
|
-
target: "%{user_lib_dir}/sample_function
|
|
20
|
+
target: "%{user_lib_dir}/sample_function.%{user_ext}"
|
|
19
21
|
|
|
20
22
|
settings:
|
|
21
23
|
files:
|
|
@@ -37,22 +39,22 @@ test:
|
|
|
37
39
|
post_install_message: |
|
|
38
40
|
Edit your tests in !txtgrn!test/approve!txtrst! and then run:
|
|
39
41
|
|
|
40
|
-
!txtpur!$
|
|
42
|
+
!txtpur!$ test/approve!txtrst!
|
|
41
43
|
|
|
42
44
|
Docs: !undblu!https://github.com/DannyBen/approvals.bash
|
|
43
45
|
|
|
44
46
|
validations:
|
|
45
47
|
files:
|
|
46
48
|
- source: "templates/lib/validations/validate_dir_exists.sh"
|
|
47
|
-
target: "%{user_lib_dir}/validations/validate_dir_exists
|
|
49
|
+
target: "%{user_lib_dir}/validations/validate_dir_exists.%{user_ext}"
|
|
48
50
|
- source: "templates/lib/validations/validate_file_exists.sh"
|
|
49
|
-
target: "%{user_lib_dir}/validations/validate_file_exists
|
|
51
|
+
target: "%{user_lib_dir}/validations/validate_file_exists.%{user_ext}"
|
|
50
52
|
- source: "templates/lib/validations/validate_integer.sh"
|
|
51
|
-
target: "%{user_lib_dir}/validations/validate_integer
|
|
53
|
+
target: "%{user_lib_dir}/validations/validate_integer.%{user_ext}"
|
|
52
54
|
- source: "templates/lib/validations/validate_not_empty.sh"
|
|
53
|
-
target: "%{user_lib_dir}/validations/validate_not_empty
|
|
55
|
+
target: "%{user_lib_dir}/validations/validate_not_empty.%{user_ext}"
|
|
54
56
|
|
|
55
57
|
yaml:
|
|
56
58
|
files:
|
|
57
59
|
- source: "templates/lib/yaml.sh"
|
|
58
|
-
target: "%{user_lib_dir}/yaml
|
|
60
|
+
target: "%{user_lib_dir}/yaml.%{user_ext}"
|
data/lib/bashly/library.rb
CHANGED
|
@@ -6,7 +6,7 @@ module Bashly
|
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
def config
|
|
9
|
-
@config ||= YAML.properly_load_file
|
|
9
|
+
@config ||= YAML.properly_load_file config_path
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def config_path
|
|
@@ -18,7 +18,8 @@ module Bashly
|
|
|
18
18
|
attr_reader :name, :args
|
|
19
19
|
|
|
20
20
|
def initialize(name, *args)
|
|
21
|
-
@name
|
|
21
|
+
@name = name.to_s
|
|
22
|
+
@args = args
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
def files
|
|
@@ -27,7 +28,7 @@ module Bashly
|
|
|
27
28
|
|
|
28
29
|
else
|
|
29
30
|
config['files'].map do |file|
|
|
30
|
-
{ path:
|
|
31
|
+
{ path: file['target'] % target_file_args,
|
|
31
32
|
content: asset_content(file['source']) }
|
|
32
33
|
end
|
|
33
34
|
end
|
|
@@ -42,13 +43,14 @@ module Bashly
|
|
|
42
43
|
end
|
|
43
44
|
|
|
44
45
|
def find_file(path)
|
|
45
|
-
files.
|
|
46
|
+
files.find { |f| f[:path] == path }
|
|
46
47
|
end
|
|
47
48
|
|
|
48
49
|
private
|
|
49
50
|
|
|
50
51
|
def custom_handler
|
|
51
52
|
return nil unless config.is_a? Symbol
|
|
53
|
+
|
|
52
54
|
@custom_handler ||= Bashly::Libraries.const_get(config).new(*args)
|
|
53
55
|
end
|
|
54
56
|
|
|
@@ -60,7 +62,8 @@ module Bashly
|
|
|
60
62
|
{
|
|
61
63
|
user_source_dir: Settings.source_dir,
|
|
62
64
|
user_target_dir: Settings.target_dir,
|
|
63
|
-
user_lib_dir:
|
|
65
|
+
user_lib_dir: Settings.full_lib_dir,
|
|
66
|
+
user_ext: Settings.partials_extension,
|
|
64
67
|
}
|
|
65
68
|
end
|
|
66
69
|
end
|