bashly 0.9.5 → 1.0.0

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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bashly/commands/add.rb +38 -86
  3. data/lib/bashly/commands/base.rb +1 -9
  4. data/lib/bashly/commands/generate.rb +16 -21
  5. data/lib/bashly/commands/init.rb +0 -2
  6. data/lib/bashly/commands/preview.rb +0 -2
  7. data/lib/bashly/commands/validate.rb +1 -9
  8. data/lib/bashly/concerns/validation_helpers.rb +0 -8
  9. data/lib/bashly/config_validator.rb +6 -9
  10. data/lib/bashly/docs/command.yml +1 -1
  11. data/lib/bashly/docs/env.yml +1 -1
  12. data/lib/bashly/docs/flag.yml +11 -1
  13. data/lib/bashly/libraries/base.rb +1 -1
  14. data/lib/bashly/{templates/lib → libraries/colors}/colors.sh +0 -0
  15. data/lib/bashly/libraries/{completions_function.rb → completions/completions_function.rb} +0 -0
  16. data/lib/bashly/libraries/{completions_script.rb → completions/completions_script.rb} +0 -0
  17. data/lib/bashly/libraries/{completions_yaml.rb → completions/completions_yaml.rb} +0 -0
  18. data/lib/bashly/{templates/lib → libraries/config}/config.sh +0 -0
  19. data/lib/bashly/libraries/{help.rb → help/help.rb} +1 -1
  20. data/lib/bashly/{templates → libraries}/help/help_command.sh +0 -0
  21. data/lib/bashly/{templates → libraries}/lib/sample_function.sh +0 -0
  22. data/lib/bashly/libraries/libraries.yml +85 -0
  23. data/lib/bashly/{templates → libraries/settings}/settings.yml +7 -1
  24. data/lib/bashly/{templates → libraries/strings}/strings.yml +0 -0
  25. data/lib/bashly/{templates → libraries}/test/approvals.bash +0 -0
  26. data/lib/bashly/{templates → libraries}/test/approve +0 -0
  27. data/lib/bashly/{templates/lib → libraries}/validations/validate_dir_exists.sh +0 -0
  28. data/lib/bashly/{templates/lib → libraries}/validations/validate_file_exists.sh +0 -0
  29. data/lib/bashly/{templates/lib → libraries}/validations/validate_integer.sh +0 -0
  30. data/lib/bashly/{templates/lib → libraries}/validations/validate_not_empty.sh +0 -0
  31. data/lib/bashly/{templates/lib → libraries/yaml}/yaml.sh +0 -0
  32. data/lib/bashly/library.rb +14 -25
  33. data/lib/bashly/library_source.rb +84 -0
  34. data/lib/bashly/message_strings.rb +1 -1
  35. data/lib/bashly/script/command.rb +10 -4
  36. data/lib/bashly/script/flag.rb +1 -1
  37. data/lib/bashly/settings.rb +21 -4
  38. data/lib/bashly/version.rb +1 -1
  39. data/lib/bashly/views/command/long_usage.gtx +2 -2
  40. data/lib/bashly/views/command/usage_environment_variables.gtx +1 -1
  41. data/lib/bashly/views/command/usage_flags.gtx +1 -1
  42. metadata +22 -22
  43. data/lib/bashly/deprecation.rb +0 -27
  44. data/lib/bashly/libraries.yml +0 -60
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34993542fcfa09d73fa8a1e0a0dceff571612efd1fa93211d3656279301c6f95
4
- data.tar.gz: '04218807cb6464dd9cfb5bcf2d8e3b442b67885cd44d91942b5e3f900a3c29b6'
3
+ metadata.gz: 7382bd9a007cc8e3c9b4451e7f3fdbccd62bf740f66cc76f24b03c0e6ef1abdd
4
+ data.tar.gz: 32b2ee626d40efd3f60bab256b08e486b2322b3ef4d429c1de090f0d849f5982
5
5
  SHA512:
6
- metadata.gz: f03c2c3cb8a8fa45c12fcc9a06c5d12a21303b2917c0ada24b60e6895606eac42b5fcfb411702aa24e8bc0885e454f7ad8f4b874294888fb673b323178bbcd81
7
- data.tar.gz: 1c1e28ac06bbc58d573d9b4e2270cde6628059af9ac4377c4c1c8393f488646ccfcb3cc2d8abc8b1e2332219720a8340b2f15b6e829f66725a27024d772e3d5e
6
+ metadata.gz: 947f2accba281a365338b86580fe9113ca0a4e5286fa206ee3d11e3816514113f9af80417298b24101c63b8fc84cd95fbca4d6d6abf2be32d95c2a122f092050
7
+ data.tar.gz: b70e60017a58d0107e44388dfdf228d3089b39d9e1bb3f650c6b4565905b08604f1a400ed4cb4648cc91846298e8e5320d54f45064f5ecc36dfaacb9e609d8bc
@@ -3,120 +3,72 @@ module Bashly
3
3
  class Add < Base
4
4
  help 'Add extra features and customization to your script'
5
5
 
6
- usage 'bashly add colors [--force]'
7
- usage 'bashly add comp FORMAT [OUTPUT --force]'
8
- usage 'bashly add config [--force]'
9
- usage 'bashly add help [--force]'
10
- usage 'bashly add lib [--force]'
11
- usage 'bashly add settings [--force]'
12
- usage 'bashly add strings [--force]'
13
- usage 'bashly add test [--force]'
14
- usage 'bashly add validations [--force]'
15
- usage 'bashly add yaml [--force]'
6
+ usage 'bashly add [--source NAME] LIBRARY [ARGS...] [--force]'
7
+ usage 'bashly add [--source NAME] --list'
16
8
  usage 'bashly add (-h|--help)'
