bashly 1.1.0 → 1.1.2

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: d333139a3555fdc50cdb3ddf21119712fcada4ab837f5703f29529f346c6ad24
4
- data.tar.gz: 0a40e42bfa542ed5d4f8d59792aa2a19518ae1c9098db0309f9349db391c74b2
3
+ metadata.gz: c90e3d5380ed91982c50ec46ff37c490e6b00785b80b75c60c4ddbb163902099
4
+ data.tar.gz: b1777dac4776226205c27781cf86af045deed8f25a282e0e2a1a8fd3848e0115
5
5
  SHA512:
6
- metadata.gz: e601e098208e0a5de186279e67c001ff58c44536f09e5cea6815722e9bef3ec3dc1b257c1b9ca2267e94977f05514916a66f03721c88c5a795cab93e8eadb20d
7
- data.tar.gz: 670bcae80903cdabc5d76b5139b1c6d80b1ee3ca33af03078a340a847c4ef1385ca74ca08b2b0a274845f0be5ecfc7ecd9822575b8f8ea8cb3592b821df22760
6
+ metadata.gz: 24c19fb49d0cfe9a1ed96bfd0fa3d77973136ed2dfda747c11aa54244c30d2af17384f6aa4f7604c1a41562e41ffe9e5c1ad2a204a7dd85ac6e2d797c588d65b
7
+ data.tar.gz: b2020a3dcf36073049511f4484d32542a5e54037a464c9e838c7a3ffb2fb48141223ea96ecf334aeb8b4609bedaeca3491d23901d02a481c5fb621354e695936
@@ -8,7 +8,6 @@
8
8
  ## - Use any of the following functions to access and manipulate the values.
9
9
  ## - INI sections are optional (i.e., sectionless key=value pairs are allowed).
10
10
  ##
11
-
12
11
  ## Show all the key=value pairs from your config file
