bashly 0.8.9 → 0.9.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.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/bin/bashly +2 -2
- data/lib/bashly/cli.rb +2 -3
- data/lib/bashly/commands/add.rb +74 -50
- data/lib/bashly/commands/base.rb +4 -3
- data/lib/bashly/commands/generate.rb +41 -35
- data/lib/bashly/commands/init.rb +10 -9
- data/lib/bashly/commands/preview.rb +4 -4
- data/lib/bashly/commands/validate.rb +8 -7
- data/lib/bashly/concerns/asset_helper.rb +1 -1
- data/lib/bashly/concerns/completions.rb +24 -15
- data/lib/bashly/concerns/renderable.rb +5 -5
- data/lib/bashly/concerns/validation_helpers.rb +20 -12
- data/lib/bashly/config.rb +1 -1
- data/lib/bashly/config_validator.rb +47 -23
- data/lib/bashly/deprecation.rb +9 -7
- data/lib/bashly/exceptions.rb +1 -1
- data/lib/bashly/extensions/array.rb +4 -4
- data/lib/bashly/extensions/file.rb +3 -3
- data/lib/bashly/extensions/string.rb +6 -6
- data/lib/bashly/libraries/base.rb +11 -1
- data/lib/bashly/libraries/completions_function.rb +9 -10
- data/lib/bashly/libraries/completions_script.rb +7 -8
- data/lib/bashly/libraries/completions_yaml.rb +7 -8
- data/lib/bashly/libraries/help.rb +36 -0
- data/lib/bashly/libraries.yml +3 -1
- data/lib/bashly/library.rb +7 -5
- data/lib/bashly/message_strings.rb +1 -1
- data/lib/bashly/refinements/compose_refinements.rb +2 -2
- data/lib/bashly/script/argument.rb +1 -1
- data/lib/bashly/script/base.rb +3 -2
- data/lib/bashly/script/catch_all.rb +6 -4
- data/lib/bashly/script/command.rb +51 -51
- data/lib/bashly/script/environment_variable.rb +5 -5
- data/lib/bashly/script/flag.rb +7 -7
- data/lib/bashly/script/wrapper.rb +5 -4
- data/lib/bashly/settings.rb +4 -5
- data/lib/bashly/templates/help/help_command.sh +30 -0
- data/lib/bashly/templates/lib/colors.sh +2 -2
- data/lib/bashly/templates/lib/config.sh +10 -10
- data/lib/bashly/templates/lib/yaml.sh +9 -9
- data/lib/bashly/templates/test/approvals.bash +36 -12
- data/lib/bashly/templates/test/approve +14 -9
- data/lib/bashly/version.rb +2 -2
- data/lib/bashly/views/command/command_fallback.gtx +2 -2
- data/lib/bashly/views/command/command_filter.gtx +9 -9
- data/lib/bashly/views/command/dependencies_filter.gtx +7 -2
- data/lib/bashly/views/command/fixed_flags_filter.gtx +18 -12
- data/lib/bashly/views/command/inspect_args.gtx +2 -2
- data/lib/bashly/views/command/normalize_input.gtx +1 -1
- data/lib/bashly/views/command/parse_requirements_while.gtx +11 -11
- data/lib/bashly/views/command/run.gtx +14 -13
- data/lib/bashly/views/command/usage_environment_variables.gtx +1 -1
- data/lib/bashly/views/flag/case.gtx +1 -1
- data/lib/bashly/views/flag/case_no_arg.gtx +1 -1
- metadata +10 -8
- data/lib/bashly/libraries/completions.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51f9de0e5f94e6af9e792e567704aeb3b7a48b269fc376657244d6801210f3b9
|
4
|
+
data.tar.gz: 5b353f9e94ce7b164a121f824ee846e55403bc54a6237fed29e6fa39d19ce6ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
+
[](https://github.com/DannyBen/bashly/stargazers)
|
79
|
+
|
80
|
+
[](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
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:
|
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
|
data/lib/bashly/commands/add.rb
CHANGED
@@ -1,40 +1,58 @@
|
|
1
1
|
module Bashly
|
2
2
|
module Commands
|
3
3
|
class Add < Base
|
4
|
-
help
|
5
|
-
|
6
|
-
usage
|
7
|
-
usage
|
8
|
-
usage
|
9
|
-
usage
|
10
|
-
usage
|
11
|
-
usage
|
12
|
-
usage
|
13
|
-
usage
|
14
|
-
usage
|
15
|
-
usage
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
param
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
51
|
-
when
|
52
|
-
when
|
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
|
79
|
-
add_lib '
|
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
|
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
|
101
|
-
raise InitError,
|
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?
|
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
|
data/lib/bashly/commands/base.rb
CHANGED
@@ -25,9 +25,10 @@ module Bashly
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def show_deprecations
|
28
|
-
return if config_validator.deprecations.empty?
|
29
|
-
|
30
|
-
|
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
|
7
|
-
|
8
|
-
usage
|
9
|
-
usage
|
10
|
-
|
11
|
-
option
|
12
|
-
option
|
13
|
-
option
|
14
|
-
option
|
15
|
-
option
|
16
|
-
option
|
17
|
-
|
18
|
-
environment
|
19
|
-
|
20
|
-
|
21
|
-
environment
|
22
|
-
environment
|
23
|
-
|
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
|
-
|
36
|
+
HELP
|
30
37
|
|
31
|
-
example
|
32
|
-
example
|
33
|
-
example
|
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
|
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
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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!,
|
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?
|
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
|
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
|
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
|
data/lib/bashly/commands/init.rb
CHANGED
@@ -1,24 +1,25 @@
|
|
1
1
|
module Bashly
|
2
2
|
module Commands
|
3
3
|
class Init < Base
|
4
|
-
summary
|
5
|
-
help
|
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
|
8
|
-
usage
|
7
|
+
usage 'bashly init [--minimal]'
|
8
|
+
usage 'bashly init (-h|--help)'
|
9
9
|
|
10
|
-
option
|
10
|
+
option '-m --minimal', 'Use a minimal configuration file (without commands)'
|
11
11
|
|
12
|
-
environment
|
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?
|
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
|
-
|
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
|
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
|
4
|
+
help 'Generate the bash script to STDOUT'
|
5
5
|
|
6
|
-
usage
|
7
|
-
usage
|
6
|
+
usage 'bashly preview'
|
7
|
+
usage 'bashly preview (-h|--help)'
|
8
8
|
|
9
|
-
environment
|
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
|
4
|
+
help 'Scan the configuration file for errors'
|
5
5
|
|
6
|
-
usage
|
7
|
-
usage
|
6
|
+
usage 'bashly validate [--verbose]'
|
7
|
+
usage 'bashly validate (-h|--help)'
|
8
8
|
|
9
|
-
option
|
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
|
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
|
23
|
+
say '!txtgrn!OK'
|
23
24
|
else
|
24
25
|
say "!txtred!WARNING!txtrst! Found #{deprecations.count} deprecations"
|
25
26
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
27
|
-
|
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
|
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
|
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
|
-
|
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
|
-
@
|
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
|
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
|