bashly 0.8.10 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -0
  3. data/bin/bashly +2 -2
  4. data/lib/bashly/cli.rb +2 -3
  5. data/lib/bashly/commands/add.rb +74 -50
  6. data/lib/bashly/commands/base.rb +4 -3
  7. data/lib/bashly/commands/generate.rb +41 -35
  8. data/lib/bashly/commands/init.rb +10 -9
  9. data/lib/bashly/commands/preview.rb +4 -4
  10. data/lib/bashly/commands/validate.rb +8 -7
  11. data/lib/bashly/concerns/asset_helper.rb +1 -1
  12. data/lib/bashly/concerns/completions.rb +24 -15
  13. data/lib/bashly/concerns/renderable.rb +5 -5
  14. data/lib/bashly/concerns/validation_helpers.rb +20 -12
  15. data/lib/bashly/config.rb +1 -1
  16. data/lib/bashly/config_validator.rb +46 -22
  17. data/lib/bashly/deprecation.rb +9 -7
  18. data/lib/bashly/exceptions.rb +1 -1
  19. data/lib/bashly/extensions/array.rb +4 -4
  20. data/lib/bashly/extensions/file.rb +3 -3
  21. data/lib/bashly/extensions/string.rb +6 -6
  22. data/lib/bashly/libraries/base.rb +11 -1
  23. data/lib/bashly/libraries/completions_function.rb +9 -10
  24. data/lib/bashly/libraries/completions_script.rb +7 -8
  25. data/lib/bashly/libraries/completions_yaml.rb +7 -8
  26. data/lib/bashly/libraries/help.rb +36 -0
  27. data/lib/bashly/libraries.yml +3 -1
  28. data/lib/bashly/library.rb +7 -5
  29. data/lib/bashly/message_strings.rb +1 -1
  30. data/lib/bashly/refinements/compose_refinements.rb +2 -2
  31. data/lib/bashly/script/argument.rb +1 -1
  32. data/lib/bashly/script/base.rb +3 -2
  33. data/lib/bashly/script/catch_all.rb +6 -4
  34. data/lib/bashly/script/command.rb +47 -53
  35. data/lib/bashly/script/environment_variable.rb +5 -5
  36. data/lib/bashly/script/flag.rb +7 -7
  37. data/lib/bashly/script/wrapper.rb +5 -4
  38. data/lib/bashly/settings.rb +4 -5
  39. data/lib/bashly/templates/help/help_command.sh +30 -0
  40. data/lib/bashly/templates/lib/colors.sh +2 -2
  41. data/lib/bashly/templates/lib/config.sh +10 -10
  42. data/lib/bashly/templates/lib/yaml.sh +9 -9
  43. data/lib/bashly/templates/test/approvals.bash +36 -12
  44. data/lib/bashly/templates/test/approve +14 -9
  45. data/lib/bashly/version.rb +2 -2
  46. data/lib/bashly/views/command/command_fallback.gtx +2 -2
  47. data/lib/bashly/views/command/command_filter.gtx +9 -9
  48. data/lib/bashly/views/command/dependencies_filter.gtx +7 -2
  49. data/lib/bashly/views/command/fixed_flags_filter.gtx +18 -12
  50. data/lib/bashly/views/command/inspect_args.gtx +2 -2
  51. data/lib/bashly/views/command/normalize_input.gtx +1 -1
  52. data/lib/bashly/views/command/parse_requirements_while.gtx +11 -11
  53. data/lib/bashly/views/command/run.gtx +14 -13
  54. data/lib/bashly/views/command/usage_environment_variables.gtx +1 -1
  55. data/lib/bashly/views/flag/case.gtx +1 -1
  56. data/lib/bashly/views/flag/case_no_arg.gtx +1 -1
  57. metadata +10 -8
  58. data/lib/bashly/libraries/completions.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93a8d1b32e641bee6713b57ed0cd3e970c8806273f02f900909553dd391d5b43
