bashly 0.7.6 → 0.7.7

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: 98fc7fa0a703a1bdef30afdd0e4ff4b5a4d5cc6025380e4aa952aeb77c0b9aa8
4
- data.tar.gz: 2d148783f32363862d4039b424ef8ddd5fa050c849bbe742f7195096cdf78830
3
+ metadata.gz: 187dd845a74d432185c8c53460836cf856251384c750cc4c0e4f2d2d894946c9
4
+ data.tar.gz: 1b4f519c55758ca113be95a0149ca8050481e0a57c64ba5a01ce1596d0aa1035
5
5
  SHA512:
6
- metadata.gz: 309afb5a2c73c170fafacf9ab02066bd1e4d29934c6a94f6518328dbfd246a8679fc0e8ffc51e00a3359adc90cc25d1d9433e8944db7def0cf806ac5dd99d89d
7
- data.tar.gz: fd16952f25275a54d0aaaf990b00575a19fc5d38cab3206918722240466df9e1ae7f55f439ccfc1129ca5d8733181583fbd4280bf18cb42615119a9122f666d8
6
+ metadata.gz: 92a1416625eeb9d8f8e3d3b5c7b1cfaadf0b43b5d7e329af5f89173f82eb1f5d9bda10fa33d486d5e86262a8858b36ff5a8e794271d10ec57b8191f0ed96dd06
7
+ data.tar.gz: f52974cfdabc844b12ba046b155fe77dd598f5dcbfd3d7dbbf6e7b7dd0103cefb006e08cfebc0ecb93a811748e523afe18a57883ce6e71bdb080a7ec0cf138ed
@@ -32,6 +32,7 @@ module Bashly
32
32
  example "bashly add comp script completions.bash"
33
33
 
34
34
  environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
35
+ environment "BASHLY_LIB_DIR", "The path to use for creating the library files, relative to the source dir [default: lib]"
35
36
 
36
37
  def strings_command
37
38
  add_lib 'strings'
@@ -5,6 +5,12 @@ module Bashly
5
5
  module Commands
6
6
  class Base < MisterBin::Command
7
7
  include AssetHelper
8
+
9
+ def validate_config
10
+ config = Config.new "#{Settings.source_dir}/bashly.yml"
11
+ validator = ConfigValidator.new config
12
+ validator.validate
13
+ end
8
14
  end
9
15
  end
10
16
  end
@@ -13,12 +13,14 @@ module Bashly
13
13
 
14
14
  environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
15
15
  environment "BASHLY_TARGET_DIR", "The path to use for creating the bash script [default: .]"
16
+ environment "BASHLY_LIB_DIR", "The path to use for upgrading library files, relative to the source dir [default: lib]"
16
17
  environment "BASHLY_STRICT", "When not empty, enable bash strict mode (set -euo pipefail)"
17
18
 
18
19
  example "bashly generate --force"
19
20
  example "bashly generate --wrap my_function"
20
21
 
21
22
  def run
23
+ validate_config
22
24
  create_user_files
23
25
  upgrade_libs if args['--upgrade']
24
26
  create_master_script
@@ -9,9 +9,7 @@ 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
- config = Config.new "#{Settings.source_dir}/bashly.yml"
13
- validator = ConfigValidator.new config
14
- validator.validate
12
+ validate_config
15
13
  say "!txtgrn!OK"
16
14
  end
17
15
  end
data/lib/bashly/config.rb CHANGED
@@ -10,7 +10,7 @@ module Bashly
10
10
 
11
11
  def self.new(config)
12
12
  if config.is_a? String
13
- YAML.load_file(config).compose
13
+ YAML.properly_load_file(config).compose
14
14
  else
15
15
  config
16
16
  end
@@ -84,6 +84,8 @@ module Bashly
84
84
  assert_array "#{key}.allowed", value['allowed'], of: :string
85
85
 
86
86
  refute value['name'].match(/^-/), "#{key}.name must not start with '-'"
87
+
88
+ refute value['required'] && value['default'], "#{key} cannot have both required and default"
87
89
  end
88
90
 
89
91
  def assert_flag(key, value)
@@ -104,6 +106,16 @@ module Bashly
104
106
  assert value['long'].match(/^--[a-zA-Z0-9_\-]+$/), "#{key}.long must be in the form of '--name'" if value['long']
105
107
  assert value['short'].match(/^-[a-zA-Z0-9]$/), "#{key}.short must be in the form of '-n'" if value['short']
106
108
  refute value['arg'].match(/^-/), "#{key}.arg must not start with '-'" if value['arg']
109
+
110
+ refute value['required'] && value['default'], "#{key} cannot have both required and default"
111
+
112
+ if value['default']
113
+ assert value['arg'], "#{key}.default does not make sense without arg"
114
+ end
115
+
116
+ if value['allowed']
117
+ assert value['arg'], "#{key}.allowed does not make sense without arg"
118
+ end
107
119
  end
108
120
 
109
121
  def assert_env_var(key, value)
@@ -140,6 +152,16 @@ module Bashly
140
152
  assert_array "#{key}.filters", value['filters'], of: :string
