bashly 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67c0cd0da5f37edbad28313553ac30b878edae7d2255158d940af0deb8aa0a05
4
- data.tar.gz: 6cf9bac796564e7730f3a55e6022d78a962506b418eb00cdecbe1111f3770ffb
3
+ metadata.gz: e8541b3056b57bf3b312972de9468334a8590dbf9c759a0a099de12230b164e4
4
+ data.tar.gz: 2ad5a9367d40f95fed80dcb5da2743469237f24e7935ba1d7530459adbc9dfc8
5
5
  SHA512:
6
- metadata.gz: 16eb355eb439bfc24457b184dd8255c091bb62dc1646c15e6d2842160f8848595de799cb453e54e43cdf5c2605906ed8f8c49ee21f5afda3999c9224b8d6fbc6
7
- data.tar.gz: 889722479c576c8b30c3be1081911d0a7f61613664fc146fb4a2867b65d7199a5283464cc59eb40530e2c43f8270fbaa11e7f3a3d851cedc87a71515aef235b8
6
+ metadata.gz: 1bd9c8ce895b05bae99c0fa658a23816426c10d33ea965cd0186460da5de6e088f3a1c9f6acf5969ef84022db3c10321163a0740966162646b39744855c1984f
7
+ data.tar.gz: 12a626b4e5875110003c5a8b22ea9b289e63b0e05638ba37d25c353e73b86149e65b7e5b9e5460ae5c356c971057a2cef8d73a472f09f851533d64c665b71f2d
data/README.md CHANGED
@@ -29,7 +29,12 @@ a [docker image](https://hub.docker.com/r/dannyben/bashly).
29
29
 
30
30
  ## Bashly is Sponsored By
31
31
 
32
- <a href="https://rhodecode.com/"><img src='support/img/RhodeCode-logo.png' width=280></a>
32
+ <table>
33
+ <tr>
34
+ <td><a href="https://rhodecode.com/"><img src='support/img/RhodeCode-logo.png' width=240></a></td>
35
+ <td><a href="https://decisiohealth.com/"><img src='support/img/decisio-logo.png' width=240></a></td>
36
+ </tr>
37
+ </table>
33
38
 
34
39
 
35
40
  ## Documentation
@@ -69,7 +74,7 @@ Bashly is responsible for:
69
74
  - **Bash completions**.
70
75
  - and more.
71
76
 
72
- ## Contributing / Support
77
+ ## Contributing / Support
73
78
 
74
79
  If you experience any issue, have a question or a suggestion, or if you wish
75
80
  to contribute, feel free to [open an issue][issues] or
@@ -75,7 +75,7 @@ module Bashly
75
75
  def raw_data
76
76
  @raw_data ||= begin
77
77
  result = {}
78
- Dir["#{docs_dir}/*.yml"].sort.each do |path|
78
+ Dir["#{docs_dir}/*.yml"].each do |path|
79
79
  result.merge! YAML.load_file(path)
80
80
  end
81
81
  result
@@ -89,7 +89,7 @@ module Bashly
89
89
  end
90
90
 
91
91
  def generated_files
92
- Dir["#{Settings.source_dir}/**/*.*"].sort
92
+ Dir["#{Settings.source_dir}/**/*.*"]
93
93
  end
94
94
 
95
95
  def upgrade(existing_file, library_name, *args)
@@ -125,9 +125,6 @@ module Bashly
125
125
  def create_user_files
126
126
  quiet_say "creating user files in g`#{Settings.source_dir}`"
127
127
 
128
- create_file "#{Settings.source_dir}/initialize.#{Settings.partials_extension}",
129
- command.render(:default_initialize_script)
130
-
131
128
  if command.commands.empty?
132
129
  create_root_command_file
133
130
  else
@@ -29,7 +29,7 @@ module Bashly
29
29
  end
30
30
  end
31
31
 
32
- commands.each do |command|
32
+ public_commands.each do |command|
33
33
  result.merge! command.completion_data(with_version: false)
34
34
  end
35
35
 
@@ -62,7 +62,7 @@ module Bashly
62
62
  end
63
63
 
64
64
  def completion_flag_names
65
- flags.map(&:name) + flags.map(&:short)
65
+ public_flags.map(&:name) + public_flags.map(&:short)
66
66
  end
67
67
 
68
68
  def completion_allowed_args
@@ -73,7 +73,7 @@ module Bashly
73
73
  trivial_flags = %w[--help -h]
74
74
  trivial_flags += %w[--version -v] if with_version
75
75
  all = (
76
- command_aliases + trivial_flags +
76
+ public_command_aliases + trivial_flags +
77
77
  completion_flag_names + completion_allowed_args
78
78
  )
79
79
 
@@ -100,14 +100,14 @@ module Bashly
100
100
 
101
101
  refute value['name'].match(/^-/), "#{key}.name must not start with '-'"
102
102
 
103
- refute value['required'] && value['default'], "#{key} cannot have both required and default"
103
+ refute value['required'] && value['default'], "#{key} cannot have both nub`required` and nub`default`"
104
104
  end
105
105
 
106
106
  def assert_flag(key, value)
107
107
  assert_hash key, value, keys: Script::Flag.option_keys
108
- assert value['short'] || value['long'], "#{key} must have at least one of long or short name"
108
+ assert value['short'] || value['long'], "#{key} must have at least one of nub`long` or nub`short`"
109
109
 
110
- refute value['allowed'] && value['completions'], "#{key} cannot have both allowed and completions"
110
+ refute value['allowed'] && value['completions'], "#{key} cannot have both nub`allowed` and nub`completions`"
111
111
 
112
112
  assert_optional_string "#{key}.long", value['long']
113
113
  assert_optional_string "#{key}.short", value['short']
@@ -127,18 +127,18 @@ module Bashly
127
127
  assert value['short'].match(/^-[a-zA-Z0-9]$/), "#{key}.short must be in the form of '-n'" if value['short']
128
128
  refute value['arg'].match(/^-/), "#{key}.arg must not start with '-'" if value['arg']
129
129
 
130
- refute value['required'] && value['default'], "#{key} cannot have both required and default"
130
+ refute value['required'] && value['default'], "#{key} cannot have both nub`required` and nub`default`"
131
131
 
132
132
  if value['default']
133
- assert value['arg'], "#{key}.default does not make sense without arg"
133
+ assert value['arg'], "#{key}.default does not make sense without nub`arg`"
134
134
  end
135
135
 
136
136
  if value['allowed']
137
- assert value['arg'], "#{key}.allowed does not make sense without arg"
137
+ assert value['arg'], "#{key}.allowed does not make sense without nub`arg`"
138
138
  end
139
139
 
140
140
  if value['completions']
141
- assert value['arg'], "#{key}.completions does not make sense without arg"
141
+ assert value['arg'], "#{key}.completions does not make sense without nub`arg`"
142
142
  end
143
143
  end
144
144
 
@@ -154,8 +154,8 @@ module Bashly
154
154
  def assert_command(key, value)
155
155
  assert_hash key, value, keys: Script::Command.option_keys
156
156
 
157
- refute value['commands'] && value['args'], "#{key} cannot have both commands and args"
158
- refute value['commands'] && value['catch_all'], "#{key} cannot have both commands and catch_all"
157
+ refute value['commands'] && value['args'], "#{key} cannot have both nub`commands` and nub`args`"
158
+ refute value['commands'] && value['catch_all'], "#{key} cannot have both nub`commands` and nub`catch_all`"
159
159
 
160
160
  assert_string "#{key}.name", value['name']
161
161
  assert_optional_string "#{key}.help", value['help']
@@ -202,7 +202,7 @@ module Bashly
202
202
  end
203
203
 
204
204
  if value['expose']
205
- assert value['commands'], "#{key}.expose makes no sense without commands"
205
+ assert value['commands'], "#{key}.expose makes no sense without nub`commands`"
206
206
  end
207
207
 
208
208
  if key == 'root'
@@ -0,0 +1,6 @@
1
+ ## initialize hook
2
+ ##
3
+ ## Any code here will be placed inside the `initialize()` function and called
4
+ ## before running anything else.
5
+ ##
6
+ ## You can safely delete this file if you do not need it.
@@ -30,8 +30,10 @@ help:
30
30
  handler: Bashly::Libraries::Help
31
31
 
32
32
  hooks:
33
- help: Add placeholders for before/after hooks which are executed before/after any command.
33
+ help: Add placeholders for initialize/before/after hooks which are executed on script initialization, and before/after any command.
34
34
  files:
35
+ - source: "hooks/initialize.sh"
36
+ target: "%{user_source_dir}/initialize.%{user_ext}"
35
37
  - source: "hooks/before.sh"
36
38
  target: "%{user_source_dir}/before.%{user_ext}"
37
39
  - source: "hooks/after.sh"
@@ -223,6 +223,11 @@ module Bashly
223
223
  commands.reject(&:private)
224
224
  end
225
225
 
226
+ # Returns a full list of the public Command names and aliases combined
227
+ def public_command_aliases
228
+ public_commands.map(&:aliases).flatten
229
+ end
230
+
226
231
  # Returns only environment variables that are not private
227
232
  def public_environment_variables
228
233
  environment_variables.reject(&:private)
@@ -297,7 +302,7 @@ module Bashly
297
302
  # This is meant to provide the user with the ability to add custom
298
303
  # functions
299
304
  def user_lib
300
- @user_lib ||= Dir["#{Settings.full_lib_dir}/**/*.#{Settings.partials_extension}"].sort
305
+ @user_lib ||= Dir["#{Settings.full_lib_dir}/**/*.#{Settings.partials_extension}"]
301
306
  end
302
307
 
303
308
  # Returns an array of all the args with a whitelist
@@ -56,9 +56,9 @@ module Bashly
56
56
  end
57
57
 
58
58
  def strict_string
59
- if Settings.strict.is_a? String
60
- Settings.strict
61
- elsif Settings.strict
59
+ if strict.is_a? String
60
+ strict
61
+ elsif strict
62
62
  'set -euo pipefail'
63
63
  else
64
64
  'set -e'
@@ -101,7 +101,13 @@ module Bashly
101
101
  end
102
102
 
103
103
  def user_settings_path
104
- ENV['BASHLY_SETTINGS_PATH'] || 'settings.yml'
104
+ @user_settings_path ||= if ENV['BASHLY_SETTINGS_PATH']
105
+ ENV['BASHLY_SETTINGS_PATH']
106
+ elsif File.exist? 'bashly-settings.yml'
107
+ 'bashly-settings.yml'
108
+ else
109
+ 'settings.yml'
110
+ end
105
111
  end
106
112
 
107
113
  def defsult_settings
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.4'
3
3
  end
@@ -6,7 +6,7 @@ if default_args.any? or default_flags.any?
6
6
  end
7
7
 
8
8
  default_flags.each do |flag|
9
- > [[ -n ${args['{{ flag.long }}']:-} ]] || args['{{ flag.long }}']="{{ flag.default }}"
9
+ > [[ -n ${args['{{ flag.name }}']:-} ]] || args['{{ flag.name }}']="{{ flag.default }}"
10
10
  end
11
11
 
12
12
  >
@@ -4,4 +4,4 @@ if default_environment_variables.any?
4
4
  default_environment_variables.each do |env_var|
5
5
  > export {{ env_var.name.upcase }}="${<%= env_var.name.upcase %>:-<%= env_var.default %>}"
6
6
  end
7
- end
7
+ end
@@ -4,13 +4,16 @@
4
4
  > version="<%= version %>"
5
5
  > long_usage=''
6
6
  > {{ Settings.strict_string }}
7
- >
8
7
 
9
8
  if root_command?
9
+ >
10
10
  = render(:environment_variables_default).indent 2
11
11
  end
12
12
 
13
- = load_user_file("initialize", placeholder: false).indent 2
13
+ if user_file_exist?('initialize')
14
+ >
15
+ = load_user_file('initialize').indent 2
16
+ end
14
17
 
15
18
  > }
