bashly 0.7.10 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bashly/commands/base.rb +21 -3
- data/lib/bashly/commands/generate.rb +12 -11
- data/lib/bashly/commands/preview.rb +5 -4
- data/lib/bashly/commands/validate.rb +7 -1
- data/lib/bashly/concerns/validation_helpers.rb +69 -0
- data/lib/bashly/config_validator.rb +15 -41
- data/lib/bashly/deprecation.rb +25 -0
- data/lib/bashly/extensions/array.rb +5 -0
- data/lib/bashly/script/command.rb +13 -3
- data/lib/bashly/templates/bashly.yml +2 -2
- data/lib/bashly/templates/strings.yml +1 -1
- data/lib/bashly/version.rb +1 -1
- data/lib/bashly/views/command/usage.erb +2 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3d0126229189987753e653a635054113961b1e9e0244d4cdb956beb1d5aff94
|
4
|
+
data.tar.gz: 886987a65edc65d16d2134589cbb4ee9f3fcb9e0b1819c8a87211bcd2d164d0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 880579e8bb650c8835cc7992054f3f4dd3e765ddc1b7072f83ed6fc9049d4b56b38c4a64220c3dd154f8fdbf199462cca1ef955d36d465a0d57ecc00715bd85e
|
7
|
+
data.tar.gz: efa2f73f9eed6d5ba1ebb432e37ef639e618bc1556ba83059ccad4804b6568b407d86f91fe11faa3335b69103e368fdb9bf1339f90af1fd15cb742b91163b911
|
data/lib/bashly/commands/base.rb
CHANGED
@@ -6,10 +6,28 @@ module Bashly
|
|
6
6
|
class Base < MisterBin::Command
|
7
7
|
include AssetHelper
|
8
8
|
|
9
|
+
def config
|
10
|
+
@config ||= Config.new "#{Settings.source_dir}/bashly.yml"
|
11
|
+
end
|
12
|
+
|
13
|
+
def config_validator
|
14
|
+
@config_validator ||= ConfigValidator.new config
|
15
|
+
end
|
16
|
+
|
9
17
|
def validate_config
|
10
|
-
|
11
|
-
|
12
|
-
|
18
|
+
config_validator.validate
|
19
|
+
end
|
20
|
+
|
21
|
+
def with_valid_config
|
22
|
+
validate_config
|
23
|
+
yield
|
24
|
+
show_deprecations
|
25
|
+
end
|
26
|
+
|
27
|
+
def show_deprecations
|
28
|
+
return if config_validator.deprecations.empty? or ENV['BASHLY_HIDE_DEPRECATIONS']
|
29
|
+
messages = "\n" + config_validator.deprecations.map(&:message).join("\n\n") + "\n\n"
|
30
|
+
say! messages
|
13
31
|
end
|
14
32
|
end
|
15
33
|
end
|
@@ -29,13 +29,12 @@ module Bashly
|
|
29
29
|
example "bashly generate --wrap my_function"
|
30
30
|
|
31
31
|
def run
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
quiet_say "run !txtpur!#{master_script_path} --help!txtrst! to test your bash script"
|
32
|
+
with_valid_config do
|
33
|
+
Settings.env = args['--env'] if args['--env']
|
34
|
+
quiet_say "creating !txtgrn!production!txtrst! version" if Settings.production?
|
35
|
+
generate_all_files
|
36
|
+
quiet_say "run !txtpur!#{master_script_path} --help!txtrst! to test your bash script"
|
37
|
+
end
|
39
38
|
end
|
40
39
|
|
41
40
|
private
|
@@ -44,6 +43,12 @@ module Bashly
|
|
44
43
|
say message unless args['--quiet']
|
45
44
|
end
|
46
45
|
|
46
|
+
def generate_all_files
|
47
|
+
create_user_files
|
48
|
+
upgrade_libs if args['--upgrade']
|
49
|
+
create_master_script
|
50
|
+
end
|
51
|
+
|
47
52
|
def upgrade_libs
|
48
53
|
generated_files.each do |file|
|
49
54
|
content = File.read file
|
@@ -128,10 +133,6 @@ module Bashly
|
|
128
133
|
"#{Settings.target_dir}/#{command.name}"
|
129
134
|
end
|
130
135
|
|
131
|
-
def config
|
132
|
-
@config ||= Config.new "#{Settings.source_dir}/bashly.yml"
|
133
|
-
end
|
134
|
-
|
135
136
|
def command
|
136
137
|
@command ||= Script::Command.new config
|
137
138
|
end
|
@@ -9,10 +9,11 @@ module Bashly
|
|
9
9
|
environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
|
10
10
|
|
11
11
|
def run
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
with_valid_config do
|
13
|
+
command = Script::Command.new config
|
14
|
+
script = Script::Wrapper.new command
|
15
|
+
puts script.code
|
16
|
+
end
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
@@ -10,7 +10,13 @@ module Bashly
|
|
10
10
|
|
11
11
|
def run
|
12
12
|
validate_config
|
13
|
-
|
13
|
+
show_deprecations
|
14
|
+
deprecations = config_validator.deprecations
|
15
|
+
if deprecations.empty?
|
16
|
+
say "!txtgrn!OK"
|
17
|
+
else
|
18
|
+
say "!txtred!WARNING!txtrst! Found #{deprecations.count} deprecations"
|
19
|
+
end
|
14
20
|
end
|
15
21
|
end
|
16
22
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Bashly
|
2
|
+
# This is a `ConfigValidator` concern responsible for providing basic
|
3
|
+
# assertion methods.
|
4
|
+
module ValidationHelpers
|
5
|
+
|
6
|
+
def deprecations
|
7
|
+
@deprecations ||= []
|
8
|
+
end
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
def assert(valid, message)
|
13
|
+
raise ConfigurationError, message unless valid
|
14
|
+
end
|
15
|
+
|
16
|
+
def refute(invalid, message)
|
17
|
+
assert !invalid, message
|
18
|
+
end
|
19
|
+
|
20
|
+
def deprecate(key, **options)
|
21
|
+
deprecations.push Deprecation.new(key, **options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def assert_string(key, value)
|
25
|
+
assert value.is_a?(String), "#{key} must be a string"
|
26
|
+
end
|
27
|
+
|
28
|
+
def assert_optional_string(key, value)
|
29
|
+
assert_string key, value if value
|
30
|
+
end
|
31
|
+
|
32
|
+
def assert_boolean(key, value)
|
33
|
+
assert [true, false, nil].include?(value), "#{key} must be a boolean"
|
34
|
+
end
|
35
|
+
|
36
|
+
def assert_array(key, value, of: nil)
|
37
|
+
return unless value
|
38
|
+
assert value.is_a?(Array), "#{key} must be an array"
|
39
|
+
if of
|
40
|
+
value.each_with_index do |val, i|
|
41
|
+
send "assert_#{of}".to_sym, "#{key}[#{i}]", val
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def assert_hash(key, value, whitelist = nil)
|
47
|
+
assert value.is_a?(Hash), "#{key} must be a hash"
|
48
|
+
|
49
|
+
if whitelist
|
50
|
+
invalid_keys = value.keys.map(&:to_sym) - whitelist
|
51
|
+
assert invalid_keys.empty?, "#{key} contains invalid options: #{invalid_keys.join(', ')}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def assert_uniq(key, value, array_key)
|
56
|
+
return unless value
|
57
|
+
list = value.map { |c| c[array_key] }.compact.flatten
|
58
|
+
assert list.uniq?, "#{key} cannot have elements with similar #{array_key} values"
|
59
|
+
end
|
60
|
+
|
61
|
+
def assert_string_or_array(key, value)
|
62
|
+
return unless value
|
63
|
+
assert [Array, String].include?(value.class),
|
64
|
+
"#{key} must be a string or an array"
|
65
|
+
|
66
|
+
assert_array key, value, of: :string if value.is_a? Array
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module Bashly
|
2
2
|
class ConfigValidator
|
3
|
+
include ValidationHelpers
|
4
|
+
|
3
5
|
attr_reader :data
|
4
6
|
|
5
7
|
def initialize(data)
|
@@ -12,45 +14,6 @@ module Bashly
|
|
12
14
|
|
13
15
|
private
|
14
16
|
|
15
|
-
def assert(valid, message)
|
16
|
-
raise ConfigurationError, message unless valid
|
17
|
-
end
|
18
|
-
|
19
|
-
def refute(invalid, message)
|
20
|
-
assert !invalid, message
|
21
|
-
end
|
22
|
-
|
23
|
-
def assert_string(key, value)
|
24
|
-
assert value.is_a?(String), "#{key} must be a string"
|
25
|
-
end
|
26
|
-
|
27
|
-
def assert_optional_string(key, value)
|
28
|
-
assert_string key, value if value
|
29
|
-
end
|
30
|
-
|
31
|
-
def assert_boolean(key, value)
|
32
|
-
assert [true, false, nil].include?(value), "#{key} must be a boolean"
|
33
|
-
end
|
34
|
-
|
35
|
-
def assert_array(key, value, of: nil)
|
36
|
-
return unless value
|
37
|
-
assert value.is_a?(Array), "#{key} must be an array"
|
38
|
-
if of
|
39
|
-
value.each_with_index do |val, i|
|
40
|
-
send "assert_#{of}".to_sym, "#{key}[#{i}]", val
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def assert_hash(key, value, whitelist = nil)
|
46
|
-
assert value.is_a?(Hash), "#{key} must be a hash"
|
47
|
-
|
48
|
-
if whitelist
|
49
|
-
invalid_keys = value.keys.map(&:to_sym) - whitelist
|
50
|
-
assert invalid_keys.empty?, "#{key} contains invalid options: #{invalid_keys.join(', ')}"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
17
|
def assert_version(key, value)
|
55
18
|
return unless value
|
56
19
|
assert [String, Integer, Float].include?(value.class),
|
@@ -140,7 +103,6 @@ module Bashly
|
|
140
103
|
refute value['commands'] && value['flags'], "#{key} cannot have both commands and flags"
|
141
104
|
|
142
105
|
assert_string "#{key}.name", value['name']
|
143
|
-
assert_optional_string "#{key}.short", value['short']
|
144
106
|
assert_optional_string "#{key}.help", value['help']
|
145
107
|
assert_optional_string "#{key}.footer", value['footer']
|
146
108
|
assert_optional_string "#{key}.group", value['group']
|
@@ -150,6 +112,7 @@ module Bashly
|
|
150
112
|
assert_boolean "#{key}.default", value['default']
|
151
113
|
assert_version "#{key}.version", value['version']
|
152
114
|
assert_catch_all "#{key}.catch_all", value['catch_all']
|
115
|
+
assert_string_or_array "#{key}.alias", value['alias']
|
153
116
|
assert_extensible "#{key}.extensible", value['extensible']
|
154
117
|
|
155
118
|
assert_array "#{key}.args", value['args'], of: :arg
|
@@ -161,13 +124,19 @@ module Bashly
|
|
161
124
|
assert_array "#{key}.environment_variables", value['environment_variables'], of: :env_var
|
162
125
|
assert_array "#{key}.examples", value['examples'], of: :string
|
163
126
|
|
127
|
+
assert_uniq "#{key}.commands", value['commands'], 'name'
|
128
|
+
assert_uniq "#{key}.commands", value['commands'], 'alias'
|
129
|
+
assert_uniq "#{key}.flags", value['flags'], 'long'
|
130
|
+
assert_uniq "#{key}.flags", value['flags'], 'short'
|
131
|
+
assert_uniq "#{key}.args", value['args'], 'name'
|
132
|
+
|
164
133
|
if value['catch_all'] and value['args']
|
165
134
|
repeatable_arg = value['args'].select { |a| a['repeatable'] }.first&.dig 'name'
|
166
135
|
refute repeatable_arg, "#{key}.catch_all makes no sense with repeatable arg (#{repeatable_arg})"
|
167
136
|
end
|
168
137
|
|
169
138
|
if key == "root"
|
170
|
-
refute value['
|
139
|
+
refute value['alias'], "#{key}.alias makes no sense"
|
171
140
|
refute value['group'], "#{key}.group makes no sense"
|
172
141
|
refute value['default'], "#{key}.default makes no sense"
|
173
142
|
refute value['private'], "#{key}.private makes no sense"
|
@@ -175,6 +144,11 @@ module Bashly
|
|
175
144
|
refute value['version'], "#{key}.version makes no sense"
|
176
145
|
refute value['extensible'], "#{key}.extensible makes no sense"
|
177
146
|
end
|
147
|
+
|
148
|
+
# DEPRECATION 0.8.0
|
149
|
+
if value['short']
|
150
|
+
deprecate "#{key}.short", replacement: "alias", reference: "https://github.com/DannyBen/bashly/pull/220"
|
151
|
+
end
|
178
152
|
end
|
179
153
|
end
|
180
154
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Bashly
|
2
|
+
class Deprecation
|
3
|
+
attr_reader :old, :replacement, :reference
|
4
|
+
|
5
|
+
def initialize(old, replacement: nil, reference: nil)
|
6
|
+
@old, @replacement, @reference = old, replacement, reference
|
7
|
+
end
|
8
|
+
|
9
|
+
def message
|
10
|
+
result = ["Deprecation Warning:", "!txtred!#{old}!txtrst! is deprecated"]
|
11
|
+
result.push "use !txtgrn!#{replacement}!txtrst! instead" if replacement
|
12
|
+
result.push "see !undblu!#{reference}!txtrst!" if reference
|
13
|
+
|
14
|
+
result.map { |line| "!txtred!▐!txtrst! #{line}"}.join("\n")
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_h
|
18
|
+
{
|
19
|
+
old: old,
|
20
|
+
replacement: replacement,
|
21
|
+
reference: reference
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -7,12 +7,14 @@ module Bashly
|
|
7
7
|
class << self
|
8
8
|
def option_keys
|
9
9
|
@option_keys ||= %i[
|
10
|
-
args catch_all commands completions
|
10
|
+
alias args catch_all commands completions
|
11
11
|
default dependencies environment_variables examples
|
12
12
|
extensible filename filters flags
|
13
13
|
footer group help name
|
14
|
-
private
|
14
|
+
private version
|
15
|
+
short
|
15
16
|
]
|
17
|
+
# DEPRECATION 0.8.0
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
@@ -27,7 +29,15 @@ module Bashly
|
|
27
29
|
|
28
30
|
# Returns all the possible aliases for this command
|
29
31
|
def aliases
|
30
|
-
|
32
|
+
[name] + alt
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns an array of alternative aliases if any
|
36
|
+
def alt
|
37
|
+
# DEPRECATION 0.8.0
|
38
|
+
options['alias'] ||= options['short']
|
39
|
+
return [] unless options["alias"]
|
40
|
+
options['alias'].is_a?(String) ? [options['alias']] : options['alias']
|
31
41
|
end
|
32
42
|
|
33
43
|
# Returns an array of Arguments
|
@@ -8,7 +8,7 @@ environment_variables:
|
|
8
8
|
|
9
9
|
commands:
|
10
10
|
- name: download
|
11
|
-
|
11
|
+
alias: d
|
12
12
|
help: Download a file
|
13
13
|
|
14
14
|
args:
|
@@ -32,7 +32,7 @@ commands:
|
|
32
32
|
help: Set the default location to download to
|
33
33
|
|
34
34
|
- name: upload
|
35
|
-
|
35
|
+
alias: u
|
36
36
|
help: Upload a file
|
37
37
|
args:
|
38
38
|
- name: source
|
@@ -11,7 +11,7 @@ environment_variables: "Environment Variables:"
|
|
11
11
|
group: "%{group} Commands:"
|
12
12
|
|
13
13
|
# Usage helpers
|
14
|
-
|
14
|
+
command_alias: "Alias: %{alias}"
|
15
15
|
default_command_summary: "%{summary} (default)"
|
16
16
|
required: "(required)"
|
17
17
|
repeatable: "(repeatable)"
|
data/lib/bashly/version.rb
CHANGED
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.
|
4
|
+
version: 0.8.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: 2022-
|
11
|
+
date: 2022-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -87,8 +87,10 @@ files:
|
|
87
87
|
- lib/bashly/concerns/command_scopes.rb
|
88
88
|
- lib/bashly/concerns/completions.rb
|
89
89
|
- lib/bashly/concerns/renderable.rb
|
90
|
+
- lib/bashly/concerns/validation_helpers.rb
|
90
91
|
- lib/bashly/config.rb
|
91
92
|
- lib/bashly/config_validator.rb
|
93
|
+
- lib/bashly/deprecation.rb
|
92
94
|
- lib/bashly/exceptions.rb
|
93
95
|
- lib/bashly/extensions/array.rb
|
94
96
|
- lib/bashly/extensions/file.rb
|