bashly 1.0.1 → 1.0.3

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: e17bc036331958bd9ff237d93e287c911bc00c85b33628a4b867dd2e69c818fe
4
- data.tar.gz: 236e3ba5f96e9f89fce4b77d95adf68a3030ef31d3d59a857ad0477aa871b171
3
+ metadata.gz: 2b90c79b66c9396dc7fda026e19761818e7db33c8b19b0e0501486b3cdf7f1e0
4
+ data.tar.gz: be2b5e3ae996189263e604421910ebc3b8a597e3cf9c525cf19b94e2e4434fd3
5
5
  SHA512:
6
- metadata.gz: 55f3361b37d963fcd33ad97b9204ce201517b9249522e4d4fb501c4502e8ba31ef5049c629d6bf5e82d85854ca64de1435f2604a01e12913ba5a56de346994ee
7
- data.tar.gz: 23832fbbfbbaec41862b61eeb75ef0a34598db175192d09c3f1ea738bf1bd81aa11d855df7a6ba9ec8461a5daa0de835bc9343cb56e72e8867f5d7a15492f8d7
6
+ metadata.gz: 1414d602e5fabf5e9b98dfb1811276601f01de83dc0c866ce155ab22a2246122c9a6a2605c9f83dedc70f21a47c5f397b5ed59339412d8eccf09a319429b7271
7
+ data.tar.gz: 8bef6713c24b2a2d24d0ef97b54c1fd957ad8ff28e041ec08fdfa96c3bedc22a5a41c6b4691367357e63e404ba87dbd9599d7eddd0102cbe9bac9184f0d1dcee
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
@@ -10,6 +10,7 @@ module Bashly
10
10
  @strings ||= MessageStrings.new
11
11
  end
12
12
 
13
+ # Outputs a comment that describes the view unless in production mode
13
14
  def view_marker(id = nil)
14
15
  id ||= ":#{caller_locations(1..1).first.path}"
15
16
  "# #{id}" unless Settings.production?
@@ -18,7 +19,7 @@ module Bashly
18
19
  # Reads a file from the userspace (Settings.source_dir) and returns
19
20
  # its contents. If the file is not found, returns a string with a hint.
20
21
  def load_user_file(file, placeholder: true)
21
- path = "#{Settings.source_dir}/#{file}"
22
+ path = user_file_path file
22
23
 
23
24
  content = if File.exist? path
24
25
  File.read(path).remove_front_matter
@@ -31,6 +32,22 @@ module Bashly
31
32
  Settings.production? ? content : "#{view_marker path}\n#{content}"
32
33
  end
33
34
 
35
+ # Returns a path to a file in the user's source_dir. The file argument
36
+ # should either be without exteneion, or with the user's configured
37
+ # partials_extension.
38
+ def user_file_path(file)
39
+ path = "#{Settings.source_dir}/#{file}"
40
+ ext = ".#{Settings.partials_extension}"
41
+ return path if path.end_with? ext
42
+
43
+ "#{path}#{ext}"
44
+ end
45
+
46
+ # Returns true if the user's source file exists
47
+ def user_file_exist?(file)
48
+ File.exist? user_file_path(file)
49
+ end
50
+
34
51
  private
35
52
 
36
53
  def view_path(view)
@@ -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,7 @@
1
+ ## after hook
2
+ ##
3
+ ## Any code here will be placed inside an `after_hook()` function and called
4
+ ## after running any command.
5
+ ##
6
+ ## You can safely delete this file if you do not need it.
7
+ echo "==[ After Hook Called ]=="
@@ -0,0 +1,8 @@
1
+ ## before hook
2
+ ##
3
+ ## Any code here will be placed inside a `before_hook()` function and called
4
+ ## before running any command (but after processing its arguments).
5
+ ##
6
+ ## You can safely delete this file if you do not need it.
7
+ echo "==[ Before Hook Called ]=="
8
+ inspect_args
@@ -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.
@@ -29,6 +29,16 @@ help:
29
29
  help: Add a help command, in addition to the standard --help flag.
30
30
  handler: Bashly::Libraries::Help
31
31
 
32
+ hooks:
33
+ help: Add placeholders for initialize/before/after hooks which are executed on script initialization, and before/after any command.
34
+ files:
35
+ - source: "hooks/initialize.sh"
36
+ target: "%{user_source_dir}/initialize.%{user_ext}"
37
+ - source: "hooks/before.sh"
38
+ target: "%{user_source_dir}/before.%{user_ext}"
39
+ - source: "hooks/after.sh"
40
+ target: "%{user_source_dir}/after.%{user_ext}"
41
+
32
42
  lib:
33
43
  help: |-
34
44
  Create the lib directory for any additional user scripts.
@@ -297,7 +297,7 @@ module Bashly
297
297
  # This is meant to provide the user with the ability to add custom
298
298
  # functions
