bashly 1.2.11 → 1.2.13

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: 4a153068d9772fcffd185c212747324c7af5b87378329750fd742de486401384
4
- data.tar.gz: f4a871e05d08f6fce8e6cceedd92a9c07549492c6d8f8133de9885afdbf4bb36
3
+ metadata.gz: b7352576231f786aa54762d8ae255d5599da89b8a5c1eb98d39bee4f8826cf40
4
+ data.tar.gz: 847a535d109089a3296b4dfce8477f1c3d40cd62183a4aeb662e396efe9a5f95
5
5
  SHA512:
6
- metadata.gz: b25d31be5e4171aa088698a7665b434f9c4f13a6596b597860dee9021c3426682c9a6a873b722f04bc019ebd9c8be4d7c1b5006e72711f76ad3d8a7a0397d215
7
- data.tar.gz: fc9cdd9ae807b018e1d64c15d7ed4175551624b6b5622982bf4b43c445e767aef97483359daff58e89af22a83f37edf3de6c2d1217345fa4709c70935217bf38
6
+ metadata.gz: 3b2c74316bd4d9d37a22e58ed20c4986a7ca86e7b74b7222e8f7adcad966f83b29d39b915ca7607f1d3655ef1653390aadcdcea173b9c9818ba475f861d8bbba
7
+ data.tar.gz: 89517c698abb34ec83e04590cd4919f59492fc0b999b3baade304dfde859c7aca231db77a9d469df0fcb7d98634913cb6d2321b6a791732f06c2cf608d962cc8
@@ -102,6 +102,19 @@ settings:
102
102
  - source: "settings/settings.yml"
103
103
  target: "settings.yml"
104
104
 
105
+ stacktrace:
106
+ help: Add a function that shows stacktrace on error.
107
+ files:
108
+ - source: "stacktrace/stacktrace.sh"
109
+ target: "%{user_lib_dir}/stacktrace.%{user_ext}"
110
+ post_install_message: |
111
+ The stacktrace function is designed to be called automatically on error.
112
+
113
+ To enable this functionality, call g`enable_stacktrace` in your
114
+ g`src/initialize.sh`. You may run the following command to add this file:
115
+
116
+ m`$ bashly add hooks`
117
+
105
118
  strings:
106
119
  help: Copy an additional configuration file to your project, allowing you to customize all the tips and error strings.
107
120
  files:
@@ -126,3 +126,8 @@ var_aliases:
126
126
  other_args: ~
127
127
  deps: ~
128
128
  env_var_names: ~
129
+
130
+ # Choose different names for some of the internal functions.
131
+ function_names:
132
+ run: ~
133
+ initialize: ~
@@ -0,0 +1,29 @@
1
+ ## Stack trace functions [@bashly-upgrade stacktrace]
2
+ ## This file is a part of Bashly standard library
3
+ ##
4
+ ## Usage:
5
+ ## This function is designed to be called on error.
6
+ ##
7
+ ## To enable this functionality, call `enable_stacktrace` in your
8
+ ## `src/initialize.sh` (Run `bashly add hooks` to add this file).
9
+ ##
10
+ enable_stacktrace() {
11
+ trap 'stacktrace' ERR
12
+ set -o errtrace
13
+ set -o errexit
14
+ }
15
+
16
+ stacktrace() {
17
+ local exit_status="$?"
18
+ local i=0
19
+ local caller_output line func file
20
+
21
+ printf "%s:%s in \`%s\`: %s\n" "${BASH_SOURCE[0]}" "${BASH_LINENO[0]}" "${FUNCNAME[1]}" "$BASH_COMMAND"
22
+ printf "\nStack trace:\n"
23
+ while caller_output="$(caller $i)"; do
24
+ read -r line func file <<<"$caller_output"
25
+ printf "\tfrom %s:%s in \`%s\`\n" "$file" "$line" "$func"
26
+ i=$((i + 1))
27
+ done
28
+ exit "$exit_status"
29
+ } >&2
@@ -1,4 +1,6 @@
1
1
  ## [@bashly-upgrade validations]
