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.
- checksums.yaml +4 -4
- data/lib/bashly/commands/add.rb +38 -86
- data/lib/bashly/commands/base.rb +1 -9
- data/lib/bashly/commands/generate.rb +16 -21
- data/lib/bashly/commands/init.rb +0 -2
- data/lib/bashly/commands/preview.rb +0 -2
- data/lib/bashly/commands/validate.rb +1 -9
- data/lib/bashly/concerns/validation_helpers.rb +0 -8
- data/lib/bashly/config_validator.rb +6 -9
- data/lib/bashly/docs/command.yml +1 -1
- data/lib/bashly/docs/env.yml +1 -1
- data/lib/bashly/docs/flag.yml +11 -1
- data/lib/bashly/libraries/base.rb +1 -1
- data/lib/bashly/{templates/lib → libraries/colors}/colors.sh +0 -0
- data/lib/bashly/libraries/{completions_function.rb → completions/completions_function.rb} +0 -0
- data/lib/bashly/libraries/{completions_script.rb → completions/completions_script.rb} +0 -0
- data/lib/bashly/libraries/{completions_yaml.rb → completions/completions_yaml.rb} +0 -0
- data/lib/bashly/{templates/lib → libraries/config}/config.sh +0 -0
- data/lib/bashly/libraries/{help.rb → help/help.rb} +1 -1
- data/lib/bashly/{templates → libraries}/help/help_command.sh +0 -0
- data/lib/bashly/{templates → libraries}/lib/sample_function.sh +0 -0
- data/lib/bashly/libraries/libraries.yml +85 -0
- data/lib/bashly/{templates → libraries/settings}/settings.yml +7 -1
- data/lib/bashly/{templates → libraries/strings}/strings.yml +0 -0
- data/lib/bashly/{templates → libraries}/test/approvals.bash +0 -0
- data/lib/bashly/{templates → libraries}/test/approve +0 -0
- data/lib/bashly/{templates/lib → libraries}/validations/validate_dir_exists.sh +0 -0
- data/lib/bashly/{templates/lib → libraries}/validations/validate_file_exists.sh +0 -0
- data/lib/bashly/{templates/lib → libraries}/validations/validate_integer.sh +0 -0
- data/lib/bashly/{templates/lib → libraries}/validations/validate_not_empty.sh +0 -0
- data/lib/bashly/{templates/lib → libraries/yaml}/yaml.sh +0 -0
- data/lib/bashly/library.rb +14 -25
- data/lib/bashly/library_source.rb +84 -0
- data/lib/bashly/message_strings.rb +1 -1
- data/lib/bashly/script/command.rb +10 -4
- data/lib/bashly/script/flag.rb +1 -1
- data/lib/bashly/settings.rb +21 -4
- data/lib/bashly/version.rb +1 -1
- data/lib/bashly/views/command/long_usage.gtx +2 -2
- data/lib/bashly/views/command/usage_environment_variables.gtx +1 -1
- data/lib/bashly/views/command/usage_flags.gtx +1 -1
- metadata +22 -22
- data/lib/bashly/deprecation.rb +0 -27
- data/lib/bashly/libraries.yml +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7382bd9a007cc8e3c9b4451e7f3fdbccd62bf740f66cc76f24b03c0e6ef1abdd
|
4
|
+
data.tar.gz: 32b2ee626d40efd3f60bab256b08e486b2322b3ef4d429c1de090f0d849f5982
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 947f2accba281a365338b86580fe9113ca0a4e5286fa206ee3d11e3816514113f9af80417298b24101c63b8fc84cd95fbca4d6d6abf2be32d95c2a122f092050
|
7
|
+
data.tar.gz: b70e60017a58d0107e44388dfdf228d3089b39d9e1bb3f650c6b4565905b08604f1a400ed4cb4648cc91846298e8e5320d54f45064f5ecc36dfaacb9e609d8bc
|
data/lib/bashly/commands/add.rb
CHANGED
@@ -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
|
7
|
-
usage 'bashly add
|
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 '-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
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
|
63
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
79
|
-
add_lib 'config'
|
32
|
+
lib_source.cleanup if lib_source.git?
|
80
33
|
end
|
81
34
|
|
82
|
-
|
83
|
-
add_lib 'lib'
|
84
|
-
end
|
35
|
+
private
|
85
36
|
|
86
|
-
def
|
87
|
-
|
88
|
-
add_lib 'settings'
|
37
|
+
def source
|
38
|
+
args['--source']
|
89
39
|
end
|
90
40
|
|
91
|
-
def
|
92
|
-
|
41
|
+
def lib_source
|
42
|
+
@lib_source ||= Bashly::LibrarySource.new source
|
93
43
|
end
|
94
44
|
|
95
|
-
def
|
96
|
-
|
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
|
100
|
-
|
101
|
-
|
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
|
-
|
104
|
-
|
105
|
-
end
|
59
|
+
library.args = args['ARGS']
|
60
|
+
@skip_src_check = lib_source.config.dig name, 'skip_src_check'
|
106
61
|
|
107
|
-
|
108
|
-
add_lib 'yaml'
|
62
|
+
add_library_files library
|
109
63
|
end
|
110
64
|
|
111
|
-
|
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
|
data/lib/bashly/commands/base.rb
CHANGED
@@ -7,7 +7,7 @@ module Bashly
|
|
7
7
|
include AssetHelper
|
8
8
|
|
9
9
|
def config
|
10
|
-
@config ||= Config.new
|
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',
|
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
|
111
|
-
|
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,
|
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
|
data/lib/bashly/commands/init.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/bashly/docs/command.yml
CHANGED
@@ -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
|
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:
|
data/lib/bashly/docs/env.yml
CHANGED
@@ -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.
|
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:
|
data/lib/bashly/docs/flag.yml
CHANGED
@@ -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
|
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:
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -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
|
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/bashly/library.rb
CHANGED
@@ -1,25 +1,12 @@
|
|
1
1
|
module Bashly
|
2
2
|
class Library
|
3
|
-
|
4
|
-
|
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(
|
21
|
-
@
|
22
|
-
@
|
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
|
-
{
|
32
|
-
|
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
|
41
|
+
return nil unless config['handler']
|
53
42
|
|
54
|
-
@custom_handler ||=
|
43
|
+
@custom_handler ||= Module.const_get(config['handler']).new(*args)
|
55
44
|
end
|
56
45
|
|
57
|
-
def
|
58
|
-
|
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
|
@@ -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?
|
data/lib/bashly/script/flag.rb
CHANGED
data/lib/bashly/settings.rb
CHANGED
@@ -3,13 +3,26 @@ module Bashly
|
|
3
3
|
class << self
|
4
4
|
include AssetHelper
|
5
5
|
|
6
|
-
attr_writer
|
7
|
-
:
|
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?(
|
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 '
|
102
|
+
asset 'libraries/settings/settings.yml'
|
86
103
|
end
|
87
104
|
end
|
88
105
|
end
|
data/lib/bashly/version.rb
CHANGED
@@ -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
|
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
|
>
|
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.
|
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-
|
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/
|
154
|
-
- lib/bashly/libraries/
|
155
|
-
- lib/bashly/libraries/
|
156
|
-
- lib/bashly/libraries/
|
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.
|
261
|
+
rubygems_version: 3.4.6
|
262
262
|
signing_key:
|
263
263
|
specification_version: 4
|
264
264
|
summary: Bash Command Line Tool Generator
|
data/lib/bashly/deprecation.rb
DELETED
@@ -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
|
data/lib/bashly/libraries.yml
DELETED
@@ -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}"
|