bashly 0.9.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 51f9de0e5f94e6af9e792e567704aeb3b7a48b269fc376657244d6801210f3b9
4
- data.tar.gz: 5b353f9e94ce7b164a121f824ee846e55403bc54a6237fed29e6fa39d19ce6ee
3
+ metadata.gz: e1139c7453fff329c05879511103b80b6a89a76896a9d0cb3f5cad016d224b15
4
+ data.tar.gz: acda8a068081a04a32218be7ddfee8cad1612b3dfafd9e1465170fd9cded32db
5
5
  SHA512:
6
- metadata.gz: 58becd123b9fa29d72dbb10a5812a16037a5d6dd626a8b9cbf3b94eee55c6299220e7b7cba770b1d0eae620869cd9c6e909fc1708c3ccf28a482d85e159a2d02
7
- data.tar.gz: c10390d56a7b56ccc0c3e369c5365a40d7cda17933de43621185e3488d2149f519fc9ff7a1510665562af1a8efbae7653a1185ba67669a6bf6a2b54552fdccdb
6
+ metadata.gz: 61247ecd7b928a4babdbf307004424ffa060c567a16b4eb4b062c59e51eb9812f3469981ead958bb4f08aee8cb7ecd86a32a830f6102211012540eac0b878fd4
7
+ data.tar.gz: 606e5df99d98e9853ed25a7fd516a807a90f1c40d7f19ac2ab1b8f3388a82919dd59af3b291d8de7b866d88cdcb8b1fec7883bd258b80c04f137b1729e58aca1
@@ -34,8 +34,11 @@ module Bashly
34
34
  command 'comp', 'Generate a bash completions script or function.'
35
35
  command 'config', 'Add standard functions for handling INI files to the lib directory.'
36
36
  command 'help', 'Add a help command, in addition to the standard --help flag.'
37
- command 'lib', 'Create the additional lib directory for additional user scripts. All *.sh scripts in this ' \
38
- 'folder will be included in the final bash script.'
37
+ command 'lib', <<~USAGE
38
+ Create the lib directory for any additional user scripts.
39
+ All *.sh scripts in this directory will be included in the final bash script.
40
+ Note that if you configured a different partials_extension, then the extensions of the files in this directory need to match.
41
+ USAGE
39
42
 
40
43
  command 'settings', 'Copy a sample settings.yml file to your project, allowing you to customize some ' \
41
44
  'bashly options.'
@@ -130,7 +130,8 @@ module Bashly
130
130
  def create_user_files
131
131
  quiet_say "creating user files in !txtgrn!#{Settings.source_dir}"
132
132
 
133
- create_file "#{Settings.source_dir}/initialize.sh", command.render(:default_initialize_script)
133
+ create_file "#{Settings.source_dir}/initialize.#{Settings.partials_extension}",
134
+ command.render(:default_initialize_script)
134
135
 
135
136
  if command.commands.empty?
136
137
  create_root_command_file
@@ -37,6 +37,12 @@ module Bashly
37
37
  assert_boolean "#{key}.required", value['required']
38
38
  end
39
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
+
40
46
  def assert_dependencies(key, value)
41
47
  return unless value
42
48
 
@@ -145,7 +151,7 @@ module Bashly
145
151
  assert_optional_string "#{key}.function", value['function']
146
152
 
147
153
  assert_boolean "#{key}.private", value['private']
148
- assert_boolean "#{key}.default", value['default']
154
+ assert_default_command "#{key}.default", value['default']
149
155
  assert_expose "#{key}.expose", value['expose']
150
156
  assert_version "#{key}.version", value['version']
151
157
  assert_catch_all "#{key}.catch_all", value['catch_all']
@@ -171,10 +177,6 @@ module Bashly
171
177
  "#{key}.function must contain lowercase alphanumeric characters and underscores only"
172
178
  end
173
179
 
174
- if value['default']
175
- assert value['args'], "#{key}.default makes no sense without args"
176
- end
177
-
178
180
  if value['catch_all'] && value['args']
179
181
  repeatable_arg = value['args'].find { |a| a['repeatable'] }&.dig 'name'
180
182
  refute repeatable_arg, "#{key}.catch_all makes no sense with repeatable arg (#{repeatable_arg})"
@@ -4,7 +4,7 @@ module Bashly
4
4
  def files