16
19
  >
@@ -2,7 +2,7 @@ if required_flags.any?
2
2
  = view_marker
3
3
 
4
4
  required_flags.each do |flag|
5
- > if [[ -z ${args['{{ flag.long }}']+x} ]]; then
5
+ > if [[ -z ${args['{{ flag.name }}']+x} ]]; then
6
6
  > printf "{{ strings[:missing_required_flag] % { usage: flag.usage_string } }}\n" >&2
7
7
  > exit 1
8
8
  > fi
@@ -12,7 +12,7 @@ if whitelisted_args.any? or whitelisted_flags.any?
12
12
  > done
13
13
 
14
14
  else
15
- > if [[ ! ${args['{{ arg.name }}']} =~ ^({{ arg.allowed.join '|' }})$ ]]; then
15
+ > if [[ -n ${args['{{ arg.name }}']} ]] && [[ ! ${args['{{ arg.name }}']} =~ ^({{ arg.allowed.join '|' }})$ ]]; then
16
16
  > printf "%s\n" "{{ strings[:disallowed_argument] % { name: arg.name, allowed: arg.allowed.join(', ') } }}" >&2
17
17
  > exit 1
18
18
  > fi
@@ -31,7 +31,7 @@ if whitelisted_args.any? or whitelisted_flags.any?
31
31
  > done
