bashly 0.7.0 → 0.7.4

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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bashly/cli.rb +1 -0
  3. data/lib/bashly/commands/add.rb +14 -25
  4. data/lib/bashly/commands/generate.rb +20 -19
  5. data/lib/bashly/commands/validate.rb +19 -0
  6. data/lib/bashly/concerns/command_scopes.rb +68 -0
  7. data/lib/bashly/config_validator.rb +143 -0
  8. data/lib/bashly/extensions/string.rb +4 -0
  9. data/lib/bashly/libraries/base.rb +19 -0
  10. data/lib/bashly/libraries/completions.rb +14 -0
  11. data/lib/bashly/{library → libraries}/completions_function.rb +18 -6
  12. data/lib/bashly/libraries/completions_script.rb +29 -0
  13. data/lib/bashly/libraries/completions_yaml.rb +27 -0
  14. data/lib/bashly/libraries.yml +39 -0
  15. data/lib/bashly/library.rb +63 -0
  16. data/lib/bashly/refinements/compose_refinements.rb +45 -0
  17. data/lib/bashly/script/base.rb +5 -3
  18. data/lib/bashly/script/catch_all.rb +49 -0
  19. data/lib/bashly/script/command.rb +9 -111
  20. data/lib/bashly/version.rb +1 -1
  21. data/lib/bashly/views/command/catch_all_filter.erb +2 -2
  22. data/lib/bashly/views/command/command_filter.erb +1 -1
  23. data/lib/bashly/views/command/default_assignments.erb +2 -2
  24. data/lib/bashly/views/command/default_initialize_script.erb +6 -6
  25. data/lib/bashly/views/command/default_root_script.erb +1 -1
  26. data/lib/bashly/views/command/environment_variables_filter.erb +1 -1
  27. data/lib/bashly/views/command/fixed_flags_filter.erb +1 -1
  28. data/lib/bashly/views/command/initialize.erb +1 -1
  29. data/lib/bashly/views/command/parse_requirements.erb +1 -0
  30. data/lib/bashly/views/command/parse_requirements_case.erb +2 -2
  31. data/lib/bashly/views/command/parse_requirements_while.erb +2 -2
  32. data/lib/bashly/views/command/root_command.erb +1 -1
  33. data/lib/bashly/views/command/run.erb +4 -4
  34. data/lib/bashly/views/command/usage.erb +1 -1
  35. data/lib/bashly/views/command/usage_args.erb +3 -3
  36. data/lib/bashly/views/command/usage_commands.erb +1 -1
  37. data/lib/bashly/views/command/user_filter.erb +11 -0
  38. data/lib/bashly.rb +2 -1
  39. metadata +18 -16
  40. data/lib/bashly/library/base.rb +0 -57
  41. data/lib/bashly/library/colors.rb +0 -9
  42. data/lib/bashly/library/completions.rb +0 -28
  43. data/lib/bashly/library/completions_script.rb +0 -17
  44. data/lib/bashly/library/completions_yaml.rb +0 -15
  45. data/lib/bashly/library/config.rb +0 -9
  46. data/lib/bashly/library/sample.rb +0 -9
  47. data/lib/bashly/library/strings.rb +0 -12
  48. data/lib/bashly/library/validations.rb +0 -9
  49. data/lib/bashly/library/yaml.rb +0 -9
@@ -0,0 +1,45 @@
1
+ require 'yaml'
2
+
3
+ module ComposeRefinements
4
+ refine Hash do
5
+ def compose(keyword = 'import')
6
+ result = {}
7
+ each do |k, v|
8
+ if k.to_s == keyword
9
+ sub = safe_load_yaml(v).compose keyword
10
+ if sub.is_a? Array
11
+ result = sub
12
+ else
13
+ result.merge! sub
14
+ end
15
+ elsif v.respond_to? :compose
16
+ result[k] = v.compose keyword
17
+ else
18
+ result[k] = v
19
+ end
20
+ end
21
+ result
22
+ end
23
+
24
+ def safe_load_yaml(path)
25
+ loaded = YAML.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}"
28
+
29
+ rescue Errno::ENOENT
30
+ raise Bashly::ConfigurationError, "Cannot find import file !txtgrn!#{path}"
31
+ end
32
+ end
33
+
34
+ refine Array do
35
+ def compose(keyword = 'import')
36
+ map do |x|
37
+ if x.respond_to? :compose
38
+ x.compose keyword
39
+ else
40
+ x
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -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
@@ -23,6 +24,7 @@ module Bashly
23
24
  long
