bashly 0.7.8 → 0.7.9
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/cli.rb +2 -1
- data/lib/bashly/commands/generate.rb +11 -1
- data/lib/bashly/concerns/renderable.rb +8 -1
- data/lib/bashly/config_validator.rb +13 -5
- data/lib/bashly/extensions/yaml.rb +2 -0
- data/lib/bashly/script/argument.rb +13 -1
- data/lib/bashly/script/base.rb +7 -29
- data/lib/bashly/script/catch_all.rb +4 -0
- data/lib/bashly/script/command.rb +13 -1
- data/lib/bashly/script/environment_variable.rb +6 -0
- data/lib/bashly/script/flag.rb +9 -0
- data/lib/bashly/version.rb +1 -1
- data/lib/bashly/views/argument/usage.erb +2 -2
- data/lib/bashly/views/argument/validations.erb +1 -1
- data/lib/bashly/views/command/catch_all_filter.erb +1 -1
- data/lib/bashly/views/command/command_fallback.erb +1 -1
- data/lib/bashly/views/command/command_filter.erb +1 -1
- data/lib/bashly/views/command/command_functions.erb +1 -1
- data/lib/bashly/views/command/default_assignments.erb +1 -1
- data/lib/bashly/views/command/dependencies_filter.erb +1 -1
- data/lib/bashly/views/command/environment_variables_filter.erb +1 -1
- data/lib/bashly/views/command/fixed_flags_filter.erb +1 -1
- data/lib/bashly/views/command/footer.erb +1 -0
- data/lib/bashly/views/command/function.erb +1 -1
- data/lib/bashly/views/command/initialize.erb +1 -1
- data/lib/bashly/views/command/inspect_args.erb +1 -1
- data/lib/bashly/views/command/master_script.erb +1 -0
- data/lib/bashly/views/command/normalize_input.erb +1 -1
- data/lib/bashly/views/command/parse_requirements.erb +1 -1
- data/lib/bashly/views/command/parse_requirements_case.erb +15 -3
- data/lib/bashly/views/command/parse_requirements_while.erb +1 -1
- data/lib/bashly/views/command/required_args_filter.erb +1 -1
- data/lib/bashly/views/command/required_flags_filter.erb +1 -1
- data/lib/bashly/views/command/root_command.erb +1 -1
- data/lib/bashly/views/command/run.erb +1 -1
- data/lib/bashly/views/command/usage.erb +1 -1
- data/lib/bashly/views/command/usage_args.erb +1 -1
- data/lib/bashly/views/command/usage_commands.erb +1 -1
- data/lib/bashly/views/command/usage_environment_variables.erb +1 -1
- data/lib/bashly/views/command/usage_examples.erb +1 -1
- data/lib/bashly/views/command/usage_fixed_flags.erb +1 -1
- data/lib/bashly/views/command/usage_flags.erb +1 -1
- data/lib/bashly/views/command/user_filter.erb +1 -1
- data/lib/bashly/views/command/user_lib.erb +2 -2
- data/lib/bashly/views/command/version_command.erb +1 -1
- data/lib/bashly/views/command/whitelist_filter.erb +11 -1
- data/lib/bashly/views/environment_variable/usage.erb +1 -1
- data/lib/bashly/views/flag/case.erb +1 -1
- data/lib/bashly/views/flag/conflicts.erb +1 -1
- data/lib/bashly/views/flag/usage.erb +1 -1
- data/lib/bashly/views/flag/validations.erb +1 -1
- data/lib/bashly/views/wrapper/bash3_bouncer.erb +1 -1
- data/lib/bashly/views/wrapper/wrapper.erb +1 -1
- data/lib/bashly.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2ef923a576e9bb9e16ec9f78c96c6008772c77d3bfc9520299fc2dd3cd7f3dd3
|
|
4
|
+
data.tar.gz: 593393d64ca6e63216e0e974c580db50db754fe430d319115aef8610c47d39aa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2b0ffb33c0c11b423cb59d594362a0c2c071a685a2ad7d4837cbdc3bb1d6a494bdcce8ff1cb3d19cfb0078ac5f167912a9d2f93c44f173d2821b415fe9cbd92e
|
|
7
|
+
data.tar.gz: c6b6989f3c75226641847feee4e4e8a73326da2a006bbbd52ce7544c7c4ffb3bf1f4a659a15f0b70f14590b1fe0392062099f6ced43134b2a3d81000d5a350f9
|
data/lib/bashly/cli.rb
CHANGED
|
@@ -6,7 +6,8 @@ module Bashly
|
|
|
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
|
+
footer: "Help: !txtpur!bashly COMMAND --help!txtrst!\nDocs: !undblu!https://bashly.dannyb.co"
|
|
10
11
|
|
|
11
12
|
runner.route 'init', to: Commands::Init
|
|
12
13
|
runner.route 'preview', to: Commands::Preview
|
|
@@ -3,24 +3,34 @@ module Bashly
|
|
|
3
3
|
class Generate < Base
|
|
4
4
|
help "Generate the bash script and required files"
|
|
5
5
|
|
|
6
|
-
usage "bashly generate [
|
|
6
|
+
usage "bashly generate [options]"
|
|
7
7
|
usage "bashly generate (-h|--help)"
|
|
8
8
|
|
|
9
9
|
option "-f --force", "Overwrite existing files"
|
|
10
10
|
option "-q --quiet", "Disable on-screen progress report"
|
|
11
11
|
option "-u --upgrade", "Upgrade all added library functions"
|
|
12
12
|
option "-w --wrap FUNCTION", "Wrap the entire script in a function so it can also be sourced"
|
|
13
|
+
option "-e --env ENV", "Force the generation environment (see BASHLY_ENV)"
|
|
13
14
|
|
|
14
15
|
environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
|
|
15
16
|
environment "BASHLY_TARGET_DIR", "The path to use for creating the bash script [default: .]"
|
|
16
17
|
environment "BASHLY_LIB_DIR", "The path to use for upgrading library files, relative to the source dir [default: lib]"
|
|
17
18
|
environment "BASHLY_STRICT", "When not empty, enable bash strict mode (set -euo pipefail)"
|
|
19
|
+
environment "BASHLY_ENV", <<~EOF
|
|
20
|
+
Set to 'production' or 'development':
|
|
21
|
+
- production generate a smaller script, without file markers
|
|
22
|
+
- development generate with file markers
|
|
23
|
+
|
|
24
|
+
Can be overridden with --env [default: development]
|
|
25
|
+
EOF
|
|
18
26
|
|
|
19
27
|
example "bashly generate --force"
|
|
20
28
|
example "bashly generate --wrap my_function"
|
|
21
29
|
|
|
22
30
|
def run
|
|
23
31
|
validate_config
|
|
32
|
+
ENV['BASHLY_ENV'] = args['--env'] if args['--env']
|
|
33
|
+
quiet_say "creating !txtgrn!production!txtrst! version" if Bashly.production?
|
|
24
34
|
create_user_files
|
|
25
35
|
upgrade_libs if args['--upgrade']
|
|
26
36
|
create_master_script
|
|
@@ -4,13 +4,20 @@ module Bashly
|
|
|
4
4
|
module Renderable
|
|
5
5
|
def render(view)
|
|
6
6
|
template = File.read view_path(view)
|
|
7
|
-
ERB.new(template, trim_mode: '%-')
|
|
7
|
+
erb = ERB.new(template, trim_mode: '%-')
|
|
8
|
+
erb.filename = "#{views_subfolder}.#{view}"
|
|
9
|
+
erb.result binding
|
|
8
10
|
end
|
|
9
11
|
|
|
10
12
|
def strings
|
|
11
13
|
@strings ||= MessageStrings.new
|
|
12
14
|
end
|
|
13
15
|
|
|
16
|
+
def view_marker(id = nil)
|
|
17
|
+
id ||= ":#{caller_locations.first.path}"
|
|
18
|
+
"# #{id}" unless Bashly.production?
|
|
19
|
+
end
|
|
20
|
+
|
|
14
21
|
private
|
|
15
22
|
|
|
16
23
|
def view_path(view)
|
|
@@ -42,8 +42,13 @@ module Bashly
|
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
def assert_hash(key, value)
|
|
45
|
+
def assert_hash(key, value, whitelist = nil)
|
|
46
46
|
assert value.is_a?(Hash), "#{key} must be a hash"
|
|
47
|
+
|
|
48
|
+
if whitelist
|
|
49
|
+
invalid_keys = value.keys.map(&:to_sym) - whitelist
|
|
50
|
+
assert invalid_keys.empty?, "#{key} contains invalid options: #{invalid_keys.join(', ')}"
|
|
51
|
+
end
|
|
47
52
|
end
|
|
48
53
|
|
|
49
54
|
def assert_version(key, value)
|
|
@@ -61,6 +66,7 @@ module Bashly
|
|
|
61
66
|
end
|
|
62
67
|
|
|
63
68
|
def assert_catch_all_hash(key, value)
|
|
69
|
+
assert_hash key, value, Script::CatchAll.option_keys
|
|
64
70
|
assert_string "#{key}.label", value['label']
|
|
65
71
|
assert_optional_string "#{key}.help", value['help']
|
|
66
72
|
assert_boolean "#{key}.required", value['required']
|
|
@@ -73,7 +79,7 @@ module Bashly
|
|
|
73
79
|
end
|
|
74
80
|
|
|
75
81
|
def assert_arg(key, value)
|
|
76
|
-
assert_hash key, value
|
|
82
|
+
assert_hash key, value, Script::Argument.option_keys
|
|
77
83
|
assert_string "#{key}.name", value['name']
|
|
78
84
|
assert_optional_string "#{key}.help", value['help']
|
|
79
85
|
assert_optional_string "#{key}.default", value['default']
|
|
@@ -89,7 +95,7 @@ module Bashly
|
|
|
89
95
|
end
|
|
90
96
|
|
|
91
97
|
def assert_flag(key, value)
|
|
92
|
-
assert_hash key, value
|
|
98
|
+
assert_hash key, value, Script::Flag.option_keys
|
|
93
99
|
assert value['short'] || value['long'], "#{key} must have at least one of long or short name"
|
|
94
100
|
|
|
95
101
|
assert_optional_string "#{key}.long", value['long']
|
|
@@ -99,6 +105,7 @@ module Bashly
|
|
|
99
105
|
assert_optional_string "#{key}.default", value['default']
|
|
100
106
|
assert_optional_string "#{key}.validate", value['validate']
|
|
101
107
|
|
|
108
|
+
assert_boolean "#{key}.repeatable", value['repeatable']
|
|
102
109
|
assert_boolean "#{key}.required", value['required']
|
|
103
110
|
assert_array "#{key}.allowed", value['allowed'], of: :string
|
|
104
111
|
assert_array "#{key}.conflicts", value['conflicts'], of: :string
|
|
@@ -119,7 +126,7 @@ module Bashly
|
|
|
119
126
|
end
|
|
120
127
|
|
|
121
128
|
def assert_env_var(key, value)
|
|
122
|
-
assert_hash key, value
|
|
129
|
+
assert_hash key, value, Script::EnvironmentVariable.option_keys
|
|
123
130
|
assert_string "#{key}.name", value['name']
|
|
124
131
|
assert_optional_string "#{key}.help", value['help']
|
|
125
132
|
assert_optional_string "#{key}.default", value['default']
|
|
@@ -127,7 +134,7 @@ module Bashly
|
|
|
127
134
|
end
|
|
128
135
|
|
|
129
136
|
def assert_command(key, value)
|
|
130
|
-
assert_hash key, value
|
|
137
|
+
assert_hash key, value, Script::Command.option_keys
|
|
131
138
|
|
|
132
139
|
refute value['commands'] && value['args'], "#{key} cannot have both commands and args"
|
|
133
140
|
refute value['commands'] && value['flags'], "#{key} cannot have both commands and flags"
|
|
@@ -139,6 +146,7 @@ module Bashly
|
|
|
139
146
|
assert_optional_string "#{key}.group", value['group']
|
|
140
147
|
assert_optional_string "#{key}.filename", value['filename']
|
|
141
148
|
|
|
149
|
+
assert_boolean "#{key}.private", value['private']
|
|
142
150
|
assert_boolean "#{key}.default", value['default']
|
|
143
151
|
assert_version "#{key}.version", value['version']
|
|
144
152
|
assert_catch_all "#{key}.catch_all", value['catch_all']
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
module Bashly
|
|
2
2
|
module Script
|
|
3
3
|
class Argument < Base
|
|
4
|
+
class << self
|
|
5
|
+
def option_keys
|
|
6
|
+
@option_keys ||= %i[
|
|
7
|
+
allowed default help name repeatable required validate
|
|
8
|
+
]
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
4
12
|
def usage_string
|
|
5
|
-
required ?
|
|
13
|
+
required ? label : "[#{label}]"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def label
|
|
17
|
+
repeatable ? "#{name.upcase}..." : name.upcase
|
|
6
18
|
end
|
|
7
19
|
end
|
|
8
20
|
end
|
data/lib/bashly/script/base.rb
CHANGED
|
@@ -5,33 +5,11 @@ module Bashly
|
|
|
5
5
|
|
|
6
6
|
attr_reader :options
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
conflicts
|
|
14
|
-
default
|
|
15
|
-
dependencies
|
|
16
|
-
description
|
|
17
|
-
environment_variables
|
|
18
|
-
examples
|
|
19
|
-
extensible
|
|
20
|
-
filters
|
|
21
|
-
flags
|
|
22
|
-
footer
|
|
23
|
-
group
|
|
24
|
-
help
|
|
25
|
-
long
|
|
26
|
-
name
|
|
27
|
-
parent_name
|
|
28
|
-
private
|
|
29
|
-
repeatable
|
|
30
|
-
required
|
|
31
|
-
short
|
|
32
|
-
validate
|
|
33
|
-
version
|
|
34
|
-
]
|
|
8
|
+
class << self
|
|
9
|
+
def option_keys
|
|
10
|
+
@option_keys ||= []
|
|
11
|
+
end
|
|
12
|
+
end
|
|
35
13
|
|
|
36
14
|
def initialize(options)
|
|
37
15
|
raise Error, "Invalid options provided" unless options.respond_to? :keys
|
|
@@ -39,7 +17,7 @@ module Bashly
|
|
|
39
17
|
end
|
|
40
18
|
|
|
41
19
|
def optional
|
|
42
|
-
!required
|
|
20
|
+
!options['required']
|
|
43
21
|
end
|
|
44
22
|
|
|
45
23
|
def summary
|
|
@@ -56,7 +34,7 @@ module Bashly
|
|
|
56
34
|
end
|
|
57
35
|
|
|
58
36
|
def respond_to_missing?(method_name, include_private = false)
|
|
59
|
-
|
|
37
|
+
self.class.option_keys.include?(method_name) || super
|
|
60
38
|
end
|
|
61
39
|
end
|
|
62
40
|
end
|
|
@@ -4,6 +4,18 @@ module Bashly
|
|
|
4
4
|
include Completions
|
|
5
5
|
include CommandScopes
|
|
6
6
|
|
|
7
|
+
class << self
|
|
8
|
+
def option_keys
|
|
9
|
+
@option_keys ||= %i[
|
|
10
|
+
args catch_all commands completions
|
|
11
|
+
default dependencies environment_variables examples
|
|
12
|
+
extensible filename filters flags
|
|
13
|
+
footer group help name
|
|
14
|
+
private short version
|
|
15
|
+
]
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
7
19
|
# Returns the name to be used as an action.
|
|
8
20
|
# - If it is the root command, the action is "root"
|
|
9
21
|
# - Else, it is all the parents, except the first one (root) joined
|
|
@@ -90,7 +102,7 @@ module Bashly
|
|
|
90
102
|
default_content
|
|
91
103
|
end
|
|
92
104
|
|
|
93
|
-
"#
|
|
105
|
+
Bashly.production? ? content : "#{view_marker path}\n#{content}"
|
|
94
106
|
end
|
|
95
107
|
|
|
96
108
|
# Returns an array of all parents. For example, the command
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
module Bashly
|
|
2
2
|
module Script
|
|
3
3
|
class EnvironmentVariable < Base
|
|
4
|
+
class << self
|
|
5
|
+
def option_keys
|
|
6
|
+
@option_keys ||= %i[default help name required]
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
4
10
|
def usage_string(extended: false)
|
|
5
11
|
result = [name.upcase]
|
|
6
12
|
result << strings[:required] if required and extended
|
data/lib/bashly/script/flag.rb
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
module Bashly
|
|
2
2
|
module Script
|
|
3
3
|
class Flag < Base
|
|
4
|
+
class << self
|
|
5
|
+
def option_keys
|
|
6
|
+
@option_keys ||= %i[
|
|
7
|
+
allowed arg conflicts default help long repeatable required
|
|
8
|
+
short validate
|
|
9
|
+
]
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
4
13
|
def aliases
|
|
5
14
|
if long and short
|
|
6
15
|
[long, short]
|
data/lib/bashly/version.rb
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
<%= view_marker %>
|
|
2
|
+
% repeatable_arg = false
|
|
2
3
|
% if args.any?
|
|
3
4
|
% condition = "if"
|
|
4
5
|
% args.each do |arg|
|
|
5
6
|
<%= condition %> [[ -z ${args[<%= arg.name %>]+x} ]]; then
|
|
6
7
|
<%= arg.render(:validations).indent 2 %>
|
|
8
|
+
% if arg.repeatable
|
|
9
|
+
% repeatable_arg = true
|
|
10
|
+
args[<%= arg.name %>]="\"$1\""
|
|
11
|
+
shift
|
|
12
|
+
else
|
|
13
|
+
args[<%= arg.name %>]="${args[<%= arg.name %>]} \"$1\""
|
|
14
|
+
shift
|
|
15
|
+
% else
|
|
7
16
|
args[<%= arg.name %>]=$1
|
|
8
17
|
shift
|
|
18
|
+
% end
|
|
9
19
|
% condition = "elif"
|
|
10
20
|
% end
|
|
21
|
+
% if !repeatable_arg
|
|
11
22
|
else
|
|
23
|
+
% end
|
|
12
24
|
% if catch_all.enabled?
|
|
13
25
|
other_args+=("$1")
|
|
14
26
|
shift
|
|
15
|
-
%
|
|
27
|
+
% elsif !repeatable_arg
|
|
16
28
|
printf "<%= strings[:invalid_argument] %>\n" "$key"
|
|
17
29
|
exit 1
|
|
18
30
|
% end
|
|
@@ -20,7 +32,7 @@ fi
|
|
|
20
32
|
% elsif catch_all.enabled?
|
|
21
33
|
other_args+=("$1")
|
|
22
34
|
shift
|
|
23
|
-
%
|
|
35
|
+
% elsif !repeatable_arg
|
|
24
36
|
printf "<%= strings[:invalid_argument] %>\n" "$key"
|
|
25
37
|
exit 1
|
|
26
38
|
% end
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
<%= view_marker %>
|
|
2
2
|
% whitelisted_args.each do |arg|
|
|
3
|
+
% if arg.repeatable
|
|
4
|
+
eval "input_array=(${args[<%= arg.name %>]})"
|
|
5
|
+
for i in "${input_array[@]}"; do
|
|
6
|
+
if [[ ! $i =~ ^(<%= arg.allowed.join '|' %>)$ ]]; then
|
|
7
|
+
printf "%s\n" "<%= strings[:disallowed_argument] % { name: arg.name, allowed: arg.allowed.join(', ') } %>"
|
|
8
|
+
exit 1
|
|
9
|
+
fi
|
|
10
|
+
done
|
|
11
|
+
% else
|
|
3
12
|
if [[ ! ${args[<%= arg.name %>]} =~ ^(<%= arg.allowed.join '|' %>)$ ]]; then
|
|
4
13
|
printf "%s\n" "<%= strings[:disallowed_argument] % { name: arg.name, allowed: arg.allowed.join(', ') } %>"
|
|
5
14
|
exit 1
|
|
6
15
|
fi
|
|
7
16
|
% end
|
|
17
|
+
% end
|
|
8
18
|
% whitelisted_flags.each do |flag|
|
|
9
19
|
% if flag.repeatable
|
|
10
20
|
eval "input_array=(${args[<%= flag.name %>]})"
|
data/lib/bashly.rb
CHANGED
|
@@ -15,3 +15,15 @@ requires 'bashly/script/base'
|
|
|
15
15
|
requires 'bashly/commands/base'
|
|
16
16
|
requires 'bashly/libraries/base'
|
|
17
17
|
requires 'bashly'
|
|
18
|
+
|
|
19
|
+
module Bashly
|
|
20
|
+
class << self
|
|
21
|
+
def env
|
|
22
|
+
ENV['BASHLY_ENV']&.to_sym
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def production?
|
|
26
|
+
env == :production
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bashly
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.7.
|
|
4
|
+
version: 0.7.9
|
|
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: 2022-
|
|
11
|
+
date: 2022-04-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: colsole
|