bashly 0.8.10 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -0
  3. data/bin/bashly +2 -2
  4. data/lib/bashly/cli.rb +2 -3
  5. data/lib/bashly/commands/add.rb +74 -50
  6. data/lib/bashly/commands/base.rb +4 -3
  7. data/lib/bashly/commands/generate.rb +41 -35
  8. data/lib/bashly/commands/init.rb +10 -9
  9. data/lib/bashly/commands/preview.rb +4 -4
  10. data/lib/bashly/commands/validate.rb +8 -7
  11. data/lib/bashly/concerns/asset_helper.rb +1 -1
  12. data/lib/bashly/concerns/completions.rb +24 -15
  13. data/lib/bashly/concerns/renderable.rb +5 -5
  14. data/lib/bashly/concerns/validation_helpers.rb +20 -12
  15. data/lib/bashly/config.rb +1 -1
  16. data/lib/bashly/config_validator.rb +46 -22
  17. data/lib/bashly/deprecation.rb +9 -7
  18. data/lib/bashly/exceptions.rb +1 -1
  19. data/lib/bashly/extensions/array.rb +4 -4
  20. data/lib/bashly/extensions/file.rb +3 -3
  21. data/lib/bashly/extensions/string.rb +6 -6
  22. data/lib/bashly/libraries/base.rb +11 -1
  23. data/lib/bashly/libraries/completions_function.rb +9 -10
  24. data/lib/bashly/libraries/completions_script.rb +7 -8
  25. data/lib/bashly/libraries/completions_yaml.rb +7 -8
  26. data/lib/bashly/libraries/help.rb +36 -0
  27. data/lib/bashly/libraries.yml +3 -1
  28. data/lib/bashly/library.rb +7 -5
  29. data/lib/bashly/message_strings.rb +1 -1
  30. data/lib/bashly/refinements/compose_refinements.rb +2 -2
  31. data/lib/bashly/script/argument.rb +1 -1
  32. data/lib/bashly/script/base.rb +3 -2
  33. data/lib/bashly/script/catch_all.rb +6 -4
  34. data/lib/bashly/script/command.rb +47 -53
  35. data/lib/bashly/script/environment_variable.rb +5 -5
  36. data/lib/bashly/script/flag.rb +7 -7
  37. data/lib/bashly/script/wrapper.rb +5 -4
  38. data/lib/bashly/settings.rb +4 -5
  39. data/lib/bashly/templates/help/help_command.sh +30 -0
  40. data/lib/bashly/templates/lib/colors.sh +2 -2
  41. data/lib/bashly/templates/lib/config.sh +10 -10
  42. data/lib/bashly/templates/lib/yaml.sh +9 -9
  43. data/lib/bashly/templates/test/approvals.bash +36 -12
  44. data/lib/bashly/templates/test/approve +14 -9
  45. data/lib/bashly/version.rb +2 -2
  46. data/lib/bashly/views/command/command_fallback.gtx +2 -2
  47. data/lib/bashly/views/command/command_filter.gtx +9 -9
  48. data/lib/bashly/views/command/dependencies_filter.gtx +7 -2
  49. data/lib/bashly/views/command/fixed_flags_filter.gtx +18 -12
  50. data/lib/bashly/views/command/inspect_args.gtx +2 -2
  51. data/lib/bashly/views/command/normalize_input.gtx +1 -1
  52. data/lib/bashly/views/command/parse_requirements_while.gtx +11 -11
  53. data/lib/bashly/views/command/run.gtx +14 -13
  54. data/lib/bashly/views/command/usage_environment_variables.gtx +1 -1
  55. data/lib/bashly/views/flag/case.gtx +1 -1
  56. data/lib/bashly/views/flag/case_no_arg.gtx +1 -1
  57. metadata +10 -8
  58. 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
- if of
40
- value.each_with_index do |val, i|
41
- send "assert_#{of}".to_sym, "#{key}[#{i}]", val
42
- end
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, whitelist = nil)
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 whitelist
50
- invalid_keys = value.keys.map(&:to_sym) - whitelist
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.map { |c| c[array_key] }.compact.flatten
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
@@ -16,4 +16,4 @@ module Bashly
16
16
  end
17
17
  end
18
18
  end
19
- end
19
+ end
@@ -9,52 +9,70 @@ module Bashly
9
9
  end
10
10
 
11
11
  def validate