299
299
  def user_lib
300
- @user_lib ||= Dir["#{Settings.full_lib_dir}/**/*.#{Settings.partials_extension}"].sort
300
+ @user_lib ||= Dir["#{Settings.full_lib_dir}/**/*.#{Settings.partials_extension}"]
301
301
  end
302
302
 
303
303
  # Returns an array of all the args with a whitelist
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.3'
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
  >
@@ -1,4 +1,4 @@
1
- if dependencies
1
+ if dependencies.any?
2
2
  = view_marker
3
3
 
4
4
  dependencies.each do |dependency|
@@ -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.sh", 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
  >
@@ -8,6 +8,7 @@
8
8
  = render :user_lib if user_lib.any?
9
9
  = render :command_functions
10
10
  = render :parse_requirements
11
+ = render :user_hooks
11
12
  = render :initialize
12
13
  = render :run
13
14
 
@@ -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
@@ -7,26 +7,26 @@
7
7
  > declare -a input=()
8
8
  > normalize_input "$@"
9
9
  > parse_requirements "${input[@]}"
10
+ if user_file_exist?('before')
11
+ > before_hook
12
+ end
10
13
  >
11
14
  > case "$action" in
12
15
 
13
16
  deep_commands.each do |command|
14
- > "{{ command.action_name }}")
15
- > if [[ ${args['--help']:-} ]]; then
16
- > long_usage=yes
17
- > {{ command.function_name }}_usage
18
- > else
19
- > {{ command.function_name }}_command
20
- > fi
21
- > ;;
22
- >
17
+ > "{{ command.action_name }}") {{ command.function_name }}_command ;;
23
18
  end
24
19
 
25
20
  if commands.empty?
26
- > "root")
27
- > root_command
28
- > ;;
21
+ > "root") root_command ;;
29
22
  end
30
- >
31
23
  > esac
24
+
25
+ if user_file_exist?('after')
26
+ >
27
+ > after_hook
28
+ end
29
+
32
30
  > }
31
+
32
+
@@ -0,0 +1,17 @@
1
+ if user_file_exist?('before') || user_file_exist?('after')
2
+ = view_marker
3
+ end
4
+
5
+ if user_file_exist?('before')
6
+ > before_hook() {
7
+ = load_user_file("before").indent 2
8
+ > }
9
+ >
10
+ end
11
+
12
+ if user_file_exist?('after')
13
+ > after_hook() {
14
+ = load_user_file("after").indent 2
15
+ > }
16
+ >
17
+ end
@@ -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.1
4
+ version: 1.0.3
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-03 00:00:00.000000000 Z
11
+ date: 2023-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -155,6 +155,9 @@ files:
155
155
  - lib/bashly/libraries/config/config.sh
156
156
  - lib/bashly/libraries/help/help.rb
157
157
  - lib/bashly/libraries/help/help_command.sh
158
+ - lib/bashly/libraries/hooks/after.sh
159
+ - lib/bashly/libraries/hooks/before.sh
160
+ - lib/bashly/libraries/hooks/initialize.sh
158
161
  - lib/bashly/libraries/lib/sample_function.sh
159
162
  - lib/bashly/libraries/libraries.yml
160
163
  - lib/bashly/libraries/settings/settings.yml
@@ -190,7 +193,6 @@ files:
190
193
  - lib/bashly/views/command/command_filter.gtx
191
194
  - lib/bashly/views/command/command_functions.gtx
192
195
  - lib/bashly/views/command/default_assignments.gtx
193
- - lib/bashly/views/command/default_initialize_script.gtx
194
196
  - lib/bashly/views/command/default_root_script.gtx
195
197
  - lib/bashly/views/command/default_script.gtx
196
198
  - lib/bashly/views/command/dependencies_filter.gtx
@@ -222,6 +224,7 @@ files:
222
224
  - lib/bashly/views/command/usage_fixed_flags.gtx
223
225
  - lib/bashly/views/command/usage_flags.gtx
224
226
  - lib/bashly/views/command/user_filter.gtx
227
+ - lib/bashly/views/command/user_hooks.gtx
225
228
  - lib/bashly/views/command/user_lib.gtx
226
229
  - lib/bashly/views/command/version_command.gtx
227
230
  - lib/bashly/views/command/whitelist_filter.gtx
@@ -252,14 +255,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
252
255
  requirements:
253
256
  - - ">="
254
257
  - !ruby/object:Gem::Version
255
- version: 2.7.0
258
+ version: '3.0'
256
259
  required_rubygems_version: !ruby/object:Gem::Requirement
257
260
  requirements:
258
261
  - - ">="
259
262
  - !ruby/object:Gem::Version
260
263
  version: '0'
261
264
  requirements: []
262
- rubygems_version: 3.4.7
265
+ rubygems_version: 3.4.10
263
266
  signing_key:
264
267
  specification_version: 4
265
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
- >