32
32
 
33
33
  else
34
- > if [[ ! ${args['{{ flag.name }}']} =~ ^({{ flag.allowed.join '|' }})$ ]]; then
34
+ > if [[ ${args['{{ flag.name }}']} ]] && [[ ! ${args['{{ flag.name }}']} =~ ^({{ flag.allowed.join '|' }})$ ]]; then
35
35
  > printf "%s\n" "{{ strings[:disallowed_flag] % { name: flag.name, allowed: flag.allowed.join(', ') } }}" >&2
36
36
  > exit 1
37
37
  > fi
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: 1.0.2
4
+ version: 1.0.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: 2023-03-23 00:00:00.000000000 Z
11
+ date: 2023-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -157,6 +157,7 @@ files:
157
157
  - lib/bashly/libraries/help/help_command.sh
158
158
  - lib/bashly/libraries/hooks/after.sh
159
159
  - lib/bashly/libraries/hooks/before.sh
160
+ - lib/bashly/libraries/hooks/initialize.sh
160
161
  - lib/bashly/libraries/lib/sample_function.sh
161
162
  - lib/bashly/libraries/libraries.yml
162
163
  - lib/bashly/libraries/settings/settings.yml
@@ -192,7 +193,6 @@ files:
192
193
  - lib/bashly/views/command/command_filter.gtx
193
194
  - lib/bashly/views/command/command_functions.gtx
194
195
  - lib/bashly/views/command/default_assignments.gtx
195
- - lib/bashly/views/command/default_initialize_script.gtx
196
196
  - lib/bashly/views/command/default_root_script.gtx
197
197
  - lib/bashly/views/command/default_script.gtx
198
198
  - lib/bashly/views/command/dependencies_filter.gtx
@@ -255,14 +255,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
255
255
  requirements:
256
256
  - - ">="
257
257
  - !ruby/object:Gem::Version
258
- version: 2.7.0
258
+ version: '3.0'
259
259
  required_rubygems_version: !ruby/object:Gem::Requirement
260
260
  requirements:
261
261
  - - ">="
262
262
  - !ruby/object:Gem::Version
263
263
  version: '0'
264
264
  requirements: []
265
- rubygems_version: 3.4.8
265
+ rubygems_version: 3.3.26
266
266
  signing_key:
267
267
  specification_version: 4
268
268
  summary: Bash Command Line Tool Generator
@@ -1,7 +0,0 @@
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 variables:
4
- > ## CONFIG_FILE=settings.ini
5
- > ##
6
- > ## Feel free to empty (but not delete) this file.
7
- >