12
- assert_command "root", data
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_dependencies(key, value)
41
+ return unless value
42
+
43
+ case value
44
+ when Array
45
+ assert_array key, value, of: :string
46
+ when Hash
47
+ assert_hash key, value, of: :string
48
+ else
49
+ assert [Array, Hash].include?(value.class),
50
+ "#{key} must be an array or a hash"
51
+ end
52
+ end
53
+
38
54
  def assert_extensible(key, value)
39
55
  return unless value
56
+
40
57
  assert [TrueClass, String].include?(value.class),
41
- "#{key} must be a boolean or a string"
58
+ "#{key} must be a boolean or a string"
42
59
  end
43
60
 
44
61
  def assert_expose(key, value)
45
62
  return unless value
46
- assert [true, false, nil, 'always'].include?(value), "#{key} must be a boolean, or the string 'always'"
63
+
64
+ assert [true, false, nil, 'always'].include?(value), "#{key} must be a boolean, or the string 'always'"
47
65
  end
48
66
 
49
67
  def assert_arg(key, value)
50
- assert_hash key, value, Script::Argument.option_keys
68
+ assert_hash key, value, keys: Script::Argument.option_keys
51
69
  assert_string "#{key}.name", value['name']
52
70
  assert_optional_string "#{key}.help", value['help']
53
71
  assert_optional_string "#{key}.default", value['default']
54
72
  assert_optional_string "#{key}.validate", value['validate']
55
73
  assert_boolean "#{key}.required", value['required']
56
74
  assert_boolean "#{key}.repeatable", value['repeatable']
57
-
75
+
58
76
  assert_array "#{key}.allowed", value['allowed'], of: :string
59
77
 
60
78
  refute value['name'].match(/^-/), "#{key}.name must not start with '-'"
@@ -63,7 +81,7 @@ module Bashly
63
81
  end
64
82
 
65
83
  def assert_flag(key, value)
66
- assert_hash key, value, Script::Flag.option_keys
84
+ assert_hash key, value, keys: Script::Flag.option_keys
67
85
  assert value['short'] || value['long'], "#{key} must have at least one of long or short name"
68
86
 
69
87
  refute value['allowed'] && value['completions'], "#{key} cannot have both allowed and completions"
@@ -74,14 +92,14 @@ module Bashly
74
92
  assert_optional_string "#{key}.arg", value['arg']
75
93
  assert_optional_string "#{key}.default", value['default']
76
94
  assert_optional_string "#{key}.validate", value['validate']
77
-
95
+
78
96
  assert_boolean "#{key}.repeatable", value['repeatable']
79
97
  assert_boolean "#{key}.required", value['required']
80
98
  assert_array "#{key}.allowed", value['allowed'], of: :string
81
99
  assert_array "#{key}.conflicts", value['conflicts'], of: :string
82
100
  assert_array "#{key}.completions", value['completions'], of: :string
83
101
 
84
- assert value['long'].match(/^--[a-zA-Z0-9_\-]+$/), "#{key}.long must be in the form of '--name'" if value['long']
102
+ assert value['long'].match(/^--[a-zA-Z0-9_-]+$/), "#{key}.long must be in the form of '--name'" if value['long']
85
103
  assert value['short'].match(/^-[a-zA-Z0-9]$/), "#{key}.short must be in the form of '-n'" if value['short']
86
104
  refute value['arg'].match(/^-/), "#{key}.arg must not start with '-'" if value['arg']
87
105
 
@@ -101,15 +119,20 @@ module Bashly
101
119
  end
102
120
 
103
121
  def assert_env_var(key, value)
104
- assert_hash key, value, Script::EnvironmentVariable.option_keys
122
+ assert_hash key, value, keys: Script::EnvironmentVariable.option_keys
105
123
  assert_string "#{key}.name", value['name']
106
124
  assert_optional_string "#{key}.help", value['help']
107
125
  assert_optional_string "#{key}.default", value['default']
108
126
  assert_boolean "#{key}.required", value['required']
127
+ assert_boolean "#{key}.private", value['private']
128
+
129
+ if value['private']
130
+ assert value['default'], "#{key}.private makes no sense without default"
131
+ end
109
132
  end
110
133
 
111
134
  def assert_command(key, value)
112
- assert_hash key, value, Script::Command.option_keys
135
+ assert_hash key, value, keys: Script::Command.option_keys
113
136
 
114
137
  refute value['commands'] && value['args'], "#{key} cannot have both commands and args"
115
138
  refute value['commands'] && value['catch_all'], "#{key} cannot have both commands and catch_all"
@@ -129,30 +152,31 @@ module Bashly
129
152
  assert_string_or_array "#{key}.alias", value['alias']