4
- data.tar.gz: 4024323aa10f725b947d9b59c4019724bd26a58945ff1436102d57130a677442
3
+ metadata.gz: 51f9de0e5f94e6af9e792e567704aeb3b7a48b269fc376657244d6801210f3b9
4
+ data.tar.gz: 5b353f9e94ce7b164a121f824ee846e55403bc54a6237fed29e6fa39d19ce6ee
5
5
  SHA512:
6
- metadata.gz: 81a26b1e7eb07c45f596db2b3f787af3580cfdc9be9490b7b361670decdf582b3eeb996a889f8409631ea4f9470cb81812d73655727189844b833849e543bbb5
7
- data.tar.gz: 3d52eb5364d947bfe5e8a9e3efa626d10da75ddd68f1dff3c279aca4f830f4ef52e17b6b65a95f2b4dfcba1927fecbcc5c9445d6f0e02dc472834f48bcb9284e
6
+ metadata.gz: 58becd123b9fa29d72dbb10a5812a16037a5d6dd626a8b9cbf3b94eee55c6299220e7b7cba770b1d0eae620869cd9c6e909fc1708c3ccf28a482d85e159a2d02
7
+ data.tar.gz: c10390d56a7b56ccc0c3e369c5365a40d7cda17933de43621185e3488d2149f519fc9ff7a1510665562af1a8efbae7653a1185ba67669a6bf6a2b54552fdccdb
data/README.md CHANGED
@@ -73,6 +73,13 @@ to contribute, feel free to [open an issue][issues] or
73
73
  Visit the *[How to contribute][contributing]* page for more information.
74
74
 
75
75
 