24
25
  name
25
26
  parent_name
27
+ private
26
28
  required
27
29
  short
28
30
  validate
@@ -32,7 +34,7 @@ module Bashly
32
34
  def initialize(options)
33
35
  raise Error, "Invalid options provided" unless options.respond_to? :keys
34
36
  @options = options
35
- verify if respond_to? :verify
37
+ validate_options if respond_to? :validate_options
36
38
  end
37
39
 
38
40
  def optional
@@ -52,9 +54,9 @@ module Bashly
52
54
  respond_to?(method_name) ? options[key] : super
53
55
  end
54
56
 
55
- def respond_to?(method_name, include_private = false)
57
+ def respond_to_missing?(method_name, include_private = false)
56
58
  OPTION_KEYS.include?(method_name) || super
57
59
  end
58
60
  end
59
61
  end
60
- 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,44 +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
- return nil unless catch_all
36
-
37
- if catch_all.is_a? String
38
- "#{catch_all.upcase}..."
39
- elsif catch_all.is_a?(Hash) and catch_all['label'].is_a?(String)
40
- "#{catch_all['label'].upcase}..."
41
- else
42
- "..."
43
- end
44
- end
45
-
46
- # Returns a used defined help string for the catch_all directive
47
- def catch_all_help
48
- return nil unless catch_all
49
-
50
- if catch_all.is_a?(Hash) and catch_all['help'].is_a?(String)
51
- catch_all['help']
52
- else
53
- nil
54
- end
55
- end
56
-
57
- # Returns true if catch_all is required
58
- def catch_all_required?
59
- catch_all.is_a?(Hash) and catch_all['required']
60
- end
61
-
62
- # Returns a string suitable for catch_all Usage pattern
63
- def catch_all_usage
64
- return nil unless catch_all
65
- catch_all_required? ? catch_all_label : "[#{catch_all_label}]"
66
- end
67
-
68
- # Returns only the names of the Commands
69
- def command_names
70
- commands.map &:name
34
+ def catch_all
35
+ @catch_all ||= CatchAll.from_config options['catch_all']
71
36
  end
72
37
 
73
38
  # Returns an array of the Commands
@@ -79,40 +44,6 @@ module Bashly
79
44
  end
80
45
  end
81
46
 
82
- # Returns a flat array containing all the commands in this tree.
83
- # This includes self + children + grandchildres + ...
84
- def deep_commands
85
- result = []
86
- commands.each do |command|
87
- result << command
88
- if command.commands.any?
89
- result += command.deep_commands
90
- end
91
- end
92
- result
93
- end
94
-
95
- # Returns an array of all the default Args
96
- def default_args
97
- args.select &:default
98
- end
99
-
100
- # If any of this command's subcommands has the default option set to
101
- # true, this default command will be returned, nil otherwise.
102
- def default_command
103
- commands.find { |c| c.default }
104
- end
105
-
106
- # Returns an array of all the default Environment Variables
107
- def default_environment_variables
108
- environment_variables.select &:default
109
- end
110
-
111
- # Returns an array of all the default Flags
112
- def default_flags
113
- flags.select &:default
114
- end
115
-
116
47
  # Returns an array of EnvironmentVariables
117
48
  def environment_variables
118
49
  return [] unless options["environment_variables"]
@@ -124,7 +55,7 @@ module Bashly
124
55
  # Returns the bash filename that is expected to hold the user code
125
56
  # for this command
126
57
  def filename
127
- "#{action_name.to_underscore}_command.sh"
58
+ options["filename"] || "#{action_name.to_underscore}_command.sh"
128
59
  end
129
60
 
130
61
  # Returns an array of Flags
@@ -154,7 +85,7 @@ module Bashly
154
85
  default_content = placeholder ? "echo \"error: cannot load file\"" : ''