5
5
  [
6
6
  {
7
- path: "#{Settings.full_lib_dir}/#{function_name}.sh",
7
+ path: "#{Settings.full_lib_dir}/#{function_name}.#{Settings.partials_extension}",
8
8
  content: completions_function_code(function_name),
9
9
  },
10
10
  ]
@@ -6,7 +6,7 @@ module Bashly
6
6
  def files
7
7
  [
8
8
  {
9
- path: "#{Settings.source_dir}/help_command.sh",
9
+ path: "#{Settings.source_dir}/help_command.#{Settings.partials_extension}",
10
10
  content: help_command,
11
11
  },
12
12
  ]
@@ -1,7 +1,7 @@
1
1
  colors:
2
2
  files:
3
3
  - source: "templates/lib/colors.sh"
4
- target: "%{user_lib_dir}/colors.sh"
4
+ target: "%{user_lib_dir}/colors.%{user_ext}"
5
5
 
6
6
  completions: :CompletionsFunction
7
7
  completions_script: :CompletionsScript
@@ -10,14 +10,14 @@ completions_yaml: :CompletionsYAML
10
10
  config:
11
11
  files:
12
12
  - source: "templates/lib/config.sh"
13
- target: "%{user_lib_dir}/config.sh"
13
+ target: "%{user_lib_dir}/config.%{user_ext}"
14
14
 
15
15
  help: :Help
16
16
 
17
17
  lib:
18
18
  files:
19
19
  - source: "templates/lib/sample_function.sh"
20
- target: "%{user_lib_dir}/sample_function.sh"
20
+ target: "%{user_lib_dir}/sample_function.%{user_ext}"
21
21
 
22
22
  settings:
23
23
  files:
@@ -46,15 +46,15 @@ test:
46
46
  validations:
47
47
  files:
48
48
  - source: "templates/lib/validations/validate_dir_exists.sh"
49
- target: "%{user_lib_dir}/validations/validate_dir_exists.sh"
49
+ target: "%{user_lib_dir}/validations/validate_dir_exists.%{user_ext}"
50
50
  - source: "templates/lib/validations/validate_file_exists.sh"
51
- target: "%{user_lib_dir}/validations/validate_file_exists.sh"
51
+ target: "%{user_lib_dir}/validations/validate_file_exists.%{user_ext}"
52
52
  - source: "templates/lib/validations/validate_integer.sh"
53
- target: "%{user_lib_dir}/validations/validate_integer.sh"
53
+ target: "%{user_lib_dir}/validations/validate_integer.%{user_ext}"
54
54
  - source: "templates/lib/validations/validate_not_empty.sh"
55
- target: "%{user_lib_dir}/validations/validate_not_empty.sh"
55
+ target: "%{user_lib_dir}/validations/validate_not_empty.%{user_ext}"
56
56
 
57
57
  yaml:
58
58
  files:
59
59
  - source: "templates/lib/yaml.sh"
60
- target: "%{user_lib_dir}/yaml.sh"
60
+ target: "%{user_lib_dir}/yaml.%{user_ext}"
@@ -63,6 +63,7 @@ module Bashly
63
63
  user_source_dir: Settings.source_dir,
64
64
  user_target_dir: Settings.target_dir,
65
65
  user_lib_dir: Settings.full_lib_dir,
66
+ user_ext: Settings.partials_extension,
66
67
  }
67
68
  end
68
69
  end
@@ -156,7 +156,7 @@ module Bashly
156
156
  # Returns the bash filename that is expected to hold the user code
157
157
  # for this command
158
158
  def filename
159
- options['filename'] || "#{action_name.to_underscore}_command.sh"
159
+ options['filename'] || "#{action_name.to_underscore}_command.#{Settings.partials_extension}"
160
160
  end
161
161
 
162
162
  # Returns an array of Flags
@@ -281,7 +281,7 @@ module Bashly
281
281
  # This is meant to provide the user with the ability to add custom
282
282
  # functions
283
283
  def user_lib
284
- @user_lib ||= Dir["#{Settings.full_lib_dir}/**/*.sh"].sort
284
+ @user_lib ||= Dir["#{Settings.full_lib_dir}/**/*.#{Settings.partials_extension}"].sort
285
285
  end
286
286
 
287
287
  # Returns an array of all the args with a whitelist
@@ -49,7 +49,7 @@ module Bashly
49
49
  end
50
50
 
51
51
  def custom_header_path
52
- @custom_header_path ||= "#{Settings.source_dir}/header.sh"
52
+ @custom_header_path ||= "#{Settings.source_dir}/header.#{Settings.partials_extension}"
53
53
  end