141
153
  assert_array "#{key}.environment_variables", value['environment_variables'], of: :env_var
142
154
  assert_array "#{key}.examples", value['examples'], of: :string
155
+
156
+ if key == "root"
157
+ refute value['short'], "#{key}.short makes no sense"
158
+ refute value['group'], "#{key}.group makes no sense"
159
+ refute value['default'], "#{key}.default makes no sense"
160
+ refute value['private'], "#{key}.private makes no sense"
161
+ else
162
+ refute value['version'], "#{key}.version makes no sense"
163
+ refute value['extensible'], "#{key}.extensible makes no sense"
164
+ end
143
165
  end
144
166
  end
145
167
  end
@@ -0,0 +1,8 @@
1
+ module YAML
2
+ # This awkward patch is due to https://bugs.ruby-lang.org/issues/17866
3
+ def self.properly_load_file(path)
4
+ YAML.load_file path, aliases: true
5
+ rescue ArgumentError
6
+ YAML.load_file path
7
+ end
8
+ end
@@ -4,7 +4,7 @@ module Bashly
4
4
  def files
5
5
  [
6
6
  {
7
- path: "#{Settings.source_dir}/lib/#{function_name}.sh",
7
+ path: "#{Settings.full_lib_dir}/#{function_name}.sh",
8
8
  content: completions_function_code(function_name)
9
9
  }
10
10
  ]
@@ -1,22 +1,22 @@
1
1
  colors:
2
2
  files:
3
3
  - source: "templates/lib/colors.sh"
4
- target: "%{user_source_dir}/lib/colors.sh"
4
+ target: "%{user_lib_dir}/colors.sh"
5
5
 
6
6
  config:
7
7
  files:
8
8
  - source: "templates/lib/config.sh"
9
- target: "%{user_source_dir}/lib/config.sh"
9
+ target: "%{user_lib_dir}/config.sh"
10
10
 
11
11
  yaml:
12
12
  files:
13
13
  - source: "templates/lib/yaml.sh"
14
- target: "%{user_source_dir}/lib/yaml.sh"
14
+ target: "%{user_lib_dir}/yaml.sh"
15
15
 
16
16
  lib:
17
17
  files:
18
18
  - source: "templates/lib/sample_function.sh"
19
- target: "%{user_source_dir}/lib/sample_function.sh"
19
+ target: "%{user_lib_dir}/sample_function.sh"
20
20
 
21
21
  strings:
22
22
  files:
@@ -41,13 +41,13 @@ test:
41
41
  validations:
42
42
  files:
43
43
  - source: "templates/lib/validations/validate_dir_exists.sh"
44
- target: "%{user_source_dir}/lib/validations/validate_dir_exists.sh"
44
+ target: "%{user_lib_dir}/validations/validate_dir_exists.sh"
45
45
  - source: "templates/lib/validations/validate_file_exists.sh"
46
- target: "%{user_source_dir}/lib/validations/validate_file_exists.sh"
46
+ target: "%{user_lib_dir}/validations/validate_file_exists.sh"
47
47
  - source: "templates/lib/validations/validate_integer.sh"
48
- target: "%{user_source_dir}/lib/validations/validate_integer.sh"
48
+ target: "%{user_lib_dir}/validations/validate_integer.sh"
49
49
  - source: "templates/lib/validations/validate_not_empty.sh"
50
- target: "%{user_source_dir}/lib/validations/validate_not_empty.sh"
50
+ target: "%{user_lib_dir}/validations/validate_not_empty.sh"
51
51
 
52
52
  completions: :CompletionsFunction
53
53
  completions_script: :CompletionsScript
@@ -6,7 +6,7 @@ module Bashly
6
6
  end
7
7
 
8
8
  def config
9
- @config ||= YAML.load_file(config_path)
9
+ @config ||= YAML.properly_load_file(config_path)
10
10
  end
11
11
 
12
12
  def config_path
@@ -59,7 +59,8 @@ module Bashly
59
59
  def target_file_args
60
60
  {
61
61
  user_source_dir: Settings.source_dir,
62
- user_target_dir: Settings.target_dir
62
+ user_target_dir: Settings.target_dir,
63
+ user_lib_dir: Settings.full_lib_dir,
63
64
  }
64
65
  end
65
66
  end
@@ -13,7 +13,7 @@ module Bashly
13
13
  private
14
14
 
15
15
  def values!
16
- defaults = YAML.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,7 +23,7 @@ module Bashly
23
23
 
24
24
  def project_strings!
25
25
  if File.exist? project_strings_path
26
- YAML.load_file project_strings_path
26
+ YAML.properly_load_file project_strings_path
27
27
  else
28
28
  {}
29
29
  end
@@ -22,7 +22,7 @@ module ComposeRefinements
22
22
  end
23
23
 
24
24
  def safe_load_yaml(path)
25
- loaded = YAML.load_file path
25
+ loaded = YAML.properly_load_file path
26
26
  return loaded if loaded.is_a? Array or loaded.is_a? Hash
27
27
  raise Bashly::ConfigurationError, "Cannot find a valid YAML in !txtgrn!#{path}"