13
12
  config_show() {
14
13
  config_load
@@ -28,8 +27,8 @@ config_show() {
28
27
  ## theme="$(config_get interface.theme)"
29
28
  ##
30
29
  config_get() {
31
- local key="$1"
32
- local default_value="$2"
30
+ local key="${1-}"
31
+ local default_value="${2-}"
33
32
 
34
33
  config_load
35
34
  echo "${ini["$key"]:-$default_value}"
@@ -40,7 +39,7 @@ config_get() {
40
39
  ## config_set cloud.provider aws
41
40
  ##
42
41
  config_set() {
43
- local key="$1"
42
+ local key="${1-}"
44
43
  shift
45
44
  local value="$*"
46
45
 
@@ -54,7 +53,7 @@ config_set() {
54
53
  ## config_del login.email
55
54
  ##
56
55
  config_del() {
57
- local key="$1"
56
+ local key="${1-}"
58
57
 
59
58
  config_load
60
59
  unset "ini[$key]"
@@ -93,7 +92,7 @@ config_reload() {
93
92
  ## Load an INI file (unless loaded) and populate the associative array
94
93
  ## NOTE: Normally there is no need to call this function, it is called as needed
95
94
  config_load() {
96
- [[ "$config_loaded" == "true" ]] && return
95
+ [[ "${config_loaded-}" == "true" ]] && return
97
96
 
98
97
  declare -g CONFIG_FILE=${CONFIG_FILE:=config.ini}
99
98
  declare -g config_loaded=true
@@ -10,7 +10,7 @@
10
10
  ## - name: command
11
11
  ## help: Help subject
12
12
  ##
13
- command="${args[command]}"
13
+ command="${args[command]:-}"
14
14
  long_usage=yes
15
15
 
16
16
  if [[ -z "$command" ]]; then
@@ -25,7 +25,6 @@
25
25
  ## unset ini[section1.key1]
26
26
  ## ini_save path/to/config.ini
27
27
  ##
28
-
29
28
  ## Load an INI file and populate the associative array `ini`.
30
29
  ini_load() {
31
30
  declare -gA ini
@@ -47,6 +46,7 @@ ini_load() {
47
46
  elif [[ $line =~ $key_regex ]]; then
48
47
  key="${BASH_REMATCH[1]}"
49
48
  value="${BASH_REMATCH[2]}"
49
+ [[ $value == *\$* ]] && eval "value=\"$value\""
50
50
  ini["${section}${key}"]="$value"
51
51
  fi
52
52
  done <"$ini_file"
@@ -43,3 +43,21 @@ Add an authors string to your man pages.
43
43
  ```yaml
44
44
  x_mandoc_authors: Lana Lang
45
45
  ```
46
+
47
+ ### See Also: `x_mandoc_see_also`
48
+
49
+ Adds additional pages to the `SEE ALSO` section, in addition to the
50
+ pages that are added automatically (like the parent command, and
51
+ sub commands).
52
+
53
+ This property should be an array of strings. You can optionally add
54
+ a section number in parentheses. If not provided, `(1)` will be used
55
+ as default.
56
+
57
+ #### Example
58
+
59
+ ```yaml
60
+ x_mandoc_see_also:
61
+ - docker
62
+ - docker-compose.yml(5)
63
+ ```
@@ -181,14 +181,19 @@ if examples
181
181
  >
182
182
  end
183
183
 
184
- if public_commands.any? || parents.any?
184
+ see_also = []
185
+ see_also << parents.first if parents.any?
186
+ see_also += public_commands.map { |x| x.full_name.to_hyphen } if public_commands.any?
187
+ see_also += x_mandoc_see_also if x_mandoc_see_also && x_mandoc_see_also.is_a?(Array)
188
+ see_also.map! do |item|
189
+ item.match(/(.+)(\(\d\))/) ? "**#{$1}**#{$2}" : "**#{item}**(1)"
190
+ end
191
+
192
+ if see_also.any?
185
193
  > SEE ALSO
186
194
  > ==================================================
187
195
  >
188
- if parents.any?
189
- > **{{ parents.first }}**(1)
190
- end
191
- = public_commands.map { |x| "**#{x.full_name.to_hyphen}**(1)" }.join ', '
196
+ = see_also.join ', '
192
197
  >
193
198
  end
194
199
 
@@ -1,4 +1,4 @@
1
- # approvals.bash v0.3.3
1
+ # approvals.bash v0.4.0
2
2
  #
3
3
  # Interactive approval testing for Bash.
4
4
  # https://github.com/DannyBen/approvals.bash
@@ -9,6 +9,10 @@ approve() {
9
9
  cmd=$1
10
10
  last_exit_code=0
11
11
  actual=$(eval "$cmd" 2>&1) || last_exit_code=$?
12
+ if [[ "$allow_diff_regex" ]]; then
13
+ actual=$(echo "$actual" | sed "s/$allow_diff_regex/*/g")
14
+ unset allow_diff_regex
15
+ fi
12
16
  approval=$(printf "%b" "$cmd" | tr -s -c "[:alnum:]" _)
13
17
  approval_file="$approvals_dir/${2:-"$approval"}"
14
18
 
@@ -35,6 +39,10 @@ approve() {
35
39
  fi
36
40
  }
37
41
 
42
+ allow_diff() {
43
+ allow_diff_regex="$1"
44
+ }
45
+
38
46
  describe() {
39
47
  echo
40
48
  blue "= $*"
@@ -1,4 +1,5 @@
1
1
  require 'fileutils'
2
+ require 'tmpdir'
2
3
 
3
4
  module Bashly
4
5
  class LibrarySource
@@ -14,7 +15,7 @@ module Bashly
14
15
  end
15
16
 
16
17
  def config
17
- @config ||= YAML.load_file config_path
18
+ @config ||= LibrarySourceConfig.new(config_path).validated_data
18
19
  end
19
20
 
20
21
  def libraries
@@ -0,0 +1,48 @@
1
+ module Bashly
2
+ class LibrarySourceConfig
3
+ include ValidationHelpers
4
+
5
+ attr_reader :path
6
+
7
+ def initialize(path)
8
+ @path = path
9
+ end
10
+
11
+ def data
12
+ @data ||= YAML.load_file path
13
+ end
14
+
15
+ def validated_data
16
+ validate
17
+ data
18
+ end
19
+
20
+ def validate
21
+ assert_root path, data
22
+ end
23
+
24
+ private
25
+
26
+ def assert_root(path, value)
27
+ assert_hash path, value
28
+ data.each { |id, spec| assert_lib "[#{path}] #{id}", spec }
29
+ end
30
+
31
+ def assert_lib(key, value)
32
+ assert_string "#{key}.help", value['help']
33
+
34
+ assert_optional_string "#{key}.usage", value['usage']
35
+ assert_optional_string "#{key}.handler", value['handler']
36
+ assert_optional_string "#{key}.post_install_message", value['post_install_message']
37
+
38
+ return if value['handler']
39
+
40
+ assert_array "#{key}.files", value['files'], of: :filespec
41
+ end
42
+
43
+ def assert_filespec(key, value)
44
+ assert_string "#{key}.source", value['source']
45
+ assert_string "#{key}.target", value['target']
46
+ end
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.2'
3
3
  end
@@ -12,7 +12,7 @@ if whitelisted_args.any? or whitelisted_flags.any?
12
12
  > done
13
13
 
14
14
  else
15
- > if [[ -n ${args['{{ arg.name }}']} ]] && [[ ! ${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 }}']} ]] && [[ ! ${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
data/lib/bashly.rb CHANGED
@@ -15,6 +15,7 @@ module Bashly
15
15
  autoload :ConfigValidator, 'bashly/config_validator'
16
16
  autoload :Library, 'bashly/library'
17
17
  autoload :LibrarySource, 'bashly/library_source'
18
+ autoload :LibrarySourceConfig, 'bashly/library_source_config'
18
19
  autoload :MessageStrings, 'bashly/message_strings'
19
20
  autoload :RenderContext, 'bashly/render_context'
20
21
  autoload :RenderSource, 'bashly/render_source'
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.1.0
4
+ version: 1.1.2
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-08-28 00:00:00.000000000 Z
11
+ date: 2023-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -207,6 +207,7 @@ files:
207
207
  - lib/bashly/libraries/yaml/yaml.sh
208
208
  - lib/bashly/library.rb
209
209
  - lib/bashly/library_source.rb
210
+ - lib/bashly/library_source_config.rb
210
211
  - lib/bashly/message_strings.rb
211
212
  - lib/bashly/refinements/compose_refinements.rb
212
213
  - lib/bashly/render_context.rb