bashly 0.7.9 → 0.7.10
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 +41 -33
- data/lib/bashly/commands/generate.rb +4 -3
- data/lib/bashly/concerns/renderable.rb +1 -1
- data/lib/bashly/config_validator.rb +6 -1
- data/lib/bashly/extensions/string.rb +6 -0
- data/lib/bashly/libraries.yml +13 -9
- data/lib/bashly/script/command.rb +12 -6
- data/lib/bashly/script/wrapper.rb +11 -7
- data/lib/bashly/settings.rb +34 -5
- data/lib/bashly/templates/settings.yml +24 -0
- data/lib/bashly/version.rb +1 -1
- data/lib/bashly/views/command/parse_requirements_case.erb +5 -35
- data/lib/bashly/views/command/parse_requirements_case_catch_all.erb +18 -0
- data/lib/bashly/views/command/parse_requirements_case_repeatable.erb +18 -0
- data/lib/bashly/views/command/parse_requirements_case_simple.erb +18 -0
- data/lib/bashly/views/flag/case.erb +1 -27
- data/lib/bashly/views/flag/case_arg.erb +19 -0
- data/lib/bashly/views/flag/case_no_arg.erb +8 -0
- data/lib/bashly.rb +0 -12
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 471a0ae8e462a056c196ebf128f02f3f30ff3a100c10aff2d2c010757d6d942e
|
4
|
+
data.tar.gz: d78cf8473f40b241ee412a00d819be124a244acda1f487f20e105dee1cba9842
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77617bc6668796730c67d33621d497a8a454a6208d7f42d7c28ecb26e940da2e4edee6b3aefd8fc98b301d8480a13f14c1f6b292ff7f4d29b6030e601cdc1b08
|
7
|
+
data.tar.gz: d7b851826c9dde19201f2fb48b5f4b5ff0cd9a2421f4770ed3fdbc1c340943b9d0c3b3703b26646e46dfb012dca0c2a10728c568786ac4c381ab1431dc191695
|
data/lib/bashly/commands/add.rb
CHANGED
@@ -3,14 +3,15 @@ module Bashly
|
|
3
3
|
class Add < Base
|
4
4
|
help "Add extra features and customization to your script"
|
5
5
|
|
6
|
-
usage "bashly add strings [--force]"
|
7
|
-
usage "bashly add lib [--force]"
|
8
|
-
usage "bashly add config [--force]"
|
9
6
|
usage "bashly add colors [--force]"
|
10
|
-
usage "bashly add yaml [--force]"
|
11
|
-
usage "bashly add validations [--force]"
|
12
|
-
usage "bashly add test [--force]"
|
13
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]"
|
14
15
|
usage "bashly add (-h|--help)"
|
15
16
|
|
16
17
|
option "-f --force", "Overwrite existing files"
|
@@ -18,14 +19,15 @@ module Bashly
|
|
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."
|
19
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."
|
20
21
|
|
21
|
-
command "strings", "Copy an additional configuration file to your project, allowing you to customize all the tips and error strings."
|
22
|
-
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."
|
23
|
-
command "config", "Add standard functions for handling INI files to the lib directory."
|
24
22
|
command "colors", "Add standard functions for printing colorful and formatted text to the lib directory."
|
25
|
-
command "yaml", "Add standard functions for reading YAML files to the lib directory."
|
26
|
-
command "validations", "Add argument validation functions to the lib directory."
|
27
|
-
command "test", "Add approval testing."
|
28
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."
|
29
31
|
|
30
32
|
example "bashly add strings --force"
|
31
33
|
example "bashly add comp function"
|
@@ -34,45 +36,51 @@ module Bashly
|
|
34
36
|
environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
|
35
37
|
environment "BASHLY_LIB_DIR", "The path to use for creating the library files, relative to the source dir [default: lib]"
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
+
attr_reader :skip_src_check
|
40
|
+
|
41
|
+
def colors_command
|
42
|
+
add_lib 'colors'
|
39
43
|
end
|
40
44
|
|
41
|
-
def
|
42
|
-
|
45
|
+
def comp_command
|
46
|
+
format = args['FORMAT']
|
47
|
+
output = args['OUTPUT']
|
48
|
+
|
49
|
+
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
|
53
|
+
else raise Error, "Unrecognized format: #{format}"
|
54
|
+
end
|
43
55
|
end
|
44
56
|
|
45
57
|
def config_command
|
46
58
|
add_lib 'config'
|
47
59
|
end
|
48
60
|
|
49
|
-
def
|
50
|
-
|
61
|
+
def settings_command
|
62
|
+
@skip_src_check = true
|
63
|
+
add_lib 'settings'
|
51
64
|
end
|
52
65
|
|
53
|
-
def
|
54
|
-
add_lib '
|
66
|
+
def strings_command
|
67
|
+
add_lib 'strings'
|
55
68
|
end
|
56
69
|
|
57
|
-
def
|
58
|
-
add_lib '
|
70
|
+
def lib_command
|
71
|
+
add_lib 'lib'
|
59
72
|
end
|
60
73
|
|
61
74
|
def test_command
|
62
75
|
add_lib 'test'
|
63
76
|
end
|
64
77
|
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
case format
|
70
|
-
when "script" then add_lib 'completions_script', output
|
71
|
-
when "function" then add_lib 'completions', output
|
72
|
-
when "yaml" then add_lib 'completions_yaml', output
|
73
|
-
else raise Error, "Unrecognized format: #{format}"
|
74
|
-
end
|
78
|
+
def yaml_command
|
79
|
+
add_lib 'yaml'
|
80
|
+
end
|
75
81
|
|
82
|
+
def validations_command
|
83
|
+
add_lib 'validations'
|
76
84
|
end
|
77
85
|
|
78
86
|
private
|
@@ -89,7 +97,7 @@ module Bashly
|
|
89
97
|
end
|
90
98
|
|
91
99
|
def safe_write(path, content)
|
92
|
-
if !Dir.exist? Settings.source_dir
|
100
|
+
if !skip_src_check and !Dir.exist? Settings.source_dir
|
93
101
|
raise InitError, "Directory !txtgrn!#{Settings.source_dir}!txtrst! does not exist\nRun !txtpur!bashly init!txtrst! first"
|
94
102
|
end
|
95
103
|
|
@@ -16,6 +16,7 @@ module Bashly
|
|
16
16
|
environment "BASHLY_TARGET_DIR", "The path to use for creating the bash script [default: .]"
|
17
17
|
environment "BASHLY_LIB_DIR", "The path to use for upgrading library files, relative to the source dir [default: lib]"
|
18
18
|
environment "BASHLY_STRICT", "When not empty, enable bash strict mode (set -euo pipefail)"
|
19
|
+
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)"
|
19
20
|
environment "BASHLY_ENV", <<~EOF
|
20
21
|
Set to 'production' or 'development':
|
21
22
|
- production generate a smaller script, without file markers
|
@@ -29,8 +30,8 @@ module Bashly
|
|
29
30
|
|
30
31
|
def run
|
31
32
|
validate_config
|
32
|
-
|
33
|
-
quiet_say "creating !txtgrn!production!txtrst! version" if
|
33
|
+
Settings.env = args['--env'] if args['--env']
|
34
|
+
quiet_say "creating !txtgrn!production!txtrst! version" if Settings.production?
|
34
35
|
create_user_files
|
35
36
|
upgrade_libs if args['--upgrade']
|
36
37
|
create_master_script
|
@@ -114,7 +115,7 @@ module Bashly
|
|
114
115
|
end
|
115
116
|
|
116
117
|
def create_master_script
|
117
|
-
File.write master_script_path, script.code
|
118
|
+
File.write master_script_path, script.code(tab_indent: Settings.tab_indent)
|
118
119
|
FileUtils.chmod "+x", master_script_path
|
119
120
|
quiet_say "!txtgrn!created!txtrst! #{master_script_path}"
|
120
121
|
end
|
@@ -138,7 +138,7 @@ module Bashly
|
|
138
138
|
|
139
139
|
refute value['commands'] && value['args'], "#{key} cannot have both commands and args"
|
140
140
|
refute value['commands'] && value['flags'], "#{key} cannot have both commands and flags"
|
141
|
-
|
141
|
+
|
142
142
|
assert_string "#{key}.name", value['name']
|
143
143
|
assert_optional_string "#{key}.short", value['short']
|
144
144
|
assert_optional_string "#{key}.help", value['help']
|
@@ -161,6 +161,11 @@ module Bashly
|
|
161
161
|
assert_array "#{key}.environment_variables", value['environment_variables'], of: :env_var
|
162
162
|
assert_array "#{key}.examples", value['examples'], of: :string
|
163
163
|
|
164
|
+
if value['catch_all'] and value['args']
|
165
|
+
repeatable_arg = value['args'].select { |a| a['repeatable'] }.first&.dig 'name'
|
166
|
+
refute repeatable_arg, "#{key}.catch_all makes no sense with repeatable arg (#{repeatable_arg})"
|
167
|
+
end
|
168
|
+
|
164
169
|
if key == "root"
|
165
170
|
refute value['short'], "#{key}.short makes no sense"
|
166
171
|
refute value['group'], "#{key}.group makes no sense"
|
data/lib/bashly/libraries.yml
CHANGED
@@ -3,21 +3,25 @@ colors:
|
|
3
3
|
- source: "templates/lib/colors.sh"
|
4
4
|
target: "%{user_lib_dir}/colors.sh"
|
5
5
|
|
6
|
+
completions: :CompletionsFunction
|
7
|
+
completions_script: :CompletionsScript
|
8
|
+
completions_yaml: :CompletionsYAML
|
9
|
+
|
6
10
|
config:
|
7
11
|
files:
|
8
12
|
- source: "templates/lib/config.sh"
|
9
13
|
target: "%{user_lib_dir}/config.sh"
|
10
14
|
|
11
|
-
yaml:
|
12
|
-
files:
|
13
|
-
- source: "templates/lib/yaml.sh"
|
14
|
-
target: "%{user_lib_dir}/yaml.sh"
|
15
|
-
|
16
15
|
lib:
|
17
16
|
files:
|
18
17
|
- source: "templates/lib/sample_function.sh"
|
19
18
|
target: "%{user_lib_dir}/sample_function.sh"
|
20
19
|
|
20
|
+
settings:
|
21
|
+
files:
|
22
|
+
- source: "templates/settings.yml"
|
23
|
+
target: "settings.yml"
|
24
|
+
|
21
25
|
strings:
|
22
26
|
files:
|
23
27
|
- source: "templates/strings.yml"
|
@@ -37,7 +41,6 @@ test:
|
|
37
41
|
|
38
42
|
Docs: !undblu!https://github.com/DannyBen/approvals.bash
|
39
43
|
|
40
|
-
|
41
44
|
validations:
|
42
45
|
files:
|
43
46
|
- source: "templates/lib/validations/validate_dir_exists.sh"
|
@@ -49,6 +52,7 @@ validations:
|
|
49
52
|
- source: "templates/lib/validations/validate_not_empty.sh"
|
50
53
|
target: "%{user_lib_dir}/validations/validate_not_empty.sh"
|
51
54
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
+
yaml:
|
56
|
+
files:
|
57
|
+
- source: "templates/lib/yaml.sh"
|
58
|
+
target: "%{user_lib_dir}/yaml.sh"
|
@@ -40,7 +40,7 @@ module Bashly
|
|
40
40
|
|
41
41
|
# Returns a string suitable to be a headline
|
42
42
|
def caption_string
|
43
|
-
help ? "#{full_name} - #{summary}"
|
43
|
+
help.empty? ? full_name : "#{full_name} - #{summary}"
|
44
44
|
end
|
45
45
|
|
46
46
|
def catch_all
|
@@ -94,15 +94,16 @@ module Bashly
|
|
94
94
|
# If the file is not found, returns a string with a hint.
|
95
95
|
def load_user_file(file, placeholder: true)
|
96
96
|
path = "#{Settings.source_dir}/#{file}"
|
97
|
-
default_content = placeholder ? "echo \"error: cannot load file\"" : ''
|
98
97
|
|
99
98
|
content = if File.exist? path
|
100
99
|
File.read(path).remove_front_matter
|
101
|
-
|
102
|
-
|
100
|
+
elsif placeholder
|
101
|
+
%q[echo "error: cannot load file"]
|
102
|
+
else
|
103
|
+
''
|
103
104
|
end
|
104
105
|
|
105
|
-
|
106
|
+
Settings.production? ? content : "#{view_marker path}\n#{content}"
|
106
107
|
end
|
107
108
|
|
108
109
|
# Returns an array of all parents. For example, the command
|
@@ -111,7 +112,12 @@ module Bashly
|
|
111
112
|
options['parents'] || []
|
112
113
|
end
|
113
114
|
|
114
|
-
# Returns
|
115
|
+
# Returns true if one of the args is repeatable
|
116
|
+
def repeatable_arg_exist?
|
117
|
+
args.select(&:repeatable).any?
|
118
|
+
end
|
119
|
+
|
120
|
+
# Returns true if this is the root command (no parents)
|
115
121
|
def root_command?
|
116
122
|
parents.empty?
|
117
123
|
end
|
@@ -9,18 +9,22 @@ module Bashly
|
|
9
9
|
@command, @function_name = command, function_name
|
10
10
|
end
|
11
11
|
|
12
|
-
def code
|
13
|
-
|
14
|
-
|
12
|
+
def code(tab_indent: false)
|
13
|
+
tab_indent ? base_code.expand_tabs : base_code
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def base_code
|
19
|
+
result = if function_name
|
20
|
+
[header, render('wrapper')]
|
15
21
|
else
|
16
|
-
|
22
|
+
[header, body]
|
17
23
|
end
|
18
24
|
|
19
|
-
result.lint
|
25
|
+
result.join("\n").lint
|
20
26
|
end
|
21
27
|
|
22
|
-
private
|
23
|
-
|
24
28
|
def header
|
25
29
|
@header ||= header!
|
26
30
|
end
|
data/lib/bashly/settings.rb
CHANGED
@@ -1,27 +1,56 @@
|
|
1
1
|
module Bashly
|
2
2
|
class Settings
|
3
3
|
class << self
|
4
|
-
attr_writer :source_dir, :target_dir, :lib_dir, :strict
|
4
|
+
attr_writer :source_dir, :target_dir, :lib_dir, :strict, :tab_indent
|
5
5
|
|
6
6
|
def source_dir
|
7
|
-
@source_dir ||=
|
7
|
+
@source_dir ||= get :source_dir, 'src'
|
8
8
|
end
|
9
9
|
|
10
10
|
def target_dir
|
11
|
-
@target_dir ||=
|
11
|
+
@target_dir ||= get :target_dir, '.'
|
12
12
|
end
|
13
13
|
|
14
14
|
def lib_dir
|
15
|
-
@lib_dir ||=
|
15
|
+
@lib_dir ||= get :lib_dir, 'lib'
|
16
16
|
end
|
17
17
|
|
18
18
|
def strict
|
19
|
-
@strict ||=
|
19
|
+
@strict ||= get :strict
|
20
|
+
end
|
21
|
+
|
22
|
+
def tab_indent
|
23
|
+
@tab_indent ||= get :tab_indent
|
24
|
+
end
|
25
|
+
|
26
|
+
def env
|
27
|
+
@env ||= get(:env, :development)&.to_sym
|
28
|
+
end
|
29
|
+
|
30
|
+
def env=(value)
|
31
|
+
@env = value&.to_sym
|
32
|
+
end
|
33
|
+
|
34
|
+
def production?
|
35
|
+
env == :production
|
20
36
|
end
|
21
37
|
|
22
38
|
def full_lib_dir
|
23
39
|
"#{source_dir}/#{lib_dir}"
|
24
40
|
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def get(key, default = nil)
|
45
|
+
ENV["BASHLY_#{key.upcase}"] || user_settings[key.to_s] || default
|
46
|
+
end
|
47
|
+
|
48
|
+
def user_settings
|
49
|
+
@user_settings ||= begin
|
50
|
+
File.exist?('settings.yml') ? Config.new('settings.yml') : {}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
25
54
|
end
|
26
55
|
end
|
27
56
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# All settings are optional (with their default values provided below), and
|
2
|
+
# can also be set with an environment variable with the same name, capitalized
|
3
|
+
# and prefixed by `BASHLY_` - for example: BASHLY_SOURCE_DIR
|
4
|
+
|
5
|
+
# The path containing the bashly configuration and source files
|
6
|
+
source_dir: src
|
7
|
+
|
8
|
+
# The path to use for creating the bash script
|
9
|
+
target_dir: .
|
10
|
+
|
11
|
+
# The path to use for upgrading library files, relative to the source dir
|
12
|
+
lib_dir: lib
|
13
|
+
|
14
|
+
# When true, enable bash strict mode (set -euo pipefail)
|
15
|
+
strict: false
|
16
|
+
|
17
|
+
# When true, the generated script will use tab indentation instead of spaces
|
18
|
+
# (every 2 leading spaces will be converted to a tab character)
|
19
|
+
tab_indent: false
|
20
|
+
|
21
|
+
# Set to 'production' or 'development':
|
22
|
+
# - production generate a smaller script, without file markers
|
23
|
+
# - development generate with file markers
|
24
|
+
env: development
|
data/lib/bashly/version.rb
CHANGED
@@ -1,38 +1,8 @@
|
|
1
1
|
<%= view_marker %>
|
2
|
-
% repeatable_arg = false
|
3
|
-
% if args.any?
|
4
|
-
% condition = "if"
|
5
|
-
% args.each do |arg|
|
6
|
-
<%= condition %> [[ -z ${args[<%= arg.name %>]+x} ]]; then
|
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
|
16
|
-
args[<%= arg.name %>]=$1
|
17
|
-
shift
|
18
|
-
% end
|
19
|
-
% condition = "elif"
|
20
|
-
% end
|
21
|
-
% if !repeatable_arg
|
22
|
-
else
|
23
|
-
% end
|
24
2
|
% if catch_all.enabled?
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
% end
|
31
|
-
fi
|
32
|
-
% elsif catch_all.enabled?
|
33
|
-
other_args+=("$1")
|
34
|
-
shift
|
35
|
-
% elsif !repeatable_arg
|
36
|
-
printf "<%= strings[:invalid_argument] %>\n" "$key"
|
37
|
-
exit 1
|
3
|
+
<%= render(:parse_requirements_case_catch_all) %>
|
4
|
+
% elsif repeatable_arg_exist?
|
5
|
+
<%= render(:parse_requirements_case_repeatable) %>
|
6
|
+
% else
|
7
|
+
<%= render(:parse_requirements_case_simple) %>
|
38
8
|
% end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<%= view_marker %>
|
2
|
+
% if args.any?
|
3
|
+
% condition = "if"
|
4
|
+
% args.each do |arg|
|
5
|
+
<%= condition %> [[ -z ${args[<%= arg.name %>]+x} ]]; then
|
6
|
+
<%= arg.render(:validations).indent 2 %>
|
7
|
+
args[<%= arg.name %>]=$1
|
8
|
+
shift
|
9
|
+
% condition = "elif"
|
10
|
+
% end
|
11
|
+
else
|
12
|
+
other_args+=("$1")
|
13
|
+
shift
|
14
|
+
fi
|
15
|
+
% else
|
16
|
+
other_args+=("$1")
|
17
|
+
shift
|
18
|
+
% end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<%= view_marker %>
|
2
|
+
% condition = "if"
|
3
|
+
% args.each do |arg|
|
4
|
+
<%= condition %> [[ -z ${args[<%= arg.name %>]+x} ]]; then
|
5
|
+
<%= arg.render(:validations).indent 2 %>
|
6
|
+
% if arg.repeatable
|
7
|
+
args[<%= arg.name %>]="\"$1\""
|
8
|
+
shift
|
9
|
+
else
|
10
|
+
args[<%= arg.name %>]="${args[<%= arg.name %>]} \"$1\""
|
11
|
+
shift
|
12
|
+
% else
|
13
|
+
args[<%= arg.name %>]=$1
|
14
|
+
shift
|
15
|
+
% end
|
16
|
+
% condition = "elif"
|
17
|
+
% end
|
18
|
+
fi
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<%= view_marker %>
|
2
|
+
% if args.any?
|
3
|
+
% condition = "if"
|
4
|
+
% args.each do |arg|
|
5
|
+
<%= condition %> [[ -z ${args[<%= arg.name %>]+x} ]]; then
|
6
|
+
<%= arg.render(:validations).indent 2 %>
|
7
|
+
args[<%= arg.name %>]=$1
|
8
|
+
shift
|
9
|
+
% condition = "elif"
|
10
|
+
% end
|
11
|
+
else
|
12
|
+
printf "<%= strings[:invalid_argument] %>\n" "$key"
|
13
|
+
exit 1
|
14
|
+
fi
|
15
|
+
% else
|
16
|
+
printf "<%= strings[:invalid_argument] %>\n" "$key"
|
17
|
+
exit 1
|
18
|
+
% end
|
@@ -1,30 +1,4 @@
|
|
1
1
|
<%= view_marker %>
|
2
2
|
<%= aliases.join " | " %> )
|
3
3
|
<%= render(:conflicts).indent 2 %>
|
4
|
-
|
5
|
-
if [[ -n ${2+x} ]]; then
|
6
|
-
<%= render(:validations).indent 4 %>
|
7
|
-
% if repeatable
|
8
|
-
if [[ -z ${args[<%= name %>]+x} ]]; then
|
9
|
-
args[<%= name %>]="\"$2\""
|
10
|
-
else
|
11
|
-
args[<%= name %>]="${args[<%= name %>]} \"$2\""
|
12
|
-
fi
|
13
|
-
% else
|
14
|
-
args[<%= name %>]="$2"
|
15
|
-
% end
|
16
|
-
shift
|
17
|
-
shift
|
18
|
-
else
|
19
|
-
printf "%s\n" "<%= strings[:flag_requires_an_argument] % { name: name, usage: usage_string } %>"
|
20
|
-
exit 1
|
21
|
-
fi
|
22
|
-
% else
|
23
|
-
% if repeatable
|
24
|
-
(( args[<%= name %>]+=1 ))
|
25
|
-
% else
|
26
|
-
args[<%= name %>]=1
|
27
|
-
% end
|
28
|
-
shift
|
29
|
-
% end
|
30
|
-
;;
|
4
|
+
<%= render(arg ? :case_arg : :case_no_arg).indent 2 %>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<%= view_marker %>
|
2
|
+
if [[ -n ${2+x} ]]; then
|
3
|
+
<%= render(:validations).indent 2 %>
|
4
|
+
% if repeatable
|
5
|
+
if [[ -z ${args[<%= name %>]+x} ]]; then
|
6
|
+
args[<%= name %>]="\"$2\""
|
7
|
+
else
|
8
|
+
args[<%= name %>]="${args[<%= name %>]} \"$2\""
|
9
|
+
fi
|
10
|
+
% else
|
11
|
+
args[<%= name %>]="$2"
|
12
|
+
% end
|
13
|
+
shift
|
14
|
+
shift
|
15
|
+
else
|
16
|
+
printf "%s\n" "<%= strings[:flag_requires_an_argument] % { name: name, usage: usage_string } %>"
|
17
|
+
exit 1
|
18
|
+
fi
|
19
|
+
;;
|
data/lib/bashly.rb
CHANGED
@@ -15,15 +15,3 @@ 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.10
|
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-04-
|
11
|
+
date: 2022-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- lib/bashly/templates/lib/validations/validate_not_empty.sh
|
122
122
|
- lib/bashly/templates/lib/yaml.sh
|
123
123
|
- lib/bashly/templates/minimal.yml
|
124
|
+
- lib/bashly/templates/settings.yml
|
124
125
|
- lib/bashly/templates/strings.yml
|
125
126
|
- lib/bashly/templates/test/approvals.bash
|
126
127
|
- lib/bashly/version.rb
|
@@ -145,6 +146,9 @@ files:
|
|
145
146
|
- lib/bashly/views/command/normalize_input.erb
|
146
147
|
- lib/bashly/views/command/parse_requirements.erb
|
147
148
|
- lib/bashly/views/command/parse_requirements_case.erb
|
149
|
+
- lib/bashly/views/command/parse_requirements_case_catch_all.erb
|
150
|
+
- lib/bashly/views/command/parse_requirements_case_repeatable.erb
|
151
|
+
- lib/bashly/views/command/parse_requirements_case_simple.erb
|
148
152
|
- lib/bashly/views/command/parse_requirements_while.erb
|
149
153
|
- lib/bashly/views/command/required_args_filter.erb
|
150
154
|
- lib/bashly/views/command/required_flags_filter.erb
|
@@ -163,6 +167,8 @@ files:
|
|
163
167
|
- lib/bashly/views/command/whitelist_filter.erb
|
164
168
|
- lib/bashly/views/environment_variable/usage.erb
|
165
169
|
- lib/bashly/views/flag/case.erb
|
170
|
+
- lib/bashly/views/flag/case_arg.erb
|
171
|
+
- lib/bashly/views/flag/case_no_arg.erb
|
166
172
|
- lib/bashly/views/flag/conflicts.erb
|
167
173
|
- lib/bashly/views/flag/usage.erb
|
168
174
|
- lib/bashly/views/flag/validations.erb
|