130
153
  assert_string_or_array "#{key}.examples", value['examples']
131
154
  assert_extensible "#{key}.extensible", value['extensible']
132
-
155
+ assert_dependencies "#{key}.dependencies", value['dependencies']
156
+
133
157
  assert_array "#{key}.args", value['args'], of: :arg
134
- assert_array "#{key}.flags", value['flags'] , of: :flag
158
+ assert_array "#{key}.flags", value['flags'], of: :flag
135
159
  assert_array "#{key}.commands", value['commands'], of: :command
136
160
  assert_array "#{key}.completions", value['completions'], of: :string
137
- assert_array "#{key}.dependencies", value['dependencies'], of: :string
138
161
  assert_array "#{key}.filters", value['filters'], of: :string
139
162
  assert_array "#{key}.environment_variables", value['environment_variables'], of: :env_var
140
163
 
141
- assert_uniq "#{key}.commands", value['commands'], ['name', 'alias']
164
+ assert_uniq "#{key}.commands", value['commands'], %w[name alias]
142
165
  assert_uniq "#{key}.flags", value['flags'], 'long'
143
166
  assert_uniq "#{key}.flags", value['flags'], 'short'
144
167
  assert_uniq "#{key}.args", value['args'], 'name'
145
168
 
146
169
  if value['function']
147
- assert value['function'].match(/^[a-z0-9_]+$/), "#{key}.function must contain lowercase alphanumeric characters and underscores only"
170
+ assert value['function'].match(/^[a-z0-9_]+$/),
171
+ "#{key}.function must contain lowercase alphanumeric characters and underscores only"
148
172
  end
149
173
 
150
174
  if value['default']
151
175
  assert value['args'], "#{key}.default makes no sense without args"
152
176
  end
153
177
 
154
- if value['catch_all'] and value['args']
155
- repeatable_arg = value['args'].select { |a| a['repeatable'] }.first&.dig 'name'
178
+ if value['catch_all'] && value['args']
179
+ repeatable_arg = value['args'].find { |a| a['repeatable'] }&.dig 'name'
156
180
  refute repeatable_arg, "#{key}.catch_all makes no sense with repeatable arg (#{repeatable_arg})"
157
181
  end
158
182
 
@@ -160,7 +184,7 @@ module Bashly
160
184
  assert value['commands'], "#{key}.expose makes no sense without commands"
161
185
  end
162
186
 
163
- if key == "root"
187
+ if key == 'root'
164
188
  refute value['alias'], "#{key}.alias makes no sense"
165
189
  refute value['group'], "#{key}.group makes no sense"
166
190
  refute value['default'], "#{key}.default makes no sense"
@@ -173,7 +197,7 @@ module Bashly
173
197
 
174
198
  # DEPRECATION 0.8.0
175
199
  if value['short']
176
- deprecate "#{key}.short", replacement: "alias", reference: "https://github.com/DannyBen/bashly/pull/220"
200
+ deprecate "#{key}.short", replacement: 'alias', reference: 'https://github.com/DannyBen/bashly/pull/220'
177
201
  end
178
202
  end
179
203
  end
@@ -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, @replacement, @reference = old, replacement, reference
6
+ @old = old
7
+ @replacement = replacement
8
+ @reference = reference
7
9
  end
8
10
 
9
11
  def message
10
- result = ["Deprecation Warning:", "!txtred!#{old}!txtrst! is deprecated"]
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: old,
21
+ old: old,
20
22
  replacement: replacement,
21
- reference: reference
23
+ reference: reference,
22
24
  }
23
25
  end
24
26
  end
25
- end
27
+ end
@@ -3,4 +3,4 @@ module Bashly
3
3
  class Error < StandardError; end
4
4
  class InitError < Error; end
5
5
  class ConfigurationError < Error; end
6
- end
6
+ end
@@ -1,12 +1,12 @@
1
1
  class Array
2
2
  def indent(offset)
3
- return self unless offset > 0
4
- indentation = " " * offset
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 { |key, count| count > 1 }.keys
10
+ tally.select { |_key, count| count > 1 }.keys
10
11
  end
11
-
12
12
  end
@@ -1,13 +1,13 @@
1
- require "fileutils"
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 unless Dir.exist? 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, "a") { |f| f << content }
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", "\\n").gsub("\"", "\\\"")
3
+ gsub("\n", '\\n').gsub('"', '\"')
4
4
  end
5
5
 
6
6
  def indent(offset)