76
+ ## Stargazers and Forkers
77
+
78
+ [![Stargazers repo roster for @DannyBen/bashly](https://reporoster.com/stars/DannyBen/bashly)](https://github.com/DannyBen/bashly/stargazers)
79
+
80
+ [![Forkers repo roster for @DannyBen/bashly](https://reporoster.com/forks/DannyBen/bashly)](https://github.com/DannyBen/bashly/network/members)
81
+
82
+
76
83
 
77
84
  [issues]: https://github.com/DannyBen/bashly/issues
78
85
  [discussions]: https://github.com/DannyBen/bashly/discussions
data/bin/bashly CHANGED
@@ -9,9 +9,9 @@ begin
9
9
  exit runner.run ARGV
10
10
  rescue Bashly::Interrupt
11
11
  say! "\nGoodbye"
12
- exit 1
12
+ exit 1
13
13
  rescue => e
14
14
  puts e.backtrace.reverse if ENV['DEBUG']
15
15
  say! "!undred!#{e.class}!txtrst!\n#{e.message}"
16
16
  exit 1
17
- end
17
+ end
data/lib/bashly/cli.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  require 'mister_bin'
2
2
 
3
3
  module Bashly
4
- # The CLI class is used by the bashly binary and forwards incoming CLI
4
+ # The CLI class is used by the bashly binary and forwards incoming CLI
5
5
  # commands to the relevant Bashly::Commands class
6
6
  class CLI
7
7
  def self.runner
8
8
  runner = MisterBin::Runner.new version: Bashly::VERSION,
9
- header: "Bashly - Bash CLI Generator",
9
+ header: 'Bashly - Bash CLI Generator',
10
10
  footer: "Help: !txtpur!bashly COMMAND --help!txtrst!\nDocs: !undblu!https://bashly.dannyb.co"
11
11
 
12
12
  runner.route 'init', to: Commands::Init
@@ -18,5 +18,4 @@ module Bashly
18
18
  runner
19
19
  end
20
20
  end
21
-
22
21
  end
@@ -1,40 +1,58 @@
1
1
  module Bashly
2
2
  module Commands
3
3
  class Add < Base
4
- help "Add extra features and customization to your script"
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 lib [--force]"
10
- usage "bashly add settings [--force]"
11
- usage "bashly add strings [--force]"
12
- usage "bashly add test [--force]"
13
- usage "bashly add validations [--force]"
14
- usage "bashly add yaml [--force]"
15
- usage "bashly add (-h|--help)"
16
-
17
- option "-f --force", "Overwrite existing files"
18
-
19
- param "FORMAT", "Output format, can be one of:\n function : generate a function file to be included in your script.\n script : generate a standalone bash completions script.\n yaml : generate a yaml compatible with completely."
20
- param "OUTPUT", "For the 'comp function' command: Name of the generated function.\nFor the 'comp script' or 'comp yaml' commands: path to output file.\nIn all cases, this is optional and will have sensible defaults."
21
-
22
- command "colors", "Add standard functions for printing colorful and formatted text to the lib directory."
23
- command "comp", "Generate a bash completions script or function."
24
- command "config", "Add standard functions for handling INI files to the lib directory."
25
- command "lib", "Create the additional lib directory for additional user scripts. All *.sh scripts in this folder will be included in the final bash script."
26
- command "settings", "Copy a sample settings.yml file to your project, allowing you to customize some bashly options."
27
- command "strings", "Copy an additional configuration file to your project, allowing you to customize all the tips and error strings."
28
- command "test", "Add approval testing."
29
- command "validations", "Add argument validation functions to the lib directory."
30
- command "yaml", "Add standard functions for reading YAML files to the lib directory."
31
-
32
- example "bashly add strings --force"
33
- example "bashly add comp function"
34
- example "bashly add comp script completions.bash"
35
-
36
- environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
37
- environment "BASHLY_LIB_DIR", "The path to use for creating the library files, relative to the source dir [default: lib]"
4
+ help 'Add extra features and customization to your script'
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]'
16
+ usage 'bashly add (-h|--help)'
17
+
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
26
+
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.
31
+ 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', 'Create the additional lib directory for additional user scripts. All *.sh scripts in this ' \
38
+ 'folder will be included in the final bash script.'
39
+
40
+ command 'settings', 'Copy a sample settings.yml file to your project, allowing you to customize some ' \
41
+ 'bashly options.'
42
+
43
+ command 'strings', 'Copy an additional configuration file to your project, allowing you to customize all the ' \
44
+ 'tips and error strings.'
45
+
46
+ command 'test', 'Add approval testing.'
47
+ command 'validations', 'Add argument validation functions to the lib directory.'
48
+ command 'yaml', 'Add standard functions for reading YAML files to the lib directory.'
49
+ example 'bashly add strings --force'
50
+ example 'bashly add comp function'
51
+ example 'bashly add comp script completions.bash'
52
+
53
+ environment 'BASHLY_SOURCE_DIR', 'The path containing the bashly configuration and source files [default: src]'
54
+ environment 'BASHLY_LIB_DIR', 'The path to use for creating the library files, relative to the source dir ' \
55
+ '[default: lib]'
38
56
 
39
57
  attr_reader :skip_src_check
40
58
 
@@ -47,9 +65,9 @@ module Bashly
47
65
  output = args['OUTPUT']
48
66
 
49
67
  case format
50
- when "script" then add_lib 'completions_script', output
51
- when "function" then add_lib 'completions', output
52
- when "yaml" then add_lib 'completions_yaml', output
68
+ when 'script' then add_lib 'completions_script', output
69
+ when 'function' then add_lib 'completions', output
70
+ when 'yaml' then add_lib 'completions_yaml', output
53
71
  else raise Error, "Unrecognized format: #{format}"
54
72
  end
55
73
  end
@@ -58,6 +76,10 @@ module Bashly
58
76
  add_lib 'config'
59
77
  end
60
78
 
79
+ def lib_command
80
+ add_lib 'lib'
81
+ end
82
+
61
83
  def settings_command
62
84
  @skip_src_check = true
63
85
  add_lib 'settings'
@@ -67,22 +89,22 @@ module Bashly
67
89
  add_lib 'strings'
68
90
  end
69
91
 
70
- def lib_command
71
- add_lib 'lib'
72
- end
73
-
74
92
  def test_command
75
93
  add_lib 'test'
76
94
  end
77
95
 
78
- def yaml_command
79
- add_lib 'yaml'
96
+ def help_command
97
+ add_lib 'help'
80
98
  end
81
99
 
82
100
  def validations_command
83
101
  add_lib 'validations'
84
102
  end
85
103
 
104
+ def yaml_command
105
+ add_lib 'yaml'
106
+ end
107
+
86
108
  private
87
109
 
88
110
  def add_lib(name, *args)
@@ -93,26 +115,28 @@ module Bashly
93
115
  files_created += 1 if created
94
116
  end
95
117
  message = library.post_install_message
96
- say "\n#{message}" if message and files_created > 0
118
+ say "\n#{message}" if message && files_created.positive?
97
119
  end
98
120
 
99
121
  def safe_write(path, content)
100
- if !skip_src_check and !Dir.exist? Settings.source_dir
101
- raise InitError, "Directory !txtgrn!#{Settings.source_dir}!txtrst! does not exist\nRun !txtpur!bashly init!txtrst! first"
122
+ if !skip_src_check && !Dir.exist?(Settings.source_dir)
123
+ raise InitError, <<~ERROR
124
+ Directory !txtgrn!#{Settings.source_dir}!txtrst! does not exist
125
+ Run !txtpur!bashly init!txtrst! first
126
+ ERROR
102
127
  end
103
128
 
104
- if File.exist? path and !args['--force']
129
+ if File.exist?(path) && !args['--force']
105
130
  say "!txtblu!skipped!txtrst! #{path} (exists)"
106
131
  false
107
-
132
+
108
133
  else
109
134
  File.deep_write path, content
110
135
  say "!txtgrn!created!txtrst! #{path}"
111
136
  true
112
-
137
+
113
138
  end
114
139
  end
115
-
116
140
  end
117
141
  end
118
142
  end
@@ -25,9 +25,10 @@ module Bashly
25
25
  end
26
26
 
27
27
  def show_deprecations
28
- return if config_validator.deprecations.empty? or ENV['BASHLY_HIDE_DEPRECATIONS']
29
- messages = "\n" + config_validator.deprecations.map(&:message).join("\n\n") + "\n\n"
30
- say! messages
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"
31
32
  end
32
33
  end
33
34
  end
@@ -3,34 +3,41 @@ require 'filewatcher'
3
3
  module Bashly
4
4
  module Commands
5
5
  class Generate < Base
6
- help "Generate the bash script and required files"
7
-
8
- usage "bashly generate [options]"
9
- usage "bashly generate (-h|--help)"
10
-
11
- option "-f --force", "Overwrite existing files"
12
- option "-q --quiet", "Disable on-screen progress report"
13
- option "-u --upgrade", "Upgrade all added library functions"
14
- option "-w --watch", "Watch the source directory for changes and regenerate on change"
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)"
17
-
18
- environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
19
- environment "BASHLY_TARGET_DIR", "The path to use for creating the bash script [default: .]"
20
- environment "BASHLY_LIB_DIR", "The path to use for upgrading library files, relative to the source dir [default: lib]"
21
- environment "BASHLY_STRICT", "When not empty, enable bash strict mode (set -euo pipefail)"
22
- environment "BASHLY_TAB_INDENT", "When not empty, the generated script will use tab indentation instead of spaces (every 2 leading spaces will be converted to a tab character)"
23
- environment "BASHLY_ENV", <<~EOF
6
+ help 'Generate the bash script and required files'
7
+
8
+ usage 'bashly generate [options]'
9
+ usage 'bashly generate (-h|--help)'
10
+
11
+ option '-f --force', 'Overwrite existing files'
12
+ option '-q --quiet', 'Disable on-screen progress report'
13
+ option '-u --upgrade', 'Upgrade all added library functions'
14
+ option '-w --watch', 'Watch the source directory for changes and regenerate on change'
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)'
17
+
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
24
31
  Set to 'production' or 'development':
25
32
  - production generate a smaller script, without file markers
26
33
  - development generate with file markers
27
34
 
28
35
  Can be overridden with --env [default: development]
29
- EOF
36
+ HELP
30
37
 
31
- example "bashly generate --force"
32
- example "bashly generate --wrap my_function"
33
- example "bashly g -uw"
38
+ example 'bashly generate --force'
39
+ example 'bashly generate --wrap my_function'
40
+ example 'bashly g -uw'
34
41
 
35
42
  attr_reader :watching
36
43
 
@@ -56,13 +63,12 @@ module Bashly
56
63
 
57
64
  ensure
58
65
  quiet_say "!txtgrn!waiting\n"
59
-
60
66
  end
61
67
  end
62
68
 
63
69
  def generate
64
70
  with_valid_config do
65
- quiet_say "creating !txtgrn!production!txtrst! version" if Settings.production?
71
+ quiet_say 'creating !txtgrn!production!txtrst! version' if Settings.production?
66
72
  generate_all_files
67
73
  quiet_say "run !txtpur!#{master_script_path} --help!txtrst! to test your bash script" unless watching
68
74
  end
@@ -88,12 +94,11 @@ module Bashly
88
94
  def upgrade_libs
89
95
  generated_files.each do |file|
90
96
  content = File.read file
91
-
92
- if content =~ /\[@bashly-upgrade (.+)\]/
93
- args = $1.split ' '
94
- library_name = args.shift
95
- upgrade file, library_name, *args
96
- end
97
+ next unless content =~ /\[@bashly-upgrade (.+)\]/
98
+
99
+ args = $1.split
100
+ library_name = args.shift
101
+ upgrade file, library_name, *args
97
102
  end
98
103
  end
99
104
 
@@ -105,7 +110,8 @@ module Bashly
105
110
  if Library.exist? library_name
106
111
  upgrade! existing_file, library_name, *args
107
112
  else
108
- quiet_say "!txtred!warning!txtrst! not upgrading !txtcyn!#{existing_file}!txtrst!, unknown library '#{library_name}'"
113
+ quiet_say "!txtred!warning!txtrst! not upgrading !txtcyn!#{existing_file}!txtrst!, " \
114
+ "unknown library '#{library_name}'"
109
115
  end
110
116
  end
111
117
 
@@ -140,6 +146,7 @@ module Bashly
140
146
  def create_all_command_files
141
147
  command.deep_commands.each do |subcommand|
142
148
  next if subcommand.commands.any?
149
+
143
150
  file = "#{Settings.source_dir}/#{subcommand.filename}"
144
151
  content = subcommand.render :default_script
145
152
  create_file file, content
@@ -147,7 +154,7 @@ module Bashly
147
154
  end
148
155
 
149
156
  def create_file(file, content)
150
- if File.exist? file and !args['--force']
157
+ if File.exist?(file) && !args['--force']
151
158
  quiet_say "!txtblu!skipped!txtrst! #{file} (exists)"
152
159
  else
153
160
  File.deep_write file, content
@@ -157,12 +164,12 @@ module Bashly
157
164
 
158
165
  def create_master_script
159
166
  File.write master_script_path, script.code(tab_indent: Settings.tab_indent)
160
- FileUtils.chmod "+x", master_script_path
167
+ FileUtils.chmod '+x', master_script_path
161
168
  quiet_say "!txtgrn!created!txtrst! #{master_script_path}"
162
169
  end
163
170
 
164
171
  def script
165
- @script ||= Script::Wrapper.new(command, args['--wrap'])
172
+ @script ||= Script::Wrapper.new command, args['--wrap']
166
173
  end
167
174
 
168
175
  def master_script_path
@@ -172,7 +179,6 @@ module Bashly
172
179
  def command
173
180
  @command ||= Script::Command.new config
174
181
  end
175
-
176
182
  end
177
183
  end
178
184
  end
@@ -1,24 +1,25 @@
1
1
  module Bashly
2
2
  module Commands
3
3
  class Init < Base
4
- summary "Initialize a new workspace"
5
- help "This command will create the source folder, and place a template configuration file in it."
4
+ summary 'Initialize a new workspace'
5
+ help 'This command will create the source folder, and place a template configuration file in it.'
6
6
 
7
- usage "bashly init [--minimal]"
8
- usage "bashly init (-h|--help)"
7
+ usage 'bashly init [--minimal]'
8
+ usage 'bashly init (-h|--help)'
9
9
 
10
- option "-m --minimal", "Use a minimal configuration file (without commands)"
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]"
12
+ environment 'BASHLY_SOURCE_DIR', 'The path to use for creating the configuration file [default: src]'
13
13
 