155
86
 
156
87
  content = if File.exist? path
157
- File.read path
88
+ File.read(path).remove_front_matter
158
89
  else
159
90
  default_content
160
91
  end
@@ -168,21 +99,6 @@ module Bashly
168
99
  options['parents'] || []
169
100
  end
170
101
 
171
- # Returns an array of all the required Arguments
172
- def required_args
173
- args.select &:required
174
- end
175
-
176
- # Returns an array of all the required EnvironmentVariables
177
- def required_environment_variables
178
- environment_variables.select &:required
179
- end
180
-
181
- # Returns an array of all the required Flags
182
- def required_flags
183
- flags.select &:required
184
- end
185
-
186
102
  # Returns trus if this is the root command (no parents)
187
103
  def root_command?
188
104
  parents.empty?
@@ -201,7 +117,7 @@ module Bashly
201
117
  result << arg.usage_string
202
118
  end
203
119
  result << "[options]" unless flags.empty?
204
- result << catch_all_usage if catch_all
120
+ result << catch_all.usage_string if catch_all.enabled?
205
121
  result.join " "
206
122
  end
207
123
 
@@ -213,27 +129,9 @@ module Bashly
213
129
  end
214
130
 
215
131
  # Raise an exception if there are some serious issues with the command
216
- # definition.
217
- def verify
218
- verify_commands if commands.any?
219
- end
220
-
221
- # Returns an array of all the args with a whitelist
222
- def whitelisted_args
223
- args.select &:allowed
224
- end
225
-
226
- # Returns an array of all the flags with a whitelist arg
227
- def whitelisted_flags
228
- flags.select &:allowed
229
- end
230
-
231
- private
232
-
233
- def verify_commands
234
- if args.any? or flags.any?
235
- raise ConfigurationError, "Error in the !txtgrn!#{full_name}!txtrst! command.\nThe !txtgrn!commands!txtrst! key cannot be at the same level as the !txtgrn!args!txtrst! or !txtgrn!flags!txtrst! keys."
236
- end
132
+ # definition. This is called by Base#initialize.
133
+ def validate_options
134
+ Bashly::ConfigValidator.new(options).validate
237
135
  end
238
136
 
239
137
  end
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.4"
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
@@ -1,6 +1,6 @@
1
1
  # :command.command_filter
2
2
  % if commands.any?
3
- action=$1
3
+ action=${1:-}
4
4
 
5
5
  case $action in
6
6
  -* )
@@ -1,7 +1,7 @@
1
1
  # :command.default_assignments
2
2
  % default_args.each do |arg|
3
- [[ -n ${args[<%= arg.name %>]} ]] || args[<%= arg.name %>]="<%= arg.default %>"
3
+ [[ -n ${args[<%= arg.name %>]:-} ]] || args[<%= arg.name %>]="<%= arg.default %>"
4
4
  % end
5
5
  % default_flags.each do |flag|
6
- [[ -n ${args[<%= flag.long %>]} ]] || args[<%= flag.long %>]="<%= flag.default %>"
6
+ [[ -n ${args[<%= flag.long %>]:-} ]] || args[<%= flag.long %>]="<%= flag.default %>"
7
7
  % end
@@ -1,6 +1,6 @@
1
- # Code here runs inside the initialize() function
2
- # Use it for anything that you need to run before any other function, like
3
- # setting environment vairables:
4
- # CONFIG_FILE=settings.ini
5
- #
6
- # Feel free to empty (but not delete) this file.
1
+ ## Code here runs inside the initialize() function
2
+ ## Use it for anything that you need to run before any other function, like
3
+ ## setting environment vairables:
4
+ ## CONFIG_FILE=settings.ini
5
+ ##
6
+ ## Feel free to empty (but not delete) this file.
@@ -1,3 +1,3 @@
1
- echo "# this file is located in '<%= Settings.source_dir %>/root_command.sh'"
1
+ echo "# this file is located in '<%= "#{Settings.source_dir}/#{filename}" %>'"
2
2
  echo "# you can edit it freely and regenerate (it will not be overwritten)"
3
3
  inspect_args