28
28
 
@@ -36,7 +36,6 @@ module Bashly
36
36
  def initialize(options)
37
37
  raise Error, "Invalid options provided" unless options.respond_to? :keys
38
38
  @options = options
39
- validate_options if respond_to? :validate_options
40
39
  end
41
40
 
42
41
  def optional
@@ -125,13 +125,7 @@ module Bashly
125
125
  # This is meant to provide the user with the ability to add custom
126
126
  # functions
127
127
  def user_lib
128
- @user_lib ||= Dir["#{Settings.source_dir}/lib/**/*.sh"].sort
129
- end
130
-
131
- # Raise an exception if there are some serious issues with the command
132
- # definition. This is called by Base#initialize.
133
- def validate_options
134
- Bashly::ConfigValidator.new(options).validate
128
+ @user_lib ||= Dir["#{Settings.full_lib_dir}/**/*.sh"].sort
135
129
  end
136
130
 
137
131
  end
@@ -1,7 +1,7 @@
1
1
  module Bashly
2
2
  class Settings
3
3
  class << self
4
- attr_writer :source_dir, :target_dir
4
+ attr_writer :source_dir, :target_dir, :lib_dir, :strict
5
5
 
6
6
  def source_dir
7
7
  @source_dir ||= ENV['BASHLY_SOURCE_DIR'] || 'src'
@@ -10,6 +10,18 @@ module Bashly
10
10
  def target_dir
11
11
  @target_dir ||= ENV['BASHLY_TARGET_DIR'] || '.'
12
12
  end
13
+
14
+ def lib_dir
15
+ @lib_dir ||= ENV['BASHLY_LIB_DIR'] || 'lib'
16
+ end
17
+
18
+ def strict
19
+ @strict ||= ENV['BASHLY_STRICT']
20
+ end
21
+
22
+ def full_lib_dir
23
+ "#{source_dir}/#{lib_dir}"
24
+ end
13
25
  end
14
26
  end
15
27
  end
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = "0.7.6"
2
+ VERSION = "0.7.7"
3
3
  end
@@ -2,7 +2,7 @@
2
2
  initialize() {
3
3
  version="<%= version %>"
4
4
  long_usage=''
5
- <%= ENV['BASHLY_STRICT'] ? "set -euo pipefail" : "set -e" %>
5
+ <%= Settings.strict ? "set -euo pipefail" : "set -e" %>
6
6
 
7
7
  <%= load_user_file("initialize.sh", placeholder: false).indent 2 %>
8
8
  }
@@ -6,8 +6,18 @@ if [[ ! ${args[<%= arg.name %>]} =~ ^(<%= arg.allowed.join '|' %>)$ ]]; then
6
6
  fi
7
7
  % end
8
8
  % whitelisted_flags.each do |flag|
9
+ % if flag.repeatable
10
+ eval "input_array=(${args[<%= flag.name %>]})"
11
+ for i in "${input_array[@]}"; do
12
+ if [[ ! $i =~ ^(<%= flag.allowed.join '|' %>)$ ]]; then
13
+ printf "%s\n" "<%= strings[:disallowed_flag] % { name: flag.name, allowed: flag.allowed.join(', ') } %>"
14
+ exit 1
15
+ fi
16
+ done
17
+ % else
9
18
  if [[ ! ${args[<%= flag.name %>]} =~ ^(<%= flag.allowed.join '|' %>)$ ]]; then
10
19
  printf "%s\n" "<%= strings[:disallowed_flag] % { name: flag.name, allowed: flag.allowed.join(', ') } %>"
11
20
  exit 1
12
21
  fi
22
+ % end
13
23
  % end
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env bash
2
- # This script was generated by bashly (https://github.com/DannyBen/bashly)
2
+ # This script was generated by bashly <%= Bashly::VERSION %> (https://bashly.dannyb.co)
3
3
  # Modifying it manually is not recommended
4
4
 
data/lib/bashly.rb CHANGED
@@ -7,6 +7,7 @@ end
7
7
 
8
8
  requires 'bashly/concerns'
9
9
 
10
+ requires 'bashly/extensions'
10
11
  requires 'bashly/settings'
11
12
  requires 'bashly/exceptions'
12
13
  requires 'bashly/refinements'
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.6
4
+ version: 0.7.7
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-02-18 00:00:00.000000000 Z
11
+ date: 2022-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -93,6 +93,7 @@ files:
93
93
  - lib/bashly/extensions/array.rb
94
94
  - lib/bashly/extensions/file.rb
95
95
  - lib/bashly/extensions/string.rb
96
+ - lib/bashly/extensions/yaml.rb
96
97
  - lib/bashly/libraries.yml
97
98
  - lib/bashly/libraries/base.rb
98
99
  - lib/bashly/libraries/completions.rb
@@ -191,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
192
  - !ruby/object:Gem::Version
192
193
  version: '0'
193
194
  requirements: []
194
- rubygems_version: 3.3.7
195
+ rubygems_version: 3.2.15
195
196
  signing_key:
196
197
  specification_version: 4
197
198
  summary: Bash Command Line Tool Generator