14
14
  def run
15
- if Dir.exist? target_dir and !Dir.empty? target_dir
15
+ if Dir.exist?(target_dir) && !Dir.empty?(target_dir)
16
16
  raise InitError, "Directory !txtgrn!#{target_dir}!txtrst! already exists and is not empty"
17
17
  end
18
- Dir.mkdir target_dir unless Dir.exist? target_dir
18
+
19
+ FileUtils.mkdir_p target_dir
19
20
  File.write "#{target_dir}/bashly.yml", yaml_content
20
21
  say "!txtgrn!created!txtrst! #{target_dir}/bashly.yml"
21
- say "run !txtpur!bashly generate!txtrst! to create the bash script"
22
+ say 'run !txtpur!bashly generate!txtrst! to create the bash script'
22
23
  end
23
24
 
24
25
  private
@@ -1,12 +1,12 @@
1
1
  module Bashly
2
2
  module Commands
3
3
  class Preview < Base
4
- help "Generate the bash script to STDOUT"
4
+ help 'Generate the bash script to STDOUT'
5
5
 
6
- usage "bashly preview"
7
- usage "bashly preview (-h|--help)"
6
+ usage 'bashly preview'
7
+ usage 'bashly preview (-h|--help)'
8
8
 
9
- environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
9
+ environment 'BASHLY_SOURCE_DIR', 'The path containing the bashly configuration and source files [default: src]'
10
10
 
