bashly 0.7.5 → 0.7.6
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 +6 -0
- data/lib/bashly/config_validator.rb +2 -0
- data/lib/bashly/libraries.yml +15 -0
- data/lib/bashly/library.rb +4 -1
- data/lib/bashly/script/base.rb +2 -0
- data/lib/bashly/script/flag.rb +1 -0
- 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/parse_requirements.erb +1 -1
- data/lib/bashly/views/flag/case.erb +13 -0
- data/lib/bashly/views/flag/conflicts.erb +18 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98fc7fa0a703a1bdef30afdd0e4ff4b5a4d5cc6025380e4aa952aeb77c0b9aa8
|
4
|
+
data.tar.gz: 2d148783f32363862d4039b424ef8ddd5fa050c849bbe742f7195096cdf78830
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 309afb5a2c73c170fafacf9ab02066bd1e4d29934c6a94f6518328dbfd246a8679fc0e8ffc51e00a3359adc90cc25d1d9433e8944db7def0cf806ac5dd99d89d
|
7
|
+
data.tar.gz: fd16952f25275a54d0aaaf990b00575a19fc5d38cab3206918722240466df9e1ae7f55f439ccfc1129ca5d8733181583fbd4280bf18cb42615119a9122f666d8
|
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"
|
@@ -55,6 +57,10 @@ module Bashly
|
|
55
57
|
add_lib 'validations'
|
56
58
|
end
|
57
59
|
|
60
|
+
def test_command
|
61
|
+
add_lib 'test'
|
62
|
+
end
|
63
|
+
|
58
64
|
def comp_command
|
59
65
|
format = args['FORMAT']
|
60
66
|
output = args['OUTPUT']
|
@@ -79,6 +79,7 @@ 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
|
|
@@ -98,6 +99,7 @@ module Bashly
|
|
98
99
|
|
99
100
|
assert_boolean "#{key}.required", value['required']
|
100
101
|
assert_array "#{key}.allowed", value['allowed'], of: :string
|
102
|
+
assert_array "#{key}.conflicts", value['conflicts'], of: :string
|
101
103
|
|
102
104
|
assert value['long'].match(/^--[a-zA-Z0-9_\-]+$/), "#{key}.long must be in the form of '--name'" if value['long']
|
103
105
|
assert value['short'].match(/^-[a-zA-Z0-9]$/), "#{key}.short must be in the form of '-n'" if value['short']
|
data/lib/bashly/libraries.yml
CHANGED
@@ -23,6 +23,21 @@ strings:
|
|
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"
|
data/lib/bashly/library.rb
CHANGED
data/lib/bashly/script/base.rb
CHANGED
data/lib/bashly/script/flag.rb
CHANGED
@@ -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|
|
@@ -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
|
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.6
|
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-02-
|
11
|
+
date: 2022-02-18 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/yaml.sh
|
122
122
|
- lib/bashly/templates/minimal.yml
|
123
123
|
- lib/bashly/templates/strings.yml
|
124
|
+
- lib/bashly/templates/test/approvals.bash
|
124
125
|
- lib/bashly/version.rb
|
125
126
|
- lib/bashly/views/argument/usage.erb
|
126
127
|
- lib/bashly/views/argument/validations.erb
|
@@ -161,6 +162,7 @@ files:
|
|
161
162
|
- lib/bashly/views/command/whitelist_filter.erb
|
162
163
|
- lib/bashly/views/environment_variable/usage.erb
|
163
164
|
- lib/bashly/views/flag/case.erb
|
165
|
+
- lib/bashly/views/flag/conflicts.erb
|
164
166
|
- lib/bashly/views/flag/usage.erb
|
165
167
|
- lib/bashly/views/flag/validations.erb
|
166
168
|
- lib/bashly/views/wrapper/bash3_bouncer.erb
|