7
- return self unless offset > 0
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(/[\- ]/, '_').downcase
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.reject { |l| l =~ /^\s*##/ }.join
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" * ($1.size / tabstop)
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, "Please implement #files"
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 < Completions
3
+ class CompletionsFunction < Base
4
4
  def files
5
5
  [
6
6
  {
7
- path: "#{Settings.full_lib_dir}/#{function_name}.sh",
8
- content: completions_function_code(function_name)
9
- }
7
+ path: "#{Settings.full_lib_dir}/#{function_name}.sh",
8
+ content: completions_function_code(function_name),
9
+ },
10
10
  ]
11
11
  end
12
12
 
13
13
  def post_install_message
14
- <<~EOF
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 \"$(#{command.name} completions)\"
20
- EOF
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 < Completions
3
+ class CompletionsScript < Base
4
4
  def files
5
5
  [
6
6
  {
7
- path: target_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
- <<~EOF
14
+ <<~MESSAGE
15
15
  In order to enable completions, run:
16
16
 
17
17
  !txtpur!$ source #{target_path}
18
- EOF
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 < Completions
3
+ class CompletionsYAML < Base
4
4
  def files
5
5
  [
6
6
  {
7
- path: target_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
- <<~EOF
14
+ <<~MESSAGE
15
15
  This file can be converted to a completions script using the !txtgrn!completely!txtrst! gem.
16
- EOF
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.sh",
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
@@ -12,6 +12,8 @@ config:
12
12
  - source: "templates/lib/config.sh"
13
13
  target: "%{user_lib_dir}/config.sh"
14
14
 
15
+ help: :Help
16
+
15
17
  lib:
16
18
  files:
17
19
  - source: "templates/lib/sample_function.sh"
@@ -37,7 +39,7 @@ test:
37
39
  post_install_message: |
38
40
  Edit your tests in !txtgrn!test/approve!txtrst! and then run:
39
41
 
40
- !txtpur!$ ./test/approve!txtrst!"
42
+ !txtpur!$ test/approve!txtrst!
41
43
 
42
44
  Docs: !undblu!https://github.com/DannyBen/approvals.bash
43
45
 
@@ -6,7 +6,7 @@ module Bashly
6
6
  end
7
7
 
8
8
  def config
9
- @config ||= YAML.properly_load_file(config_path)
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, @args = name.to_s, args
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: file['target'] % target_file_args,
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.select { |f| f[:path] == path }.first
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,7 @@ module Bashly
60
62
  {
61
63
  user_source_dir: Settings.source_dir,
62
64
  user_target_dir: Settings.target_dir,
63
- user_lib_dir: Settings.full_lib_dir,
65
+ user_lib_dir: Settings.full_lib_dir,
64
66
  }
65
67
  end
66
68
  end
@@ -13,7 +13,7 @@ module Bashly
13
13
  private
14
14
 
15
15
  def values!
16
- defaults = YAML.properly_load_file asset("templates/strings.yml")
16
+ defaults = YAML.properly_load_file asset('templates/strings.yml')
17
17
  defaults.merge project_strings
18
18
  end
19
19
 
@@ -23,9 +23,9 @@ module ComposeRefinements
23
23
 
24
24
  def safe_load_yaml(path)
25
25
  loaded = YAML.properly_load_file path
26
- return loaded if loaded.is_a? Array or loaded.is_a? Hash
27
- raise Bashly::ConfigurationError, "Cannot find a valid YAML in !txtgrn!#{path}"
26
+ return loaded if loaded.is_a?(Array) || loaded.is_a?(Hash)
28
27
 
28
+ raise Bashly::ConfigurationError, "Cannot find a valid YAML in !txtgrn!#{path}"
29
29
  rescue Errno::ENOENT
30
30
  raise Bashly::ConfigurationError, "Cannot find import file !txtgrn!#{path}"
31
31
  end
@@ -18,4 +18,4 @@ module Bashly
18
18
  end
19
19
  end
20
20
  end
21
- end
21
+ end
@@ -12,7 +12,8 @@ module Bashly
12
12
  end
13
13
 
14
14
  def initialize(options)
15
- raise Error, "Invalid options provided" unless options.respond_to? :keys
15
+ raise Error, 'Invalid options provided' unless options.respond_to? :keys
16
+
16
17
  @options = options
17
18
  end
18
19
 
@@ -21,7 +22,7 @@ module Bashly
21
22
  end
22
23
 
23
24
  def summary
24
- help.empty? ? "" : help.split("\n").first
25
+ help.empty? ? '' : help.split("\n").first
25
26
  end
26
27
 
27
28
  def help