2
2
  validate_dir_exists() {
3
- [[ -d "$1" ]] || echo "must be an existing directory"
3
+ if [[ ! -d "$1" ]]; then
4
+ echo "must be an existing directory"
5
+ fi
4
6
  }
@@ -1,4 +1,6 @@
1
1
  ## [@bashly-upgrade validations]
2
2
  validate_file_exists() {
3
- [[ -f "$1" ]] || echo "must be an existing file"
3
+ if [[ ! -f "$1" ]]; then
4
+ echo "must be an existing file"
5
+ fi
4
6
  }
@@ -1,4 +1,6 @@
1
1
  ## [@bashly-upgrade validations]
2
2
  validate_integer() {
3
- [[ "$1" =~ ^[0-9]+$ ]] || echo "must be an integer"
4
- }
3
+ if ! [[ "$1" =~ ^[0-9]+$ ]]; then
4
+ echo "must be an integer"
5
+ fi
6
+ }
@@ -1,4 +1,6 @@
1
1
  ## [@bashly-upgrade validations]
2
2
  validate_not_empty() {
3
- [[ -z "$1" ]] && echo "must not be empty"
3
+ if [[ -z "$1" ]]; then
4
+ echo "must not be empty"
5
+ fi
4
6
  }
@@ -87,8 +87,8 @@ module Bashly
87
87
  # flag with arg that is defined as unique
88
88
  def has_unique_args_or_flags?
89
89
  deep_commands(include_self: true).each do |command|
90
- return true if command.args.count(&:unique).positive? ||
91
- command.flags.count(&:unique).positive?
90
+ return true if command.args.any?(&:unique) ||
91
+ command.flags.any?(&:unique)
92
92
  end
93
93
  false
94
94
  end
@@ -15,6 +15,7 @@ module Bashly
15
15
  :enable_inspect_args,
16
16
  :enable_sourcing,
17
17
  :enable_view_markers,
18
+ :function_names,
18
19
  :lib_dir,
19
20
  :partials_extension,
20
21
  :private_reveal_key,
@@ -89,6 +90,14 @@ module Bashly
89
90
  "#{source_dir}/#{lib_dir}"
90
91
  end
91
92
 
93
+ def function_name(key)
94
+ function_names[key.to_s] || key.to_s
95
+ end
96
+
97
+ def function_names
98
+ @function_names ||= get :function_names
99
+ end
100
+
92
101
  def lib_dir
93
102
  @lib_dir ||= get :lib_dir
94
103
  end
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = '1.2.11'
2
+ VERSION = '1.2.13'
3
3
  end
@@ -1,6 +1,6 @@
1
1
  = view_marker
2
2
 