11
11
  def run
12
12
  with_valid_config do
@@ -1,25 +1,26 @@
1
1
  module Bashly
2
2
  module Commands
3
3
  class Validate < Base
4
- help "Scan the configuration file for errors"
4
+ help 'Scan the configuration file for errors'
5
5
 
6
- usage "bashly validate [--verbose]"
7
- usage "bashly validate (-h|--help)"
6
+ usage 'bashly validate [--verbose]'
7
+ usage 'bashly validate (-h|--help)'
8
8
 
9
- option "-v --verbose", "Show the bashly configuration file prior to validating. This is useful when using split config (import) since it will show the final compiled configuration."
9
+ option '-v --verbose', 'Show the bashly configuration file prior to validating. ' \
10
+ 'This is useful when using split config (import) since it will show the final compiled configuration.'
10
11
 
11
- environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
12
+ environment 'BASHLY_SOURCE_DIR', 'The path containing the bashly configuration and source files [default: src]'
12
13
 
13
14
  def run
14
15
  if args['--verbose']
15
16
  lp config
16
- puts "---"
17
+ puts '---'
17
18
  end
18
19
  validate_config
19
20
  show_deprecations
20
21
  deprecations = config_validator.deprecations
21
22
  if deprecations.empty?
22
- say "!txtgrn!OK"
23
+ say '!txtgrn!OK'
23
24
  else