@@ -6,7 +6,7 @@ export <%= env_var.name.upcase %>="${<%= env_var.name.upcase %>:-<%= env_var.def
6
6
  % end
7
7
  % if required_environment_variables.any?
8
8
  % required_environment_variables.each do |env_var|
9
- if [[ -z "$<%= env_var.name.upcase %>" ]]; then
9
+ if [[ -z "${<%= env_var.name.upcase %>:-}" ]]; then
10
10
  printf "<%= strings[:missing_required_environment_variable] % { var: env_var.name.upcase } %>\n"
11
11
  exit 1
12
12
  fi
@@ -1,5 +1,5 @@
1
1
  # :command.fixed_flag_filter
2
- case "$1" in
2
+ case "${1:-}" in
3
3
  % if short_flag_exist? "-v"
4
4
  --version )
5
5
  % else
@@ -2,7 +2,7 @@
2
2
  initialize() {
3
3
  version="<%= version %>"
4
4
  long_usage=''
5
- set -e
5
+ <%= ENV['BASHLY_STRICT'] ? "set -euo pipefail" : "set -e" %>
6
6
 
7
7
  <%= load_user_file("initialize.sh", placeholder: false).indent 2 %>
8
8
  }
@@ -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
@@ -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
  ;;
@@ -1,4 +1,4 @@
1
1
  # :command.root_command
2
2
  root_command() {
3
- <%= load_user_file("root_command.sh").indent 2 %>
3
+ <%= load_user_file(filename).indent 2 %>
4
4
  }
@@ -1,15 +1,15 @@
1
1
  # :command.run
