bashly 1.0.6 → 1.0.7

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: 58a2804698490f003611b4f607614fef9995bea16f426c6d56d527d78b770a29
4
- data.tar.gz: 24a4c1d97b45332e424fc6932092225bab7b3ade618f5eec5e9c187ca91389ac
3
+ metadata.gz: a333ce419f5ba64e38000497f245fc5baf822243cd2765c1805ebdf6de2e3b46
4
+ data.tar.gz: 0c9ab24cc2cecd88cbd20a06ab11028740ce3000aec75080ca9a12c6769110c1
5
5
  SHA512:
6
- metadata.gz: 0e62c14ede0d0295e01411cd946859a21413e50b43313f850ea494c4ed5dafe6f402b914dfc8f682c3abc8e38d9004917dbd654d78f8983b961f2f35228e97e4
7
- data.tar.gz: '00309d231db02bb61fe7d9ae2c95d9d615888830a6a95c2815cda9e8b08fa4dd73e6ccc0f0127bf46a467deee4888297975f421a2a1e0c80fa5b23d871124726'
6
+ metadata.gz: ff95fd919a29a16d610d8f3c069f2de17b9984a41251de56e484a5dc49e86dd4114934c47ccb2274521f7f8bd5078287a54ef10478c5e18b6c8a93f462f1c503
7
+ data.tar.gz: 65a1be57601cc7a560a19ef48dc75b09647244fe477327f23ae52a37f8114afca4ee3871a1f72e1b046589e252a57701956a93e9015907bf76fd24455da341ff
data/README.md CHANGED
@@ -32,7 +32,6 @@ a [docker image](https://hub.docker.com/r/dannyben/bashly).
32
32
  <table>
33
33
  <tr>
34
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
35
  </tr>
37
36
  </table>
38
37
 
@@ -82,11 +81,6 @@ to contribute, feel free to [open an issue][issues] or
82
81
 
83
82
  Visit the *[How to contribute][contributing]* page for more information.
84
83
 
85
- ## Stargazers and Forkers
86
-
87
- [![Stargazers repo roster for @DannyBen/bashly](https://reporoster.com/stars/DannyBen/bashly)](https://github.com/DannyBen/bashly/stargazers)
88
-
89
- [![Forkers repo roster for @DannyBen/bashly](https://reporoster.com/forks/DannyBen/bashly)](https://github.com/DannyBen/bashly/network/members)
90
84
 
91
85
  [issues]: https://github.com/DannyBen/bashly/issues
92
86
  [discussions]: https://github.com/DannyBen/bashly/discussions
data/lib/bashly/config.rb CHANGED
@@ -2,7 +2,11 @@ require 'yaml'
2
2
 
3
3
  module Bashly
4
4
  # A convenience class to use either a hash or a filename as a configuration
5
- # source
5
+ # source.
6
+ #
7
+ # When a filename is provided, it is loaded with these extra features:
8
+ # - Support for `import` keyword to merge additional YAML files
9
+ # - Preprocessing with ERB
6
10
  class Config
7
11
  using ComposeRefinements
8
12
 
@@ -10,7 +14,7 @@ module Bashly
10
14
 
11
15
  def self.new(config)
12
16
  if config.is_a? String
13
- YAML.properly_load_file(config).compose
17
+ YAML.load_erb_file(config).compose
14
18
  else
15
19
  config
16
20
  end
@@ -13,6 +13,10 @@ class String
13
13
  gsub(/(.)([A-Z])/, '\1_\2').gsub(/[- ]/, '_').downcase
14
14
  end
15
15
 
16
+ def to_path
17
+ tr(' ', '/').downcase
18
+ end
19
+
16
20
  def wrap(length = 80)
17
21
  strip!
18
22
  split("\n").collect! do |line|
@@ -1,10 +1,12 @@
1
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
- # :nocov:
7
- YAML.load_file path
8
- # :nocov:
2
+ # We trust our loaded YAMLs
3
+ # This patch is due to https://bugs.ruby-lang.org/issues/17866
4
+ # StackOverflow: https://stackoverflow.com/questions/71191685/visit-psych-nodes-alias-unknown-alias-default-psychbadalias/71192990#71192990
5
+ class << self
6
+ alias load unsafe_load
7
+
8
+ def load_erb_file(path)
9
+ YAML.load ERB.new(File.read(path)).result
10
+ end
9
11
  end
10
12
  end
@@ -18,9 +18,15 @@ config_path: "%{source_dir}/bashly.yml"
18
18
  # The path to use for creating the bash script
19
19
  target_dir: .
20
20
 
21
- # The path to use for common library files, relative to the source dir
21
+ # The path to use for common library files, relative to source_dir
22
22
  lib_dir: lib
23
23
 
24
+ # The path to use for command files, relative to source_dir
25
+ # When set to nil (~), command files will be placed directly under source_dir
26
+ # When set to any other string, command files will be placed under this
27
+ # directory, and each command will get its own subdirectory
28
+ commands_dir: ~
29
+
24
30
  # Configure the bash options that will be added to the initialize function:
25
31
  # strict: true Bash strict mode (set -euo pipefail)
26
32
  # strict: false Only exit on errors (set -e)
@@ -14,7 +14,7 @@ module Bashly
14
14
  end
15
15
 
16
16
  def config
17
- @config ||= YAML.properly_load_file config_path
17
+ @config ||= YAML.load_file config_path
18
18
  end
19
19
 
20
20
  def libraries
@@ -13,7 +13,7 @@ module Bashly
13
13
  private
14
14
 
15
15
  def values!
16
- defaults = YAML.properly_load_file asset('libraries/strings/strings.yml')
16
+ defaults = YAML.load_file asset('libraries/strings/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.properly_load_file project_strings_path
26
+ YAML.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.properly_load_file path
25
+ loaded = YAML.load_erb_file path
26
26
  return loaded if loaded.is_a?(Array) || loaded.is_a?(Hash)
27
27
 
28
28
  raise Bashly::ConfigurationError, "Cannot find a valid YAML in g`#{path}`"
@@ -159,10 +159,10 @@ module Bashly
159
159
  options['examples'].is_a?(Array) ? options['examples'] : [options['examples']]
160
160
  end
161
161
 
162
- # Returns the bash filename that is expected to hold the user code
163
- # for this command
162
+ # Returns the filename that is expected to hold the user code for this
163
+ # command
164
164
  def filename
165
- options['filename'] || "#{action_name.to_underscore}_command.#{Settings.partials_extension}"
165
+ options['filename'] || implicit_filename
166
166
  end
167
167
 
168
168
  # Returns an array of Flags
@@ -314,6 +314,18 @@ module Bashly
314
314
  def whitelisted_flags
315
315
  flags.select(&:allowed)
316
316
  end
317
+
318
+ private
319
+
320
+ # Returns either a flat filename (docker_status_command.sh) or a nested
321
+ # path (commands/docker/status.sh)
322
+ def implicit_filename
323
+ if Settings.commands_dir
324
+ "#{Settings.commands_dir}/#{action_name.to_path}.#{Settings.partials_extension}"
325
+ else
326
+ "#{action_name.to_underscore}_command.#{Settings.partials_extension}"
327
+ end
328
+ end
317
329
  end
318
330
  end
319
331
  end
@@ -4,6 +4,7 @@ module Bashly
4
4
  include AssetHelper
5
5
 
6
6
  attr_writer(
7
+ :commands_dir,
7
8
  :compact_short_flags,
8
9
  :config_path,
9
10
  :lib_dir,
@@ -15,6 +16,10 @@ module Bashly
15
16
  :usage_colors
16
17
  )
17
18
 
19
+ def commands_dir
20
+ @commands_dir ||= get :commands_dir
21
+ end
22
+
18
23
  def compact_short_flags
19
24
  @compact_short_flags ||= get :compact_short_flags
20
25
  end
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = '1.0.6'
2
+ VERSION = '1.0.7'
3
3
  end
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.6
4
+ version: 1.0.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: 2023-06-27 00:00:00.000000000 Z
11
+ date: 2023-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -268,7 +268,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
268
268
  - !ruby/object:Gem::Version
269
269
  version: '0'
270
270
  requirements: []
271
- rubygems_version: 3.4.14
271
+ rubygems_version: 3.4.10
272
272
  signing_key:
273
273
  specification_version: 4
274
274
  summary: Bash Command Line Tool Generator