bashly 0.7.5 → 0.7.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bashly/commands/add.rb +7 -0
- data/lib/bashly/commands/base.rb +6 -0
- data/lib/bashly/commands/generate.rb +2 -0
- data/lib/bashly/commands/validate.rb +1 -3
- data/lib/bashly/config.rb +1 -1
- data/lib/bashly/config_validator.rb +24 -0
- data/lib/bashly/extensions/yaml.rb +8 -0
- data/lib/bashly/libraries/completions_function.rb +1 -1
- data/lib/bashly/libraries.yml +23 -8
- data/lib/bashly/library.rb +6 -2
- data/lib/bashly/message_strings.rb +2 -2
- data/lib/bashly/refinements/compose_refinements.rb +1 -1
- data/lib/bashly/script/base.rb +2 -1
- data/lib/bashly/script/command.rb +1 -7
- data/lib/bashly/script/flag.rb +1 -0
- data/lib/bashly/settings.rb +13 -1
- data/lib/bashly/templates/strings.yml +2 -0
- data/lib/bashly/templates/test/approvals.bash +93 -0
- data/lib/bashly/version.rb +1 -1
- data/lib/bashly/views/command/fixed_flags_filter.erb +2 -0
- data/lib/bashly/views/command/initialize.erb +1 -1
- data/lib/bashly/views/command/parse_requirements.erb +1 -1
- data/lib/bashly/views/command/whitelist_filter.erb +10 -0
- data/lib/bashly/views/flag/case.erb +13 -0
- data/lib/bashly/views/flag/conflicts.erb +18 -0
- data/lib/bashly/views/wrapper/header.erb +1 -1
- data/lib/bashly.rb +1 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d05f653ff5439edd7108eaff3c6265926dc4e894453fce1c59bc4727c4c98d1f
|
4
|
+
data.tar.gz: 39afd30e66779103285d9df99f74f4e3cc8af61220d15a6b1cb02b21a4bebe57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8db8291a3db5a496626676942eddcadb61f7080ab316ed17652af5f58376e40efa85473e7a665a3966dbbfdbc37b6662577a3e13b50d9f49c36a87792854cefc
|
7
|
+
data.tar.gz: c844bf07c523c6f04a21874a08e3c2c40fafe4562829f419f77fd17f74ebaa70b5006e61c50b430399dcca00158f9d4b4fdb7afe4dfeb2e3a425c8eb544fcc22
|
data/lib/bashly/commands/add.rb
CHANGED
@@ -9,6 +9,7 @@ module Bashly
|
|
9
9
|
usage "bashly add colors [--force]"
|
10
10
|
usage "bashly add yaml [--force]"
|
11
11
|
usage "bashly add validations [--force]"
|
12
|
+
usage "bashly add test [--force]"
|
12
13
|
usage "bashly add comp FORMAT [OUTPUT --force]"
|
13
14
|
usage "bashly add (-h|--help)"
|
14
15
|
|
@@ -23,6 +24,7 @@ module Bashly
|
|
23
24
|
command "colors", "Add standard functions for printing colorful and formatted text to the lib directory."
|
24
25
|
command "yaml", "Add standard functions for reading YAML files to the lib directory."
|
25
26
|
command "validations", "Add argument validation functions to the lib directory."
|
27
|
+
command "test", "Add approval testing."
|
26
28
|
command "comp", "Generate a bash completions script or function."
|
27
29
|
|
28
30
|
example "bashly add strings --force"
|
@@ -30,6 +32,7 @@ module Bashly
|
|
30
32
|
example "bashly add comp script completions.bash"
|
31
33
|
|
32
34
|
environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
|
35
|
+
environment "BASHLY_LIB_DIR", "The path to use for creating the library files, relative to the source dir [default: lib]"
|
33
36
|
|
34
37
|
def strings_command
|
35
38
|
add_lib 'strings'
|
@@ -55,6 +58,10 @@ module Bashly
|
|
55
58
|
add_lib 'validations'
|
56
59
|
end
|
57
60
|
|
61
|
+
def test_command
|
62
|
+
add_lib 'test'
|
63
|
+
end
|
64
|
+
|
58
65
|
def comp_command
|
59
66
|
format = args['FORMAT']
|
60
67
|
output = args['OUTPUT']
|
data/lib/bashly/commands/base.rb
CHANGED
@@ -5,6 +5,12 @@ module Bashly
|
|
5
5
|
module Commands
|
6
6
|
class Base < MisterBin::Command
|
7
7
|
include AssetHelper
|
8
|
+
|
9
|
+
def validate_config
|
10
|
+
config = Config.new "#{Settings.source_dir}/bashly.yml"
|
11
|
+
validator = ConfigValidator.new config
|
12
|
+
validator.validate
|
13
|
+
end
|
8
14
|
end
|
9
15
|
end
|
10
16
|
end
|
@@ -13,12 +13,14 @@ module Bashly
|
|
13
13
|
|
14
14
|
environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
|
15
15
|
environment "BASHLY_TARGET_DIR", "The path to use for creating the bash script [default: .]"
|
16
|
+
environment "BASHLY_LIB_DIR", "The path to use for upgrading library files, relative to the source dir [default: lib]"
|
16
17
|
environment "BASHLY_STRICT", "When not empty, enable bash strict mode (set -euo pipefail)"
|
17
18
|
|
18
19
|
example "bashly generate --force"
|
19
20
|
example "bashly generate --wrap my_function"
|
20
21
|
|
21
22
|
def run
|
23
|
+
validate_config
|
22
24
|
create_user_files
|
23
25
|
upgrade_libs if args['--upgrade']
|
24
26
|
create_master_script
|
@@ -9,9 +9,7 @@ module Bashly
|
|
9
9
|
environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
|
10
10
|
|
11
11
|
def run
|
12
|
-
|
13
|
-
validator = ConfigValidator.new config
|
14
|
-
validator.validate
|
12
|
+
validate_config
|
15
13
|
say "!txtgrn!OK"
|
16
14
|
end
|
17
15
|
end
|
data/lib/bashly/config.rb
CHANGED
@@ -79,10 +79,13 @@ module Bashly
|
|
79
79
|
assert_optional_string "#{key}.default", value['default']
|
80
80
|
assert_optional_string "#{key}.validate", value['validate']
|
81
81
|
assert_boolean "#{key}.required", value['required']
|
82
|
+
assert_boolean "#{key}.repeatable", value['repeatable']
|
82
83
|
|
83
84
|
assert_array "#{key}.allowed", value['allowed'], of: :string
|
84
85
|
|
85
86
|
refute value['name'].match(/^-/), "#{key}.name must not start with '-'"
|
87
|
+
|
88
|
+
refute value['required'] && value['default'], "#{key} cannot have both required and default"
|
86
89
|
end
|
87
90
|
|
88
91
|
def assert_flag(key, value)
|
@@ -98,10 +101,21 @@ module Bashly
|
|
98
101
|
|
99
102
|
assert_boolean "#{key}.required", value['required']
|
100
103
|
assert_array "#{key}.allowed", value['allowed'], of: :string
|
104
|
+
assert_array "#{key}.conflicts", value['conflicts'], of: :string
|
101
105
|
|
102
106
|
assert value['long'].match(/^--[a-zA-Z0-9_\-]+$/), "#{key}.long must be in the form of '--name'" if value['long']
|
103
107
|
assert value['short'].match(/^-[a-zA-Z0-9]$/), "#{key}.short must be in the form of '-n'" if value['short']
|
104
108
|
refute value['arg'].match(/^-/), "#{key}.arg must not start with '-'" if value['arg']
|
109
|
+
|
110
|
+
refute value['required'] && value['default'], "#{key} cannot have both required and default"
|
111
|
+
|
112
|
+
if value['default']
|
113
|
+
assert value['arg'], "#{key}.default does not make sense without arg"
|
114
|
+
end
|
115
|
+
|
116
|
+
if value['allowed']
|
117
|
+
assert value['arg'], "#{key}.allowed does not make sense without arg"
|
118
|
+
end
|
105
119
|
end
|
106
120
|
|
107
121
|
def assert_env_var(key, value)
|
@@ -138,6 +152,16 @@ module Bashly
|
|
138
152
|
assert_array "#{key}.filters", value['filters'], of: :string
|
139
153
|
assert_array "#{key}.environment_variables", value['environment_variables'], of: :env_var
|
140
154
|
assert_array "#{key}.examples", value['examples'], of: :string
|
155
|
+
|
156
|
+
if key == "root"
|
157
|
+
refute value['short'], "#{key}.short makes no sense"
|
158
|
+
refute value['group'], "#{key}.group makes no sense"
|
159
|
+
refute value['default'], "#{key}.default makes no sense"
|
160
|
+
refute value['private'], "#{key}.private makes no sense"
|
161
|
+
else
|
162
|
+
refute value['version'], "#{key}.version makes no sense"
|
163
|
+
refute value['extensible'], "#{key}.extensible makes no sense"
|
164
|
+
end
|
141
165
|
end
|
142
166
|
end
|
143
167
|
end
|
data/lib/bashly/libraries.yml
CHANGED
@@ -1,38 +1,53 @@
|
|
1
1
|
colors:
|
2
2
|
files:
|
3
3
|
- source: "templates/lib/colors.sh"
|
4
|
-
target: "%{
|
4
|
+
target: "%{user_lib_dir}/colors.sh"
|
5
5
|
|
6
6
|
config:
|
7
7
|
files:
|
8
8
|
- source: "templates/lib/config.sh"
|
9
|
-
target: "%{
|
9
|
+
target: "%{user_lib_dir}/config.sh"
|
10
10
|
|
11
11
|
yaml:
|
12
12
|
files:
|
13
13
|
- source: "templates/lib/yaml.sh"
|
14
|
-
target: "%{
|
14
|
+
target: "%{user_lib_dir}/yaml.sh"
|
15
15
|
|
16
16
|
lib:
|
17
17
|
files:
|
18
18
|
- source: "templates/lib/sample_function.sh"
|
19
|
-
target: "%{
|
19
|
+
target: "%{user_lib_dir}/sample_function.sh"
|
20
20
|
|
21
21
|
strings:
|
22
22
|
files:
|
23
23
|
- source: "templates/strings.yml"
|
24
24
|
target: "%{user_source_dir}/bashly-strings.yml"
|
25
25
|
|
26
|
+
test:
|
27
|
+
files:
|
28
|
+
- source: "templates/test/approvals.bash"
|
29
|
+
target: "%{user_target_dir}/test/approvals.bash"
|
30
|
+
- source: "templates/test/approve"
|
31
|
+
target: "%{user_target_dir}/test/approve"
|
32
|
+
|
33
|
+
post_install_message: |
|
34
|
+
Edit your tests in !txtgrn!test/approve!txtrst! and then run:
|
35
|
+
|
36
|
+
!txtpur!$ ./test/approve!txtrst!"
|
37
|
+
|
38
|
+
Docs: !undblu!https://github.com/DannyBen/approvals.bash
|
39
|
+
|
40
|
+
|
26
41
|
validations:
|
27
42
|
files:
|
28
43
|
- source: "templates/lib/validations/validate_dir_exists.sh"
|
29
|
-
target: "%{
|
44
|
+
target: "%{user_lib_dir}/validations/validate_dir_exists.sh"
|
30
45
|
- source: "templates/lib/validations/validate_file_exists.sh"
|
31
|
-
target: "%{
|
46
|
+
target: "%{user_lib_dir}/validations/validate_file_exists.sh"
|
32
47
|
- source: "templates/lib/validations/validate_integer.sh"
|
33
|
-
target: "%{
|
48
|
+
target: "%{user_lib_dir}/validations/validate_integer.sh"
|
34
49
|
- source: "templates/lib/validations/validate_not_empty.sh"
|
35
|
-
target: "%{
|
50
|
+
target: "%{user_lib_dir}/validations/validate_not_empty.sh"
|
36
51
|
|
37
52
|
completions: :CompletionsFunction
|
38
53
|
completions_script: :CompletionsScript
|
data/lib/bashly/library.rb
CHANGED
@@ -6,7 +6,7 @@ module Bashly
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def config
|
9
|
-
@config ||= YAML.
|
9
|
+
@config ||= YAML.properly_load_file(config_path)
|
10
10
|
end
|
11
11
|
|
12
12
|
def config_path
|
@@ -57,7 +57,11 @@ module Bashly
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def target_file_args
|
60
|
-
{
|
60
|
+
{
|
61
|
+
user_source_dir: Settings.source_dir,
|
62
|
+
user_target_dir: Settings.target_dir,
|
63
|
+
user_lib_dir: Settings.full_lib_dir,
|
64
|
+
}
|
61
65
|
end
|
62
66
|
end
|
63
67
|
end
|
@@ -13,7 +13,7 @@ module Bashly
|
|
13
13
|
private
|
14
14
|
|
15
15
|
def values!
|
16
|
-
defaults = YAML.
|
16
|
+
defaults = YAML.properly_load_file asset("templates/strings.yml")
|
17
17
|
defaults.merge project_strings
|
18
18
|
end
|
19
19
|
|
@@ -23,7 +23,7 @@ module Bashly
|
|
23
23
|
|
24
24
|
def project_strings!
|
25
25
|
if File.exist? project_strings_path
|
26
|
-
YAML.
|
26
|
+
YAML.properly_load_file project_strings_path
|
27
27
|
else
|
28
28
|
{}
|
29
29
|
end
|
@@ -22,7 +22,7 @@ module ComposeRefinements
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def safe_load_yaml(path)
|
25
|
-
loaded = YAML.
|
25
|
+
loaded = YAML.properly_load_file path
|
26
26
|
return loaded if loaded.is_a? Array or loaded.is_a? Hash
|
27
27
|
raise Bashly::ConfigurationError, "Cannot find a valid YAML in !txtgrn!#{path}"
|
28
28
|
|
data/lib/bashly/script/base.rb
CHANGED
@@ -10,6 +10,7 @@ module Bashly
|
|
10
10
|
arg
|
11
11
|
catch_all
|
12
12
|
completions
|
13
|
+
conflicts
|
13
14
|
default
|
14
15
|
dependencies
|
15
16
|
description
|
@@ -25,6 +26,7 @@ module Bashly
|
|
25
26
|
name
|
26
27
|
parent_name
|
27
28
|
private
|
29
|
+
repeatable
|
28
30
|
required
|
29
31
|
short
|
30
32
|
validate
|
@@ -34,7 +36,6 @@ module Bashly
|
|
34
36
|
def initialize(options)
|
35
37
|
raise Error, "Invalid options provided" unless options.respond_to? :keys
|
36
38
|
@options = options
|
37
|
-
validate_options if respond_to? :validate_options
|
38
39
|
end
|
39
40
|
|
40
41
|
def optional
|
@@ -125,13 +125,7 @@ module Bashly
|
|
125
125
|
# This is meant to provide the user with the ability to add custom
|
126
126
|
# functions
|
127
127
|
def user_lib
|
128
|
-
@user_lib ||= Dir["#{Settings.
|
129
|
-
end
|
130
|
-
|
131
|
-
# Raise an exception if there are some serious issues with the command
|
132
|
-
# definition. This is called by Base#initialize.
|
133
|
-
def validate_options
|
134
|
-
Bashly::ConfigValidator.new(options).validate
|
128
|
+
@user_lib ||= Dir["#{Settings.full_lib_dir}/**/*.sh"].sort
|
135
129
|
end
|
136
130
|
|
137
131
|
end
|
data/lib/bashly/script/flag.rb
CHANGED
data/lib/bashly/settings.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Bashly
|
2
2
|
class Settings
|
3
3
|
class << self
|
4
|
-
attr_writer :source_dir, :target_dir
|
4
|
+
attr_writer :source_dir, :target_dir, :lib_dir, :strict
|
5
5
|
|
6
6
|
def source_dir
|
7
7
|
@source_dir ||= ENV['BASHLY_SOURCE_DIR'] || 'src'
|
@@ -10,6 +10,18 @@ module Bashly
|
|
10
10
|
def target_dir
|
11
11
|
@target_dir ||= ENV['BASHLY_TARGET_DIR'] || '.'
|
12
12
|
end
|
13
|
+
|
14
|
+
def lib_dir
|
15
|
+
@lib_dir ||= ENV['BASHLY_LIB_DIR'] || 'lib'
|
16
|
+
end
|
17
|
+
|
18
|
+
def strict
|
19
|
+
@strict ||= ENV['BASHLY_STRICT']
|
20
|
+
end
|
21
|
+
|
22
|
+
def full_lib_dir
|
23
|
+
"#{source_dir}/#{lib_dir}"
|
24
|
+
end
|
13
25
|
end
|
14
26
|
end
|
15
27
|
end
|
@@ -14,6 +14,7 @@ group: "%{group} Commands:"
|
|
14
14
|
command_shortcut: "Shortcut: %{short}"
|
15
15
|
default_command_summary: "%{summary} (default)"
|
16
16
|
required: "(required)"
|
17
|
+
repeatable: "(repeatable)"
|
17
18
|
default: "Default: %{value}"
|
18
19
|
allowed: "Allowed: %{values}"
|
19
20
|
|
@@ -25,6 +26,7 @@ version_flag_text: Show version number
|
|
25
26
|
flag_requires_an_argument: "%{name} requires an argument: %{usage}"
|
26
27
|
invalid_argument: "invalid argument: %s"
|
27
28
|
invalid_flag: "invalid option: %s"
|
29
|
+
conflicting_flags: "conflicting options: %s cannot be used with %s"
|
28
30
|
missing_required_argument: "missing required argument: %{arg}\\nusage: %{usage}"
|
29
31
|
missing_required_flag: "missing required flag: %{usage}"
|
30
32
|
missing_required_environment_variable: "missing required environment variable: %{var}"
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# approvals.bash v0.2.7
|
2
|
+
#
|
3
|
+
# Interactive approval testing for Bash.
|
4
|
+
# https://github.com/DannyBen/approvals.bash
|
5
|
+
approve() {
|
6
|
+
local expected approval approval_file actual cmd
|
7
|
+
approvals_dir=${APPROVALS_DIR:=approvals}
|
8
|
+
|
9
|
+
cmd=$1
|
10
|
+
actual=$(eval "$cmd" 2>&1)
|
11
|
+
last_exit_code=$?
|
12
|
+
approval=$(printf "%b" "$cmd" | tr -s -c "[:alnum:]" _)
|
13
|
+
approval_file="$approvals_dir/${2:-"$approval"}"
|
14
|
+
|
15
|
+
[[ -d "$approvals_dir" ]] || mkdir "$approvals_dir"
|
16
|
+
|
17
|
+
if [[ -f "$approval_file" ]]; then
|
18
|
+
expected=$(cat "$approval_file")
|
19
|
+
else
|
20
|
+
echo "--- [$(blue "new: $cmd")] ---"
|
21
|
+
printf "%b\n" "$actual"
|
22
|
+
echo "--- [$(blue "new: $cmd")] ---"
|
23
|
+
expected="$actual"
|
24
|
+
user_approval "$cmd" "$actual" "$approval_file"
|
25
|
+
return
|
26
|
+
fi
|
27
|
+
|
28
|
+
if [[ "$(printf "%b" "$actual")" = "$(printf "%b" "$expected")" ]]; then
|
29
|
+
green "PASS $cmd"
|
30
|
+
else
|
31
|
+
echo "--- [$(blue "diff: $cmd")] ---"
|
32
|
+
$diff_cmd <(printf "%b" "$expected\n") <(printf "%b" "$actual\n" ) | tail -n +4
|
33
|
+
echo "--- [$(blue "diff: $cmd")] ---"
|
34
|
+
user_approval "$cmd" "$actual" "$approval_file"
|
35
|
+
fi
|
36
|
+
}
|
37
|
+
|
38
|
+
describe() {
|
39
|
+
cyan "TEST $*"
|
40
|
+
}
|
41
|
+
|
42
|
+
fail() {
|
43
|
+
red "FAIL $*"
|
44
|
+
exit 1
|
45
|
+
}
|
46
|
+
|
47
|
+
pass() {
|
48
|
+
green "PASS $*"
|
49
|
+
return 0
|
50
|
+
}
|
51
|
+
|
52
|
+
expect_exit_code() {
|
53
|
+
if [[ $last_exit_code == "$1" ]]; then
|
54
|
+
pass "exit $last_exit_code"
|
55
|
+
else
|
56
|
+
fail "Expected exit code $1, got $last_exit_code"
|
57
|
+
fi
|
58
|
+
}
|
59
|
+
|
60
|
+
red() { printf "\e[31m%b\e[0m\n" "$*"; }
|
61
|
+
green() { printf "\e[32m%b\e[0m\n" "$*"; }
|
62
|
+
blue() { printf "\e[34m%b\e[0m\n" "$*"; }
|
63
|
+
magenta() { printf "\e[35m%b\e[0m\n" "$*"; }
|
64
|
+
cyan() { printf "\e[36m%b\e[0m\n" "$*"; }
|
65
|
+
|
66
|
+
# Private
|
67
|
+
|
68
|
+
user_approval() {
|
69
|
+
local cmd="$1"
|
70
|
+
local actual="$2"
|
71
|
+
local approval_file="$3"
|
72
|
+
|
73
|
+
if [[ -v CI || -v GITHUB_ACTIONS ]]; then
|
74
|
+
fail "$cmd"
|
75
|
+
fi
|
76
|
+
|
77
|
+
echo
|
78
|
+
printf "[A]pprove? \n"
|
79
|
+
response=$(bash -c "read -n 1 key; echo \$key")
|
80
|
+
printf "\r"
|
81
|
+
if [[ $response =~ [Aa] ]]; then
|
82
|
+
printf "%b\n" "$actual" > "$approval_file"
|
83
|
+
pass "$cmd"
|
84
|
+
else
|
85
|
+
fail "$cmd"
|
86
|
+
fi
|
87
|
+
}
|
88
|
+
|
89
|
+
if diff --help | grep -- --color > /dev/null 2>&1; then
|
90
|
+
diff_cmd="diff --unified --color=always"
|
91
|
+
else
|
92
|
+
diff_cmd="diff --unified"
|
93
|
+
fi
|
data/lib/bashly/version.rb
CHANGED
@@ -7,7 +7,6 @@ parse_requirements() {
|
|
7
7
|
<%= render(:fixed_flags_filter).indent 2 %>
|
8
8
|
<%= render(:environment_variables_filter).indent 2 %>
|
9
9
|
<%= render(:dependencies_filter).indent 2 %>
|
10
|
-
<%= render(:user_filter).indent 2 %>
|
11
10
|
<%= render(:command_filter).indent 2 %>
|
12
11
|
<%= render(:parse_requirements_while).indent 2 %>
|
13
12
|
<%= render(:required_args_filter).indent 2 %>
|
@@ -15,6 +14,7 @@ parse_requirements() {
|
|
15
14
|
<%= render(:catch_all_filter).indent 2 %>
|
16
15
|
<%= render(:default_assignments).indent 2 %>
|
17
16
|
<%= render(:whitelist_filter).indent 2 %>
|
17
|
+
<%= render(:user_filter).indent 2 %>
|
18
18
|
}
|
19
19
|
|
20
20
|
% commands.each do |command|
|
@@ -6,8 +6,18 @@ if [[ ! ${args[<%= arg.name %>]} =~ ^(<%= arg.allowed.join '|' %>)$ ]]; then
|
|
6
6
|
fi
|
7
7
|
% end
|
8
8
|
% whitelisted_flags.each do |flag|
|
9
|
+
% if flag.repeatable
|
10
|
+
eval "input_array=(${args[<%= flag.name %>]})"
|
11
|
+
for i in "${input_array[@]}"; do
|
12
|
+
if [[ ! $i =~ ^(<%= flag.allowed.join '|' %>)$ ]]; then
|
13
|
+
printf "%s\n" "<%= strings[:disallowed_flag] % { name: flag.name, allowed: flag.allowed.join(', ') } %>"
|
14
|
+
exit 1
|
15
|
+
fi
|
16
|
+
done
|
17
|
+
% else
|
9
18
|
if [[ ! ${args[<%= flag.name %>]} =~ ^(<%= flag.allowed.join '|' %>)$ ]]; then
|
10
19
|
printf "%s\n" "<%= strings[:disallowed_flag] % { name: flag.name, allowed: flag.allowed.join(', ') } %>"
|
11
20
|
exit 1
|
12
21
|
fi
|
22
|
+
% end
|
13
23
|
% end
|
@@ -1,17 +1,30 @@
|
|
1
1
|
# :flag.case
|
2
2
|
<%= aliases.join " | " %> )
|
3
|
+
<%= render(:conflicts).indent 2 %>
|
3
4
|
% if arg
|
4
5
|
if [[ -n ${2+x} ]]; then
|
5
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
|
6
14
|
args[<%= name %>]="$2"
|
15
|
+
% end
|
7
16
|
shift
|
8
17
|
shift
|
9
18
|
else
|
10
19
|
printf "%s\n" "<%= strings[:flag_requires_an_argument] % { name: name, usage: usage_string } %>"
|
11
20
|
exit 1
|
12
21
|
fi
|
22
|
+
% else
|
23
|
+
% if repeatable
|
24
|
+
(( args[<%= name %>]+=1 ))
|
13
25
|
% else
|
14
26
|
args[<%= name %>]=1
|
27
|
+
% end
|
15
28
|
shift
|
16
29
|
% end
|
17
30
|
;;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# :flag.conflicts
|
2
|
+
% if conflicts
|
3
|
+
% if conflicts.count == 1
|
4
|
+
if [[ -n "${args[<%= conflicts.first %>]:-}" ]]; then
|
5
|
+
printf "<%= strings[:conflicting_flags] %>\n" "$key" "<%= conflicts.first %>"
|
6
|
+
exit 1
|
7
|
+
fi
|
8
|
+
|
9
|
+
% else
|
10
|
+
for conflict in <%= conflicts.join ' ' %>; do
|
11
|
+
if [[ -n "${args[$conflict]:-}" ]]; then
|
12
|
+
printf "<%= strings[:conflicting_flags] %>\n" "$key" "$conflict"
|
13
|
+
exit 1
|
14
|
+
fi
|
15
|
+
done
|
16
|
+
|
17
|
+
% end
|
18
|
+
% end
|
data/lib/bashly.rb
CHANGED
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.8
|
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-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- lib/bashly/extensions/array.rb
|
94
94
|
- lib/bashly/extensions/file.rb
|
95
95
|
- lib/bashly/extensions/string.rb
|
96
|
+
- lib/bashly/extensions/yaml.rb
|
96
97
|
- lib/bashly/libraries.yml
|
97
98
|
- lib/bashly/libraries/base.rb
|
98
99
|
- lib/bashly/libraries/completions.rb
|
@@ -121,6 +122,7 @@ files:
|
|
121
122
|
- lib/bashly/templates/lib/yaml.sh
|
122
123
|
- lib/bashly/templates/minimal.yml
|
123
124
|
- lib/bashly/templates/strings.yml
|
125
|
+
- lib/bashly/templates/test/approvals.bash
|
124
126
|
- lib/bashly/version.rb
|
125
127
|
- lib/bashly/views/argument/usage.erb
|
126
128
|
- lib/bashly/views/argument/validations.erb
|
@@ -161,6 +163,7 @@ files:
|
|
161
163
|
- lib/bashly/views/command/whitelist_filter.erb
|
162
164
|
- lib/bashly/views/environment_variable/usage.erb
|
163
165
|
- lib/bashly/views/flag/case.erb
|
166
|
+
- lib/bashly/views/flag/conflicts.erb
|
164
167
|
- lib/bashly/views/flag/usage.erb
|
165
168
|
- lib/bashly/views/flag/validations.erb
|
166
169
|
- lib/bashly/views/wrapper/bash3_bouncer.erb
|
@@ -189,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
189
192
|
- !ruby/object:Gem::Version
|
190
193
|
version: '0'
|
191
194
|
requirements: []
|
192
|
-
rubygems_version: 3.3.
|
195
|
+
rubygems_version: 3.3.3
|
193
196
|
signing_key:
|
194
197
|
specification_version: 4
|
195
198
|
summary: Bash Command Line Tool Generator
|