2
2
  run() {
3
- declare -A args
4
- declare -a other_args
5
- declare -a input
3
+ declare -A args=()
4
+ declare -a other_args=()
5
+ declare -a input=()
6
6
  normalize_input "$@"
7
7
  parse_requirements "${input[@]}"
8
8
 
9
9
  <%- condition = "if" -%>
10
10
  <%- deep_commands.each do |command| -%>
11
11
  <%= condition %> [[ $action == "<%= command.action_name %>" ]]; then
12
- if [[ ${args[--help]} ]]; then
12
+ if [[ ${args[--help]:-} ]]; then
13
13
  long_usage=yes
14
14
  <%= command.function_name %>_usage
15
15
  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 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
@@ -3,7 +3,7 @@
3
3
  printf "<%= strings[:commands] %>\n"
4
4
  % end
5
5
  % maxlen = command_names.map(&:size).max
6
- % commands.each do |command|
6
+ % commands.reject(&:private).each do |command|
7
7
  % summary = command.summary
8
8
  % summary = strings[:default_command_summary] % { summary: summary } if command.default
9
9
  % if command.group
@@ -0,0 +1,11 @@
1
+ # :command.user_filter
2
+ % if filters
3
+ % filters.each do |filter|
4
+ filter_error=$(filter_<%= filter %>)
5
+ if [[ -n $filter_error ]]; then
6
+ echo "$filter_error"
7
+ exit 1
8
+ fi
9
+
10
+ % end
11
+ % end
data/lib/bashly.rb CHANGED
@@ -9,7 +9,8 @@ requires 'bashly/concerns'
9
9
 
10
10
  requires 'bashly/settings'
11
11
  requires 'bashly/exceptions'
12
+ requires 'bashly/refinements'
12
13
  requires 'bashly/script/base'
13
14
  requires 'bashly/commands/base'
14
- requires 'bashly/library/base'
15
+ requires 'bashly/libraries/base'
15
16
  requires 'bashly'
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.0
4
+ version: 0.7.4
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-10-29 00:00:00.000000000 Z
11
+ date: 2022-02-13 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
@@ -82,28 +82,29 @@ files:
82
82
  - lib/bashly/commands/generate.rb
83
83
  - lib/bashly/commands/init.rb
84
84
  - lib/bashly/commands/preview.rb
85
+ - lib/bashly/commands/validate.rb
85
86
  - lib/bashly/concerns/asset_helper.rb
87
+ - lib/bashly/concerns/command_scopes.rb
86
88
  - lib/bashly/concerns/completions.rb
87
89
  - lib/bashly/concerns/renderable.rb
88
90
  - lib/bashly/config.rb
91
+ - lib/bashly/config_validator.rb
89
92
  - lib/bashly/exceptions.rb
90
93
  - lib/bashly/extensions/array.rb
91
94
  - lib/bashly/extensions/file.rb
92
95
  - lib/bashly/extensions/string.rb
93
- - lib/bashly/library/base.rb
94
- - lib/bashly/library/colors.rb
95
- - lib/bashly/library/completions.rb
96
- - lib/bashly/library/completions_function.rb
97
- - lib/bashly/library/completions_script.rb
98
- - lib/bashly/library/completions_yaml.rb
99
- - lib/bashly/library/config.rb
100
- - lib/bashly/library/sample.rb
101
- - lib/bashly/library/strings.rb
102
- - lib/bashly/library/validations.rb
103
- - lib/bashly/library/yaml.rb
96
+ - lib/bashly/libraries.yml
97
+ - lib/bashly/libraries/base.rb
98
+ - lib/bashly/libraries/completions.rb
99
+ - lib/bashly/libraries/completions_function.rb
100
+ - lib/bashly/libraries/completions_script.rb
101
+ - lib/bashly/libraries/completions_yaml.rb
102
+ - lib/bashly/library.rb
104
103
  - lib/bashly/message_strings.rb
104
+ - lib/bashly/refinements/compose_refinements.rb
105
105
  - lib/bashly/script/argument.rb
106
106
  - lib/bashly/script/base.rb
107
+ - lib/bashly/script/catch_all.rb
107
108
  - lib/bashly/script/command.rb
108
109
  - lib/bashly/script/environment_variable.rb
109
110
  - lib/bashly/script/flag.rb
@@ -154,6 +155,7 @@ files:
154
155
  - lib/bashly/views/command/usage_examples.erb
155
156
  - lib/bashly/views/command/usage_fixed_flags.erb
156
157
  - lib/bashly/views/command/usage_flags.erb
158
+ - lib/bashly/views/command/user_filter.erb
157
159
  - lib/bashly/views/command/user_lib.erb
158
160
  - lib/bashly/views/command/version_command.erb
159
161
  - lib/bashly/views/command/whitelist_filter.erb
@@ -187,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
189
  - !ruby/object:Gem::Version
188
190
  version: '0'
189
191
  requirements: []
190
- rubygems_version: 3.2.25
192
+ rubygems_version: 3.3.7
191
193
  signing_key:
192
194
  specification_version: 4
193
195
  summary: Bash Command Line Tool Generator
@@ -1,57 +0,0 @@
1
- module Bashly
2
- module Library
3
- class Base
4
- include AssetHelper
5
-
6
- attr_reader :target_path, :options
7
-
8
- def initialize(target_path = nil, options = nil)
9
- @target_path = target_path || Settings.source_dir
10
- @options = options || {}
11
- end
12
-
13
- def files
14
- case content
15
- when String then content_from_string content
16
- when Hash then [content]
17
- else content
18
- end
19
- end
20
-
21
- def post_install_message
22
- nil
23
- end
24
-
25
- def content
26
- raise NotImplementedError, "Please implement either #content"
27
- end
28
-
29
- private
30
-
31
- def content_from_string(string)
32
- if File.directory? asset("templates/lib/#{string}")
33
- content_for_dir string
34
- else
35
- [content_for_file(string)]
36
- end
37
- end
38
-
39
- def content_for_file(file)
40
- {
41
- path: "#{target_path}/lib/#{file}",
42
- content: asset_content("templates/lib/#{file}")
43
- }
44
- end
45
-
46
- def content_for_dir(dir)
47
- Dir[asset("templates/lib/#{dir}/*.sh")].sort.map do |file|
48
- {
49
- path: "#{target_path}/lib/#{dir}/#{File.basename file}",
50
- content: File.read(file)
51
- }
52
- end
53
- end
54
-
55
- end
56
- end
57
- end
@@ -1,9 +0,0 @@
1
- module Bashly
2
- module Library
3
- class Colors < Base
4
- def content
5
- "colors.sh"
6
- end
7
- end
8
- end
9
- end