54
54
  end
55
55
  end
@@ -3,47 +3,51 @@ module Bashly
3
3
  class << self
4
4
  include AssetHelper
5
5
 
6
- attr_writer :compact_short_flags, :source_dir, :target_dir,
7
- :lib_dir, :strict, :tab_indent
6
+ attr_writer :compact_short_flags, :lib_dir, :partials_extension,
7
+ :source_dir, :strict, :tab_indent, :target_dir
8
8
 
9
- def source_dir
10
- @source_dir ||= get :source_dir
9
+ def compact_short_flags
10
+ @compact_short_flags ||= get :compact_short_flags
11
11
  end
12
12
 
13
- def target_dir
14
- @target_dir ||= get :target_dir
13
+ def env
14
+ @env ||= get(:env)&.to_sym
15
15
  end
16
16
 
17
- def lib_dir
18
- @lib_dir ||= get :lib_dir
17
+ def env=(value)
18
+ @env = value&.to_sym
19
19
  end
20
20
 
21
- def strict
22
- @strict ||= get :strict
21
+ def full_lib_dir
22
+ "#{source_dir}/#{lib_dir}"
23
23
  end
24
24
 
25
- def tab_indent
26
- @tab_indent ||= get :tab_indent
25
+ def lib_dir
26
+ @lib_dir ||= get :lib_dir
27
27
  end
28
28
 
29
- def compact_short_flags
30
- @compact_short_flags ||= get :compact_short_flags
29
+ def partials_extension
30
+ @partials_extension ||= get :partials_extension
31
31
  end
32
32
 
33
- def env
34
- @env ||= get(:env)&.to_sym
33
+ def production?
34
+ env == :production
35
35
  end
36
36
 
37
- def env=(value)
38
- @env = value&.to_sym
37
+ def source_dir
38
+ @source_dir ||= get :source_dir
39
39
  end
40
40
 
41
- def production?
42
- env == :production
41
+ def strict
42
+ @strict ||= get :strict
43
43
  end
44
44
 
45
- def full_lib_dir
46
- "#{source_dir}/#{lib_dir}"
45
+ def tab_indent
46
+ @tab_indent ||= get :tab_indent
47
+ end
48
+
49
+ def target_dir
50
+ @target_dir ||= get :target_dir
47
51
  end
48
52
 
49
53
  private
@@ -30,3 +30,6 @@ compact_short_flags: true
30
30
  # - production generate a smaller script, without file markers
31
31
  # - development generate with file markers
32
32
  env: development
33
+
34
+ # The extension to use when reading/writing partial script snippets.
35
+ partials_extension: sh
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = '0.9.0'
2
+ VERSION = '0.9.1'
3
3
  end
@@ -1,10 +1,13 @@
1
1
  = view_marker
2
2
 
3
- > "")
4
- > {{ function_name }}_usage >&2
5
- > exit 1
6
- > ;;
7
- >
3
+ if !default_command || default_command.default != 'force'
4
+ > "")
5
+ > {{ function_name }}_usage >&2
6
+ > exit 1
7
+ > ;;
8
+ >
9
+ end
10
+
8
11
  > *)
9
12
 
10
13
  if default_command
@@ -4,8 +4,7 @@ if commands.any?
4
4
  > action=${1:-}
5
5
  >
6
6
  > case $action in
7
- > -*)
8
- > ;;
7
+ > -*) ;;
9
8
  >
10
9
 
11
10
  commands.each do |command|
@@ -5,8 +5,7 @@ if dependencies
5
5
  > if ! command -v {{ dependency }} >/dev/null 2>&1; then
6
6
  > printf "{{ strings[:missing_dependency] % { dependency: dependency } }}\n" >&2
7
7
  if message and !message.empty?
8
- > # shellcheck disable=SC2059
9
- > printf "{{ message }}\n" >&2
8
+ > printf "%s\n" "{{ message }}" >&2
10
9
  end
11
10
  > exit 1
12
11
  > fi
@@ -21,9 +21,11 @@ deep_commands.each do |command|
21
21
  >
22
22
  end
23
23
 
24
- > "root")
25
- > root_command
26
- > ;;
24
+ if commands.empty?
25
+ > "root")
26
+ > root_command
27
+ > ;;
28
+ end
27
29
  >
28
30
  > esac
29
31
  > }
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.9.0
4
+ version: 0.9.1
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-12-02 00:00:00.000000000 Z
11
+ date: 2022-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: completely