24
25
  say "!txtred!WARNING!txtrst! Found #{deprecations.count} deprecations"
25
26
  end
@@ -8,4 +8,4 @@ module Bashly
8
8
  File.read asset(path)
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -6,16 +6,14 @@ module Bashly
6
6
  module Completions
7
7
  module Flag
8
8
  def completion_data(command_full_name)
9
- result = {}
10
9
  comps = allowed || completions
10
+ return {} unless comps
11
11
 
12
- if comps
13
- aliases.each do |name|
14
- result["#{command_full_name}*#{name}"] = comps
15
- end
12
+ aliases.to_h do |name|
13
+ prefix = command_full_name
14
+ prefix = "#{prefix}*" unless prefix.end_with? '*'
15
+ ["#{prefix}#{name}", comps]
16
16
  end
17
-
18
- result
19
17
  end
20
18
  end
21
19
 
@@ -23,13 +21,14 @@ module Bashly
23
21
  def completion_data(with_version: true)
24
22
  result = {}
25
23
 
26
- all_full_names.each do |name|
27
- result[name] = completion_words(with_version: with_version)
24
+ completion_full_names.each do |name|
25
+ name = "#{name}*" if name.include? '*'
26
+ result[name] = completion_words with_version: with_version
28
27
  flags.each do |flag|