3
- > initialize() {
3
+ > {{ Settings.function_name :initialize }}() {
4
4
  > declare -g version="<%= version %>"
5
5
  > {{ Settings.strict_string }}
6
6
 
@@ -15,11 +15,11 @@
15
15
  >
16
16
  if Settings.enabled? :sourcing
17
17
  > if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
18
- > initialize
19
- > run "$@"
18
+ > {{ Settings.function_name :initialize }}
19
+ > {{ Settings.function_name :run }} "$@"
20
20
  > fi
21
21
  else
22
- > initialize
23
- > run "$@"
22
+ > {{ Settings.function_name :initialize }}
23
+ > {{ Settings.function_name :run }} "$@"
24
24
  end
25
25
  >
@@ -1,6 +1,6 @@
1
1
  = view_marker
2
2
 
3
- > run() {
3
+ > {{ Settings.function_name :run }}() {
4
4
  = render(:globals).indent(2)
5
5
  >
6
6
  > normalize_input "$@"
@@ -6,16 +6,20 @@ if validate
6
6
  > values=''
7
7
  > eval "values=(${args['{{ long }}']})"
8
8
  > for value in "${values[@]}"; do
9
- > if [[ -n $(validate_{{ validate }} "$value") ]]; then
10
- > printf "{{ strings[:validation_error] }}\n" "{{ usage_string }}" "$(validate_{{ validate }} "$value")" >&2
9
+ > validation_output="$(validate_{{ validate }} "$value")"
10
+ > if [[ -n "$validation_output" ]]; then
11
+ > printf "{{ strings[:validation_error] }}\n" "{{ usage_string }}" "$validation_output" >&2
11
12
  > exit 1
12
13
  > fi
13
14
  > done
14
15
  > fi
15
16
  else
16
- > if [[ -v args['{{ long }}'] && -n $(validate_{{ validate }} "${args['{{ long }}']:-}") ]]; then
17
- > printf "{{ strings[:validation_error] }}\n" "{{ usage_string }}" "$(validate_{{ validate }} "${args['{{ long }}']:-}")" >&2
18
- > exit 1
17
+ > if [[ -v args['{{ long }}'] ]]; then
18
+ > validation_output="$(validate_{{ validate }} "${args['{{ long }}']:-}")"
19
+ > if [[ -n "${validation_output}" ]]; then
20
+ > printf "{{ strings[:validation_error] }}\n" "{{ usage_string }}" "$validation_output" >&2
21
+ > exit 1
22
+ > fi
19
23
  > fi
20
24
  >
21
25
  end
metadata CHANGED
@@ -1,54 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bashly
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.11
4
+ version: 1.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-04 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: colsole
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - ">="
17
- - !ruby/object:Gem::Version
18
- version: 0.8.1
19
- - - "<"
16
+ - - "~>"
20
17
  - !ruby/object:Gem::Version
21
- version: '2'
18
+ version: '1.0'
22
19
  type: :runtime
23
20
  prerelease: false
24
21
  version_requirements: !ruby/object:Gem::Requirement
25
22
  requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- version: 0.8.1
29
- - - "<"
23
+ - - "~>"
30
24
  - !ruby/object:Gem::Version
31
- version: '2'
25
+ version: '1.0'
32
26
  - !ruby/object:Gem::Dependency
33
27
  name: completely
34
28
  requirement: !ruby/object:Gem::Requirement
35
29
  requirements:
36
- - - ">="
37
- - !ruby/object:Gem::Version
38
- version: 0.6.1
39
- - - "<"
30
+ - - "~>"
40
31
  - !ruby/object:Gem::Version
41
- version: '0.8'
32
+ version: 0.7.0
42
33
  type: :runtime
43
34
  prerelease: false
44
35
  version_requirements: !ruby/object:Gem::Requirement
45
36
  requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: 0.6.1
49
- - - "<"
37
+ - - "~>"
50
38
  - !ruby/object:Gem::Version
51
- version: '0.8'
39
+ version: 0.7.0
52
40
  - !ruby/object:Gem::Dependency
53
41
  name: filewatcher
54
42
  requirement: !ruby/object:Gem::Requirement
@@ -238,6 +226,7 @@ files:
238
226
  - lib/bashly/libraries/render/markdown/render.rb
239
227
  - lib/bashly/libraries/render/markdown/summary.txt
240
228
  - lib/bashly/libraries/settings/settings.yml
229
+ - lib/bashly/libraries/stacktrace/stacktrace.sh
241
230
  - lib/bashly/libraries/strings/strings.yml
242
231
  - lib/bashly/libraries/test/approvals.bash
243
232
  - lib/bashly/libraries/test/approve
@@ -355,14 +344,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
355
344
  requirements:
356
345
  - - ">="
357
346
  - !ruby/object:Gem::Version
358
- version: '3.1'
347
+ version: '3.2'
359
348
  required_rubygems_version: !ruby/object:Gem::Requirement
360
349
  requirements:
361
350
  - - ">="
362
351
  - !ruby/object:Gem::Version
363
352
  version: '0'
364
353
  requirements: []
365
- rubygems_version: 3.6.3
354
+ rubygems_version: 3.6.9
366
355
  specification_version: 4
367
356
  summary: Bash Command Line Tool Generator
368
357
  test_files: []