17
9
 
18
- option '-f --force', 'Overwrite existing files'
19
-
20
- param 'FORMAT', <<~USAGE
21
- Output format, can be one of:
22
- function : generate a function file to be included in your script.
23
- script : generate a standalone bash completions script.
24
- yaml : generate a yaml compatible with completely.
25
- USAGE
10
+ option '-s --source NAME', <<~USAGE
11
+ Specify a different libraries source. NAME can be:
26
12
 
27
- param 'OUTPUT', <<~USAGE
28
- For the 'comp function' command: Name of the generated function.
29
- For the 'comp script' or 'comp yaml' commands: path to output file.
30
- In all cases, this is optional and will have sensible defaults.
13
+ * Path to a local libraries directory
14
+ * GitHub (HTTPS) repository: github:user/repo[//path@ref]
15
+ * GitHub (SSH) repository: github-ssh:user/repo[//path@ref]
16
+ * Remote git repository: git:repo-url.git[//path@ref]
31
17
  USAGE
32
-
33
- command 'colors', 'Add standard functions for printing colorful and formatted text to the lib directory.'
34
- command 'comp', 'Generate a bash completions script or function.'
35
- command 'config', 'Add standard functions for handling INI files to the lib directory.'
36
- command 'help', 'Add a help command, in addition to the standard --help flag.'
37
- command 'lib', <<~USAGE
38
- Create the lib directory for any additional user scripts.
39
- All *.sh scripts in this directory will be included in the final bash script.
40
- Note that if you configured a different partials_extension, then the extensions of the files in this directory need to match.
41
- USAGE
42
-
43
- command 'settings', 'Copy a sample settings.yml file to your project, allowing you to customize some ' \
44
- 'bashly options.'
45
-
46
- command 'strings', 'Copy an additional configuration file to your project, allowing you to customize all the ' \
47
- 'tips and error strings.'
48
-
49
- command 'test', 'Add approval testing.'
50
- command 'validations', 'Add argument validation functions to the lib directory.'
51
- command 'yaml', 'Add standard functions for reading YAML files to the lib directory.'
52
- example 'bashly add strings --force'
53
- example 'bashly add comp function'
54
- example 'bashly add comp script completions.bash'
55
-
56
- environment 'BASHLY_SOURCE_DIR', 'The path containing the bashly configuration and source files [default: src]'
57
- environment 'BASHLY_LIB_DIR', 'The path to use for creating the library files, relative to the source dir ' \
58
- '[default: lib]'
18
+ option '-f --force', 'Overwrite existing files'
19
+ option '-l --list', 'Show available libraries'
59
20
 
60
21
  attr_reader :skip_src_check
61
22
 
62
- def colors_command
63
- add_lib 'colors'
64
- end
65
-
66
- def comp_command
67
- format = args['FORMAT']
68
- output = args['OUTPUT']
23
+ def run
24
+ say "Performing git operations, this may take a while...\n" if lib_source.git?
69
25
 
70
- case format
71
- when 'script' then add_lib 'completions_script', output
72
- when 'function' then add_lib 'completions', output
73
- when 'yaml' then add_lib 'completions_yaml', output
74
- else raise Error, "Unrecognized format: #{format}"
26
+ if args['--list']
27
+ show_list
28
+ else
29
+ add_lib args['LIBRARY']
75
30
  end
76
- end
77
31
 
78
- def config_command
79
- add_lib 'config'
32
+ lib_source.cleanup if lib_source.git?
80
33
  end
81
34
 
82
- def lib_command
83
- add_lib 'lib'
84
- end
35
+ private
85
36
 
86
- def settings_command
87
- @skip_src_check = true
88
- add_lib 'settings'
37
+ def source
38
+ args['--source']
89
39
  end
90
40
 
91
- def strings_command
92
- add_lib 'strings'
41
+ def lib_source
42
+ @lib_source ||= Bashly::LibrarySource.new source
93
43
  end
94
44
 
95
- def test_command
96
- add_lib 'test'
45
+ def show_list
46
+ lib_source.config.each do |key, config|
47
+ usage = key
48
+ usage += " #{config['usage']}" if config['usage']
49
+ say "g`#{usage}`"
50
+ say word_wrap(" #{config['help']}")
51
+ say ''
52
+ end
97
53
  end
98
54
 
99
- def help_command
100
- add_lib 'help'
101
- end
55
+ def add_lib(name)
56
+ library = lib_source.libraries[name.to_sym]
57
+ raise "Unknown library: g`#{name}`\nRun m`bashly add --list` to see available libraries" unless library
102
58
 
103
- def validations_command
104
- add_lib 'validations'
105
- end
59
+ library.args = args['ARGS']
60
+ @skip_src_check = lib_source.config.dig name, 'skip_src_check'
106
61
 
107
- def yaml_command
108
- add_lib 'yaml'
62
+ add_library_files library
109
63
  end
110
64
 
111
- private
112
-
113
- def add_lib(name, *args)
114
- library = Bashly::Library.new name, *args
65
+ def add_library_files(library)
115
66
  files_created = 0
116
67
  library.files.each do |file|
117
68
  created = safe_write file[:path], file[:content]
118
69
  files_created += 1 if created
119
70
  end
71
+
120
72
  message = library.post_install_message
121
73
  say "\n#{message}" if message && files_created.positive?
122
74
  end
@@ -7,7 +7,7 @@ module Bashly
7
7
  include AssetHelper
8
8
 
9
9
  def config
10
- @config ||= Config.new "#{Settings.source_dir}/bashly.yml"
10
+ @config ||= Config.new Settings.config_path
11
11
  end
12
12
 
13
13
  def config_validator
@@ -21,14 +21,6 @@ module Bashly
21
21
  def with_valid_config
22
22
  validate_config
23
23
  yield
24
- show_deprecations
25
- end
26
-
27
- def show_deprecations
28
- return if config_validator.deprecations.empty? || ENV['BASHLY_HIDE_DEPRECATIONS']
29
-
30
- messages = config_validator.deprecations.map(&:message).join("\n\n")
31
- say! "\n#{messages}\n\n"
32
24
  end
33
25
  end
34
26
  end
@@ -13,26 +13,11 @@ module Bashly
13
13
  option '-u --upgrade', 'Upgrade all added library functions'
14
14
  option '-w --watch', 'Watch the source directory for changes and regenerate on change'
15
15
  option '-r --wrap FUNCTION', 'Wrap the entire script in a function so it can also be sourced'
16
- option '-e --env ENV', 'Force the generation environment (see BASHLY_ENV)'
16
+ option '-e --env ENV', <<~HELP
17
+ Force the generation environment:
17
18
 
18
- environment 'BASHLY_SOURCE_DIR', 'The path containing the bashly configuration and source ' \
19
- 'files [default: src]'
20
-
21
- environment 'BASHLY_TARGET_DIR', 'The path to use for creating the bash script [default: .]'
22
- environment 'BASHLY_LIB_DIR',
23
- 'The path to use for upgrading library files, relative to the source dir [default: lib]'
24
-
25
- environment 'BASHLY_STRICT', 'When not empty, enable bash strict mode (set -euo pipefail)'
26
- environment 'BASHLY_TAB_INDENT',
27
- 'When not empty, the generated script will use tab indentation instead of spaces ' \
28
- '(every 2 leading spaces will be converted to a tab character)'
29
-
30
- environment 'BASHLY_ENV', <<~HELP
31
- Set to 'production' or 'development':
32
19
  - production generate a smaller script, without file markers
33
20
  - development generate with file markers
34
-
35
- Can be overridden with --env [default: development]
36
21
  HELP
37
22
 
38
23
  example 'bashly generate --force'
@@ -97,6 +82,7 @@ module Bashly
97
82
  next unless content =~ /\[@bashly-upgrade (.+)\]/
98
83
 
99
84
  args = $1.split
85
+
100
86
  library_name = args.shift
101
87
  upgrade file, library_name, *args
102
88
  end
@@ -107,16 +93,25 @@ module Bashly
107
93
  end
108
94
 
109
95
  def upgrade(existing_file, library_name, *args)
110
- if Library.exist? library_name
111
- upgrade! existing_file, library_name, *args
96
+ if library_name.include? ';'
97
+ source_name, library_name = library_name.split(';')
98
+ source = Bashly::LibrarySource.new source_name
99
+ else
100
+ source = Bashly::LibrarySource.new
101
+ end
102
+
103
+ library = source.libraries[library_name.to_sym]
104
+
105
+ if library
106
+ library.args = args
107
+ upgrade! existing_file, library
112
108
  else
113
109
  quiet_say "r`warning` not upgrading c`#{existing_file}`, " \
114
110
  "unknown library '#{library_name}'"
115
111
  end
116
112
  end
117
113
 
118
- def upgrade!(existing_file, library_name, *args)
119
- library = Bashly::Library.new library_name, *args
114
+ def upgrade!(existing_file, library)
120
115
  file = library.find_file existing_file
121
116
 
122
117
  if file
@@ -9,8 +9,6 @@ module Bashly
9
9
 
10
10
  option '-m --minimal', 'Use a minimal configuration file (without commands)'
11
11
 
12
- environment 'BASHLY_SOURCE_DIR', 'The path to use for creating the configuration file [default: src]'
13
-
14
12
  def run
15
13
  if Dir.exist?(target_dir) && !Dir.empty?(target_dir)
16
14
  raise InitError, "Directory g`#{target_dir}` already exists and is not empty"
@@ -6,8 +6,6 @@ module Bashly
6
6
  usage 'bashly preview'
7
7
  usage 'bashly preview (-h|--help)'
8
8
 
9
- environment 'BASHLY_SOURCE_DIR', 'The path containing the bashly configuration and source files [default: src]'
10
-
11
9
  def run
12
10
  with_valid_config do
13
11
  command = Script::Command.new config
@@ -11,21 +11,13 @@ module Bashly
11
11
  option '-v --verbose', 'Show the bashly configuration file prior to validating. ' \
12
12
  'This is useful when using split config (import) since it will show the final compiled configuration.'
13
13
 
14
- environment 'BASHLY_SOURCE_DIR', 'The path containing the bashly configuration and source files [default: src]'
15
-
16
14
  def run
17
15
  if args['--verbose']
18
16
  lp config
19
17
  puts '---'
20
18
  end
21
19
  validate_config
22
- show_deprecations
23
- deprecations = config_validator.deprecations
24
- if deprecations.empty?
25
- say 'g`OK`'
26
- else
27
- say "r`WARNING` Found #{deprecations.count} deprecations"
28
- end
20
+ say 'g`OK`'
29
21
  end
30
22
  end
31
23
  end
@@ -2,10 +2,6 @@ module Bashly
2
2
  # This is a `ConfigValidator` concern responsible for providing basic
3
3
  # assertion methods.
4
4
  module ValidationHelpers
5
- def deprecations
6
- @deprecations ||= []
7
- end
8
-
9
5
  protected
10
6
 
11
7
  def assert(valid, message)
@@ -16,10 +12,6 @@ module Bashly
16
12
  assert !invalid, message
17
13
  end
18
14
 
19
- def deprecate(key, **options)
20
- deprecations.push Deprecation.new(key, **options)
21
- end
22
-
23
15
  def assert_string(key, value)
24
16
  assert value.is_a?(String), "#{key} must be a string"
25
17
  end
@@ -99,6 +99,7 @@ module Bashly
99
99
  assert_optional_string "#{key}.default", value['default']
100
100
  assert_optional_string "#{key}.validate", value['validate']
101
101
 
102
+ assert_boolean "#{key}.private", value['private']
102
103
  assert_boolean "#{key}.repeatable", value['repeatable']
103
104
  assert_boolean "#{key}.required", value['required']
104
105
  assert_array "#{key}.allowed", value['allowed'], of: :string
@@ -131,10 +132,6 @@ module Bashly
131
132
  assert_optional_string "#{key}.default", value['default']
132
133
  assert_boolean "#{key}.required", value['required']
133
134
  assert_boolean "#{key}.private", value['private']
134
-
135
- if value['private']
136
- assert value['default'], "#{key}.private makes no sense without default"
137
- end
138
135
  end
139
136
 
140
137
  def assert_command(key, value)
@@ -160,6 +157,11 @@ module Bashly
160
157
  assert_extensible "#{key}.extensible", value['extensible']
161
158
  assert_dependencies "#{key}.dependencies", value['dependencies']
162
159
 
160
+ assert value['name'].match(/^[a-z0-9_-]+$/),
161
+ "#{key}.name must only contain lowercase alphanumeric characters, hyphens and underscores"
162
+
163
+ refute value['name'].start_with?('-'), "#{key}.name must not start with a hyphen"
164
+
163
165
  assert_array "#{key}.args", value['args'], of: :arg
164
166
  assert_array "#{key}.flags", value['flags'], of: :flag
165
167
  assert_array "#{key}.commands", value['commands'], of: :command
@@ -196,11 +198,6 @@ module Bashly
196
198
  refute value['version'], "#{key}.version makes no sense"
197
199
  refute value['extensible'], "#{key}.extensible makes no sense"
198
200
  end
199
-
200
- # DEPRECATION 0.8.0
201
- if value['short']
202
- deprecate "#{key}.short", replacement: 'alias', reference: 'https://github.com/DannyBen/bashly/pull/220'
203
- end
204
201
  end
205
202
  end
206
203
  end
@@ -75,7 +75,7 @@ command.commands:
75
75
  help: Register a local repository
76
76
 
77
77
  command.completions:
78
- help: Specify a list of additional completion suggestions when used in conjunction with `bashly add comp`.
78
+ help: Specify a list of additional completion suggestions when used in conjunction with `bashly add completions`.
79
79
  url: https://bashly.dannyb.co/configuration/command/#completions
80
80
  example: |-
81
81
  commands:
@@ -36,7 +36,7 @@ environment_variable.name:
36
36
  help: Your API key
37
37
 
38
38
  environment_variable.private:
39
- help: Specify that this environment variable should not be advertised in the usage text. Only makes sense when accompanied by `default`.
39
+ help: Specify that this environment variable should not be advertised in the usage text.
40
40
  url: https://bashly.dannyb.co/configuration/environment-variable/#private
41
41
  example: |-
42
42
  environment_variables:
@@ -46,7 +46,7 @@ flag.arg:
46
46
  help: Clone using SSH
47
47
 
48
48
  flag.completions:
49
- help: Specify a list of additional completion suggestions when used in conjunction with `bashly add comp`. Must be accompanied by `arg`.
49
+ help: Specify a list of additional completion suggestions when used in conjunction with `bashly add completions`. Must be accompanied by `arg`.
50
50
  url: https://bashly.dannyb.co/configuration/flag/#completions
51
51
  example: |-
52
52
  flags:
@@ -112,6 +112,16 @@ flag.long:
112
112
  short: -s
113
113
  help: Clone using SSH
114
114
 
115
+ flag.private:
116
+ help: Specify that this flag should not be displayed in the help text.
117
+ url: https://bashly.dannyb.co/configuration/flag/#private
118
+ example: |-
119
+ flags:
120
+ - long: --legacy
121
+ short: -l
122
+ help: Run using the legacy mode
123
+ private: true
124
+
115
125
  flag.repeatable:
116
126
  help: |-
117
127
  Specify that this flag can be provided multiple times. When used on a flag with an argument, it will be received as a space-delimited string, which needs to be converted to an array with:
@@ -22,7 +22,7 @@ module Bashly
22
22
  end
23
23
 
24
24
  def config
25
- @config ||= Config.new "#{Settings.source_dir}/bashly.yml"
25
+ @config ||= Config.new Settings.config_path
26
26
  end
27
27
  end
28
28
  end
@@ -29,7 +29,7 @@ module Bashly
29
29
  private
30
30
 
31
31
  def help_command
32
- asset_content('templates/help/help_command.sh') % { name: command.name }
32
+ asset_content('libraries/help/help_command.sh') % { name: command.name }
33
33
  end
34
34
  end
35
35
  end
@@ -0,0 +1,85 @@
1
+ colors:
2
+ help: Add standard functions for printing colorful and formatted text to the lib directory.
3
+ files:
4
+ - source: "colors/colors.sh"
5
+ target: "%{user_lib_dir}/colors.%{user_ext}"
6
+
7
+ completions:
8
+ help: Generate a bash completions function.
9
+ usage: '[PATH]'
10
+ handler: Bashly::Libraries::CompletionsFunction
11
+
12
+ completions_script:
13
+ help: Generate a standalone bash completions script.
14
+ usage: '[PATH]'
15
+ handler: Bashly::Libraries::CompletionsScript
16
+
17
+ completions_yaml:
18
+ help: Generate a completions YAML configuration for Completely.
19
+ usage: '[PATH]'
20
+ handler: Bashly::Libraries::CompletionsYAML
21
+
22
+ config:
23
+ help: Add standard functions for handling INI files to the lib directory.
24
+ files:
25
+ - source: "config/config.sh"
26
+ target: "%{user_lib_dir}/config.%{user_ext}"
27
+
28
+ help:
29
+ help: Add a help command, in addition to the standard --help flag.
30
+ handler: Bashly::Libraries::Help
31
+
32
+ lib:
33
+ help: |-
34
+ Create the lib directory for any additional user scripts.
35
+ All *.sh scripts in this directory will be included in the final bash script.
36
+ Note that if you configured a different partials_extension, then the extensions of the files in this directory need to match.
37
+ files:
38
+ - source: "lib/sample_function.sh"
39
+ target: "%{user_lib_dir}/sample_function.%{user_ext}"
40
+
41
+ settings:
42
+ help: Copy a sample settings.yml file to your project, allowing you to customize some bashly options.
43
+ skip_src_check: true
44
+ files:
45
+ - source: "settings/settings.yml"
46
+ target: "settings.yml"
47
+
48
+ strings:
49
+ help: Copy an additional configuration file to your project, allowing you to customize all the tips and error strings.
50
+ files:
51
+ - source: "strings/strings.yml"
52
+ target: "%{user_source_dir}/bashly-strings.yml"
53
+
54
+ test:
55
+ help: Add approval testing.
56
+ files:
57
+ - source: "test/approvals.bash"
58
+ target: "%{user_target_dir}/test/approvals.bash"
59
+ - source: "test/approve"
60
+ target: "%{user_target_dir}/test/approve"
61
+
62
+ post_install_message: |
63
+ Edit your tests in g`test/approve` and then run:
64
+
65
+ m`$ test/approve`
66
+
67
+ Docs: bu`https://github.com/DannyBen/approvals.bash`
68
+
69
+ validations:
70
+ help: Add argument validation functions to the lib directory.
71
+ files:
72
+ - source: "validations/validate_dir_exists.sh"
73
+ target: "%{user_lib_dir}/validations/validate_dir_exists.%{user_ext}"
74
+ - source: "validations/validate_file_exists.sh"
75
+ target: "%{user_lib_dir}/validations/validate_file_exists.%{user_ext}"
76
+ - source: "validations/validate_integer.sh"
77
+ target: "%{user_lib_dir}/validations/validate_integer.%{user_ext}"
78
+ - source: "validations/validate_not_empty.sh"
79
+ target: "%{user_lib_dir}/validations/validate_not_empty.%{user_ext}"
80
+
81
+ yaml:
82
+ help: Add standard functions for reading YAML files.
83
+ files:
84
+ - source: "yaml/yaml.sh"
85
+ target: "%{user_lib_dir}/yaml.%{user_ext}"
@@ -5,10 +5,16 @@
5
5
  # When setting environment variables, you can use:
6
6
  # - "0", "false" or "no" to represent false
7
7
  # - "1", "true" or "yes" to represent true
8
+ #
9
+ # If you wish to change the path to this file, set the environment variable
10
+ # BASHLY_SETTINGS_PATH.
8
11
 
9
- # The path containing the bashly configuration and source files
12
+ # The path containing the bashly source files
10
13
  source_dir: src
11
14
 
15
+ # Tha path to bashly.yml
16
+ config_path: "%{source_dir}/bashly.yml"
17
+
12
18
  # The path to use for creating the bash script
13
19
  target_dir: .
14
20
 
File without changes
@@ -1,25 +1,12 @@
1
1
  module Bashly
2
2
  class Library
3
- class << self
4
- def exist?(name)
5
- config.has_key? name.to_s
6
- end
7
-
8
- def config
9
- @config ||= YAML.properly_load_file config_path
10
- end
11
-
12
- def config_path
13
- @config_path ||= File.expand_path 'libraries.yml', __dir__
14
- end
15
- end
16
-
17
- include AssetHelper
18
- attr_reader :name, :args
3
+ attr_reader :path, :config, :upgrade_string
4
+ attr_accessor :args
19
5
 
20
- def initialize(name, *args)
21
- @name = name.to_s
22
- @args = args
6
+ def initialize(path, config, upgrade_string: nil)
7
+ @path = path.to_s
8
+ @config = config
9
+ @upgrade_string = upgrade_string
23
10
  end
24
11
 
25
12
  def files
@@ -28,8 +15,10 @@ module Bashly
28
15
 
29
16
  else
30
17
  config['files'].map do |file|
31
- { path: file['target'] % target_file_args,
32
- content: asset_content(file['source']) }
18
+ {
19
+ path: file['target'] % target_file_args,
20
+ content: file_contents("#{path}/#{file['source']}"),
21
+ }
33
22
  end
34
23
  end
35
24
  end
@@ -49,13 +38,13 @@ module Bashly
49
38
  private
50
39
 
51
40
  def custom_handler
52
- return nil unless config.is_a? Symbol
41
+ return nil unless config['handler']
53
42
 
54
- @custom_handler ||= Bashly::Libraries.const_get(config).new(*args)
43
+ @custom_handler ||= Module.const_get(config['handler']).new(*args)
55
44
  end
56
45
 
57
- def config
58
- @config ||= self.class.config[name]
46
+ def file_contents(path)
47
+ File.read(path).sub('[@bashly-upgrade]', "[@bashly-upgrade #{upgrade_string}]")
59
48
  end
60
49
 
61
50
  def target_file_args
@@ -0,0 +1,84 @@
1
+ require 'fileutils'
2
+
3
+ module Bashly
4
+ class LibrarySource
5
+ attr_reader :uri
6
+
7
+ def initialize(uri = nil)
8
+ @uri = uri || File.expand_path('libraries', __dir__)
9
+ transform_github_uri if /^github(:|-)/.match? @uri
10
+ end
11
+
12
+ def git?
13
+ /^(git|github|github-ssh):/.match? uri
14
+ end
15
+
16
+ def config
17
+ @config ||= YAML.properly_load_file config_path
18
+ end
19
+
20
+ def libraries
21
+ config.to_h do |name, spec|
22
+ upgrade_string = "#{uri};#{name}"
23
+ [name.to_sym, Library.new(path, spec, upgrade_string: upgrade_string)]
24
+ end
25
+ end
26
+
27
+ def config_path
28
+ @config_path ||= if File.exist?("#{path}/libraries.yml")
29
+ "#{path}/libraries.yml"
30
+ else
31
+ raise "Cannot find #{path}/libraries.yml"
32
+ end
33
+ end
34
+
35
+ def cleanup
36
+ FileUtils.rm_rf(File.join(Dir.tmpdir, 'bashly-libs-*'))
37
+ end
38
+
39
+ private
40
+
41
+ def path
42
+ @path ||= if uri.start_with? 'git:'
43
+ git_clone
44
+ else
45
+ uri
46
+ end
47
+ end
48
+
49
+ def git_clone
50
+ dir = Dir.mktmpdir 'bashly-libs-'
51
+ safe_run "git clone --quiet #{git_specs[:url]} #{dir}"
52
+ safe_run %[git -C "#{dir}" checkout --quiet #{git_specs[:ref]}] if git_specs[:ref]
53
+
54
+ "#{dir}#{git_specs[:path]}"
55
+ end
56
+
57
+ def git_specs
58
+ @git_specs ||= begin
59
+ parts = uri.match(%r{git:(?<url>.*\.git)(?:/)?(?<path>/[^@]+)?@?(?<ref>.*)})
60
+ raise 'Invalid source' unless parts
61
+
62
+ url = parts[:url]
63
+ raise 'Invalid git URL' unless url
64
+
65
+ path = parts[:path]
66
+ ref = parts[:ref].empty? ? nil : parts[:ref]
67
+
68
+ { url: url, path: path, ref: ref }
69
+ end
70
+ end
71
+
72
+ def safe_run(cmd)
73
+ raise "Failed running command:\nm`#{cmd}`" unless system cmd
74
+ end
75
+
76
+ def transform_github_uri
77
+ if (matches = uri.match(%r{github-ssh:(?<user>[^/]+)/(?<repo>[^/]+)(?<rest>.*)}))
78
+ @uri = "git:git@github.com:#{matches[:user]}/#{matches[:repo]}.git#{matches[:rest]}"
79
+ elsif (matches = uri.match(%r{github:(?<user>[^/]+)/(?<repo>[^/]+)(?<rest>.*)}))
80
+ @uri = "git:https://github.com/#{matches[:user]}/#{matches[:repo]}.git#{matches[:rest]}"
81
+ end
82
+ end
83
+ end
84
+ end
@@ -13,7 +13,7 @@ module Bashly
13
13
  private
14
14
 
15
15
  def values!
16
- defaults = YAML.properly_load_file asset('templates/strings.yml')
16
+ defaults = YAML.properly_load_file asset('libraries/strings/strings.yml')
17
17
  defaults.merge project_strings
18
18
  end
19
19
 
@@ -11,9 +11,7 @@ module Bashly
11
11
  extensible expose filename filters flags
12
12
  footer function group help name
13
13
  private version
14
- short
15
14
  ]
16
- # DEPRECATION 0.8.0
17
15
  end
18
16
  end
19
17
 
@@ -36,8 +34,6 @@ module Bashly
36
34
 
37
35
  # Returns an array of alternative aliases if any
38
36
  def alt
39
- # DEPRECATION 0.8.0
40
- options['alias'] ||= options['short']
41
37
  return [] unless options['alias']
42
38
 
43
39
  options['alias'].is_a?(String) ? [options['alias']] : options['alias']
@@ -217,6 +213,16 @@ module Bashly
217
213
  commands.reject(&:private)
218
214
  end
219
215
 
216
+ # Returns only environment variables that are not private
217
+ def public_environment_variables
218
+ environment_variables.reject(&:private)
219
+ end
220
+
221
+ # Returns only flags that are not private
222
+ def public_flags
223
+ flags.reject(&:private)
224
+ end
225
+
220
226
  # Returns true if one of the args is repeatable
221
227
  def repeatable_arg_exist?
222
228
  args.select(&:repeatable).any?
@@ -7,7 +7,7 @@ module Bashly
7
7
  def option_keys
8
8
  @option_keys ||= %i[
9
9
  allowed arg completions conflicts default help long repeatable
10
- required short validate
10
+ required short validate private
11
11
  ]
12
12
  end
13
13
  end
@@ -3,13 +3,26 @@ module Bashly
3
3
  class << self
4
4
  include AssetHelper
5
5
 
6
- attr_writer :compact_short_flags, :lib_dir, :partials_extension,
7
- :source_dir, :strict, :tab_indent, :target_dir, :usage_colors
6
+ attr_writer(
7
+ :compact_short_flags,
8
+ :config_path,
9
+ :lib_dir,
10
+ :partials_extension,
11
+ :source_dir,
12
+ :strict,
13
+ :tab_indent,
14
+ :target_dir,
15
+ :usage_colors
16
+ )
8
17
 
9
18
  def compact_short_flags
10
19
  @compact_short_flags ||= get :compact_short_flags
11
20
  end
12
21
 
22
+ def config_path
23
+ @config_path ||= get(:config_path) % { source_dir: source_dir }
24
+ end
25
+
13
26
  def env
14
27
  @env ||= get(:env)&.to_sym
15
28
  end
@@ -74,7 +87,11 @@ module Bashly
74
87
  end
75
88
 
76
89
  def user_settings
77
- @user_settings ||= File.exist?('settings.yml') ? Config.new('settings.yml') : {}
90
+ @user_settings ||= File.exist?(user_settings_path) ? Config.new(user_settings_path) : {}
91
+ end
92
+
93
+ def user_settings_path
94
+ ENV['BASHLY_SETTINGS_PATH'] || 'settings.yml'
78
95
  end
79
96
 
80
97
  def defsult_settings
@@ -82,7 +99,7 @@ module Bashly
82
99
  end
83
100
 
84
101
  def default_settings_path
85
- asset 'templates/settings.yml'
102
+ asset 'libraries/settings/settings.yml'
86
103
  end
87
104
  end
88
105
  end
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = '0.9.5'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -3,10 +3,10 @@
3
3
  > if [[ -n $long_usage ]]; then
4
4
  > printf "%s\n" "{{ strings[:options].color(:caption) }}"
5
5
  >
6
+ = render(:usage_flags).indent 2 if public_flags.any?
6
7
  = render(:usage_fixed_flags).indent 2
7
- = render(:usage_flags).indent 2 if flags.any?
8
8
  = render(:usage_args).indent 2 if args.any? or catch_all.help
9
- = render(:usage_environment_variables).indent 2 if environment_variables.any?
9
+ = render(:usage_environment_variables).indent 2 if public_environment_variables.any?
10
10
  = render(:usage_examples).indent 2 if examples
11
11
  = render(:footer).indent 2 if footer
12
12
  >
@@ -3,7 +3,7 @@
3
3
  > printf "%s\n" "{{ strings[:environment_variables].color(:caption) }}"
4
4
  >
5
5
 
6
- environment_variables.reject(&:private).each do |env_var|
6
+ public_environment_variables.each do |env_var|
7
7
  = env_var.render :usage
8
8
  end
9
9
 
@@ -1,6 +1,6 @@
1
1
  = view_marker
2
2
 
3
- flags.each do |flag|
3
+ public_flags.each do |flag|
4
4
  = flag.render :usage
5
5
  end
6
6
 
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: 0.9.5
4
+ version: 1.0.0
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-01-31 00:00:00.000000000 Z
11
+ date: 2023-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -138,7 +138,6 @@ files:
138
138
  - lib/bashly/concerns/validation_helpers.rb
139
139
  - lib/bashly/config.rb
140
140
  - lib/bashly/config_validator.rb
141
- - lib/bashly/deprecation.rb
142
141
  - lib/bashly/docs/arg.yml
143
142
  - lib/bashly/docs/command.yml
144
143
  - lib/bashly/docs/env.yml
@@ -148,13 +147,27 @@ files:
148
147
  - lib/bashly/extensions/file.rb
149
148
  - lib/bashly/extensions/string.rb
150
149
  - lib/bashly/extensions/yaml.rb
151
- - lib/bashly/libraries.yml
152
150
  - lib/bashly/libraries/base.rb
153
- - lib/bashly/libraries/completions_function.rb
154
- - lib/bashly/libraries/completions_script.rb
155
- - lib/bashly/libraries/completions_yaml.rb
156
- - lib/bashly/libraries/help.rb
151
+ - lib/bashly/libraries/colors/colors.sh
152
+ - lib/bashly/libraries/completions/completions_function.rb
153
+ - lib/bashly/libraries/completions/completions_script.rb
154
+ - lib/bashly/libraries/completions/completions_yaml.rb
155
+ - lib/bashly/libraries/config/config.sh
156
+ - lib/bashly/libraries/help/help.rb
157
+ - lib/bashly/libraries/help/help_command.sh
158
+ - lib/bashly/libraries/lib/sample_function.sh
159
+ - lib/bashly/libraries/libraries.yml
160
+ - lib/bashly/libraries/settings/settings.yml
161
+ - lib/bashly/libraries/strings/strings.yml
162
+ - lib/bashly/libraries/test/approvals.bash
163
+ - lib/bashly/libraries/test/approve
164
+ - lib/bashly/libraries/validations/validate_dir_exists.sh
165
+ - lib/bashly/libraries/validations/validate_file_exists.sh
166
+ - lib/bashly/libraries/validations/validate_integer.sh
167
+ - lib/bashly/libraries/validations/validate_not_empty.sh
168
+ - lib/bashly/libraries/yaml/yaml.sh
157
169
  - lib/bashly/library.rb
170
+ - lib/bashly/library_source.rb
158
171
  - lib/bashly/message_strings.rb
159
172
  - lib/bashly/refinements/compose_refinements.rb
160
173
  - lib/bashly/script/argument.rb
@@ -166,20 +179,7 @@ files:
166
179
  - lib/bashly/script/wrapper.rb
167
180
  - lib/bashly/settings.rb
168
181
  - lib/bashly/templates/bashly.yml
169
- - lib/bashly/templates/help/help_command.sh
170
- - lib/bashly/templates/lib/colors.sh
171
- - lib/bashly/templates/lib/config.sh
172
- - lib/bashly/templates/lib/sample_function.sh
173
- - lib/bashly/templates/lib/validations/validate_dir_exists.sh
174
- - lib/bashly/templates/lib/validations/validate_file_exists.sh
175
- - lib/bashly/templates/lib/validations/validate_integer.sh
176
- - lib/bashly/templates/lib/validations/validate_not_empty.sh
177
- - lib/bashly/templates/lib/yaml.sh
178
182
  - lib/bashly/templates/minimal.yml
179
- - lib/bashly/templates/settings.yml
180
- - lib/bashly/templates/strings.yml
181
- - lib/bashly/templates/test/approvals.bash
182
- - lib/bashly/templates/test/approve
183
183
  - lib/bashly/version.rb
184
184
  - lib/bashly/views/README.md
185
185
  - lib/bashly/views/argument/usage.gtx
@@ -258,7 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
258
258
  - !ruby/object:Gem::Version
259
259
  version: '0'
260
260
  requirements: []
261
- rubygems_version: 3.4.5
261
+ rubygems_version: 3.4.6
262
262
  signing_key:
263
263
  specification_version: 4
264
264
  summary: Bash Command Line Tool Generator
@@ -1,27 +0,0 @@
1
- module Bashly
2
- class Deprecation
3
- attr_reader :old, :replacement, :reference
4
-
5
- def initialize(old, replacement: nil, reference: nil)
6
- @old = old
7
- @replacement = replacement
8
- @reference = reference
9
- end
10
-
11
- def message
12
- result = ['Deprecation Warning:', "r`#{old}` is deprecated"]
13
- result.push "use g`#{replacement}` instead" if replacement
14
- result.push "see bu`#{reference}`" if reference
15
-
16
- result.map { |line| "r`▐` #{line}" }.join("\n")
17
- end
18
-
19
- def to_h
20
- {
21
- old: old,
22
- replacement: replacement,
23
- reference: reference,
24
- }
25
- end
26
- end
27
- end
@@ -1,60 +0,0 @@
1
- colors:
2
- files:
3
- - source: "templates/lib/colors.sh"
4
- target: "%{user_lib_dir}/colors.%{user_ext}"
5
-
6
- completions: :CompletionsFunction
7
- completions_script: :CompletionsScript
8
- completions_yaml: :CompletionsYAML
9
-
10
- config:
11
- files:
12
- - source: "templates/lib/config.sh"
13
- target: "%{user_lib_dir}/config.%{user_ext}"
14
-
15
- help: :Help
16
-
17
- lib:
18
- files:
19
- - source: "templates/lib/sample_function.sh"
20
- target: "%{user_lib_dir}/sample_function.%{user_ext}"
21
-
22
- settings:
23
- files:
24
- - source: "templates/settings.yml"
25
- target: "settings.yml"
26
-
27
- strings:
28
- files:
29
- - source: "templates/strings.yml"
30
- target: "%{user_source_dir}/bashly-strings.yml"
31
-
32
- test:
33
- files:
34
- - source: "templates/test/approvals.bash"
35
- target: "%{user_target_dir}/test/approvals.bash"
36
- - source: "templates/test/approve"
37
- target: "%{user_target_dir}/test/approve"
38
-
39
- post_install_message: |
40
- Edit your tests in g`test/approve` and then run:
41
-
42
- m`$ test/approve`
43
-
44
- Docs: bu`https://github.com/DannyBen/approvals.bash`
45
-
46
- validations:
47
- files:
48
- - source: "templates/lib/validations/validate_dir_exists.sh"
49
- target: "%{user_lib_dir}/validations/validate_dir_exists.%{user_ext}"
50
- - source: "templates/lib/validations/validate_file_exists.sh"
51
- target: "%{user_lib_dir}/validations/validate_file_exists.%{user_ext}"
52
- - source: "templates/lib/validations/validate_integer.sh"
53
- target: "%{user_lib_dir}/validations/validate_integer.%{user_ext}"
54
- - source: "templates/lib/validations/validate_not_empty.sh"
55
- target: "%{user_lib_dir}/validations/validate_not_empty.%{user_ext}"
56
-
57
- yaml:
58
- files:
59
- - source: "templates/lib/yaml.sh"
60
- target: "%{user_lib_dir}/yaml.%{user_ext}"