29
28
  result.merge! flag.completion_data(name)
30
29
  end
31
30
  end
32
-
31
+
33
32
  commands.each do |command|
34
33
  result.merge! command.completion_data(with_version: false)
35
34
  end
@@ -42,13 +41,24 @@ module Bashly
42
41
  end
43
42
 
44
43
  def completion_function(name = nil)
45
- completion_generator.wrapper_function(name)
44
+ completion_generator.wrapper_function name
45
+ end
46
+
47
+ protected
48
+
49
+ def completion_full_names
50
+ if parent_command
51
+ glue = parent_command.global_flags? ? '*' : ' '
52
+ parent_command.completion_full_names.product(aliases).map { |a| a.join glue }
53
+ else
54
+ aliases
55
+ end
46
56
  end
47
57
 
48
58
  private
49
59
 
50
60
  def completion_generator
51
- Completely::Completions.new(completion_data)
61
+ Completely::Completions.new completion_data
52
62
  end
53
63
 
54
64
  def completion_flag_names
@@ -63,14 +73,13 @@ module Bashly
63
73
  trivial_flags = %w[--help -h]
64
74
  trivial_flags += %w[--version -v] if with_version
65
75
  all = (
66
- command_aliases + trivial_flags +
76
+ command_aliases + trivial_flags +
67
77
  completion_flag_names + completion_allowed_args
68
78
  )
69
79
 
70
80
  all += completions if completions
71
81
  all.compact.uniq.sort
72
82
  end
73
-
74
83
  end
75
84
  end
76
- end
85
+ end
@@ -11,7 +11,7 @@ module Bashly
11
11
  end
12
12
 
13
13
  def view_marker(id = nil)
14
- id ||= ":#{caller_locations.first.path}"
14
+ id ||= ":#{caller_locations(1..1).first.path}"
15
15
  "# #{id}" unless Settings.production?
16
16
  end
17
17
 
@@ -23,7 +23,7 @@ module Bashly
23
23
  content = if File.exist? path
24
24
  File.read(path).remove_front_matter
25
25
  elsif placeholder
26
- %q[echo "error: cannot load file"]
26
+ 'echo "error: cannot load file"'
27
27
  else
28
28
  ''
29
29
  end
@@ -38,15 +38,15 @@ module Bashly
38
38
  end
39
39
 
40
40
  def self_views_path
41
- @self_view_path ||= "#{base_views_path}/#{views_subfolder}"
41
+ @self_views_path ||= "#{base_views_path}/#{views_subfolder}"
42
42
  end
43
43
 
44
44
  def base_views_path
45
- @base_views_path ||= File.expand_path("../views/", __dir__)
45
+ @base_views_path ||= File.expand_path '../views/', __dir__
46
46
  end
47
47
 
48
48
  def views_subfolder
49
49
  @views_subfolder ||= self.class.name.split('::').last.to_underscore
50
50
  end
51
51
  end
52
- end
52
+ end