bashly 0.8.10 → 0.9.1
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/README.md +7 -0
- data/bin/bashly +2 -2
- data/lib/bashly/cli.rb +2 -3
- data/lib/bashly/commands/add.rb +77 -50
- data/lib/bashly/commands/base.rb +4 -3
- data/lib/bashly/commands/generate.rb +43 -36
- data/lib/bashly/commands/init.rb +10 -9
- data/lib/bashly/commands/preview.rb +4 -4
- data/lib/bashly/commands/validate.rb +8 -7
- data/lib/bashly/concerns/asset_helper.rb +1 -1
- data/lib/bashly/concerns/completions.rb +24 -15
- data/lib/bashly/concerns/renderable.rb +5 -5
- data/lib/bashly/concerns/validation_helpers.rb +20 -12
- data/lib/bashly/config.rb +1 -1
- data/lib/bashly/config_validator.rb +53 -27
- data/lib/bashly/deprecation.rb +9 -7
- data/lib/bashly/exceptions.rb +1 -1
- data/lib/bashly/extensions/array.rb +4 -4
- data/lib/bashly/extensions/file.rb +3 -3
- data/lib/bashly/extensions/string.rb +6 -6
- data/lib/bashly/libraries/base.rb +11 -1
- data/lib/bashly/libraries/completions_function.rb +9 -10
- data/lib/bashly/libraries/completions_script.rb +7 -8
- data/lib/bashly/libraries/completions_yaml.rb +7 -8
- data/lib/bashly/libraries/help.rb +36 -0
- data/lib/bashly/libraries.yml +11 -9
- data/lib/bashly/library.rb +8 -5
- data/lib/bashly/message_strings.rb +1 -1
- data/lib/bashly/refinements/compose_refinements.rb +2 -2
- data/lib/bashly/script/argument.rb +1 -1
- data/lib/bashly/script/base.rb +3 -2
- data/lib/bashly/script/catch_all.rb +6 -4
- data/lib/bashly/script/command.rb +48 -54
- data/lib/bashly/script/environment_variable.rb +5 -5
- data/lib/bashly/script/flag.rb +7 -7
- data/lib/bashly/script/wrapper.rb +6 -5
- data/lib/bashly/settings.rb +30 -27
- data/lib/bashly/templates/help/help_command.sh +30 -0
- data/lib/bashly/templates/lib/colors.sh +2 -2
- data/lib/bashly/templates/lib/config.sh +10 -10
- data/lib/bashly/templates/lib/yaml.sh +9 -9
- data/lib/bashly/templates/settings.yml +3 -0
- data/lib/bashly/templates/test/approvals.bash +36 -12
- data/lib/bashly/templates/test/approve +14 -9
- data/lib/bashly/version.rb +2 -2
- data/lib/bashly/views/command/command_fallback.gtx +9 -6
- data/lib/bashly/views/command/command_filter.gtx +8 -9
- data/lib/bashly/views/command/dependencies_filter.gtx +6 -2
- data/lib/bashly/views/command/fixed_flags_filter.gtx +18 -12
- data/lib/bashly/views/command/inspect_args.gtx +2 -2
- data/lib/bashly/views/command/normalize_input.gtx +1 -1
- data/lib/bashly/views/command/parse_requirements_while.gtx +11 -11
- data/lib/bashly/views/command/run.gtx +16 -13
- data/lib/bashly/views/command/usage_environment_variables.gtx +1 -1
- data/lib/bashly/views/flag/case.gtx +1 -1
- data/lib/bashly/views/flag/case_no_arg.gtx +1 -1
- metadata +10 -8
- data/lib/bashly/libraries/completions.rb +0 -14
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
# approvals.bash v0.
|
|
1
|
+
# approvals.bash v0.3.3
|
|
2
2
|
#
|
|
3
3
|
# Interactive approval testing for Bash.
|
|
4
4
|
# https://github.com/DannyBen/approvals.bash
|
|
5
5
|
approve() {
|
|
6
6
|
local expected approval approval_file actual cmd
|
|
7
7
|
approvals_dir=${APPROVALS_DIR:=approvals}
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
cmd=$1
|
|
10
|
-
|
|
11
|
-
last_exit_code=$?
|
|
10
|
+
last_exit_code=0
|
|
11
|
+
actual=$(eval "$cmd" 2>&1) || last_exit_code=$?
|
|
12
12
|
approval=$(printf "%b" "$cmd" | tr -s -c "[:alnum:]" _)
|
|
13
13
|
approval_file="$approvals_dir/${2:-"$approval"}"
|
|
14
14
|
|
|
@@ -26,26 +26,32 @@ approve() {
|
|
|
26
26
|
fi
|
|
27
27
|
|
|
28
28
|
if [[ "$(printf "%b" "$actual")" = "$(printf "%b" "$expected")" ]]; then
|
|
29
|
-
|
|
29
|
+
pass "$cmd"
|
|
30
30
|
else
|
|
31
31
|
echo "--- [$(blue "diff: $cmd")] ---"
|
|
32
|
-
$diff_cmd <(printf "%b" "$expected\n") <(printf "%b" "$actual\n"
|
|
32
|
+
$diff_cmd <(printf "%b" "$expected\n") <(printf "%b" "$actual\n") | tail -n +4
|
|
33
33
|
echo "--- [$(blue "diff: $cmd")] ---"
|
|
34
34
|
user_approval "$cmd" "$actual" "$approval_file"
|
|
35
35
|
fi
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
describe() {
|
|
39
|
-
|
|
39
|
+
echo
|
|
40
|
+
blue "= $*"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
context() {
|
|
44
|
+
echo
|
|
45
|
+
magenta "= $*"
|
|
40
46
|
}
|
|
41
47
|
|
|
42
48
|
fail() {
|
|
43
|
-
red "
|
|
49
|
+
red " FAILED: $*"
|
|
44
50
|
exit 1
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
pass() {
|
|
48
|
-
green "
|
|
54
|
+
green " approved: $*"
|
|
49
55
|
return 0
|
|
50
56
|
}
|
|
51
57
|
|
|
@@ -74,19 +80,37 @@ user_approval() {
|
|
|
74
80
|
fail "$cmd"
|
|
75
81
|
fi
|
|
76
82
|
|
|
77
|
-
echo
|
|
83
|
+
echo
|
|
78
84
|
printf "[A]pprove? \n"
|
|
79
85
|
response=$(bash -c "read -n 1 key; echo \$key")
|
|
80
86
|
printf "\r"
|
|
81
87
|
if [[ $response =~ [Aa] ]]; then
|
|
82
|
-
printf "%b\n" "$actual" >
|
|
88
|
+
printf "%b\n" "$actual" >"$approval_file"
|
|
83
89
|
pass "$cmd"
|
|
84
90
|
else
|
|
85
91
|
fail "$cmd"
|
|
86
92
|
fi
|
|
87
93
|
}
|
|
88
94
|
|
|
89
|
-
|
|
95
|
+
onexit() {
|
|
96
|
+
exitcode=$?
|
|
97
|
+
if [[ "$exitcode" == 0 ]]; then
|
|
98
|
+
green "\nFinished successfully"
|
|
99
|
+
else
|
|
100
|
+
red "\nFinished with failures"
|
|
101
|
+
fi
|
|
102
|
+
exit $exitcode
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
onerror() {
|
|
106
|
+
fail "Caller: $(caller)"
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
set -e
|
|
110
|
+
trap 'onexit' EXIT
|
|
111
|
+
trap 'onerror' ERR
|
|
112
|
+
|
|
113
|
+
if diff --help | grep -- --color >/dev/null 2>&1; then
|
|
90
114
|
diff_cmd="diff --unified --color=always"
|
|
91
115
|
else
|
|
92
116
|
diff_cmd="diff --unified"
|
|
@@ -3,18 +3,23 @@
|
|
|
3
3
|
|
|
4
4
|
cd ./test || exit
|
|
5
5
|
source approvals.bash
|
|
6
|
-
PATH="$PATH:../"
|
|
7
6
|
|
|
8
7
|
# Update me
|
|
9
|
-
cli
|
|
8
|
+
cli=./download
|
|
10
9
|
|
|
11
|
-
# Tests
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
approve "$cli --help"
|
|
10
|
+
# Tests (context, describe and indentation are optional)
|
|
11
|
+
context "when DEBUG is on"
|
|
12
|
+
export DEBUG=1
|
|
15
13
|
|
|
16
|
-
describe "
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
describe "root command"
|
|
15
|
+
approve "$cli"
|
|
16
|
+
approve "$cli --help"
|
|
17
|
+
|
|
18
|
+
context "when DEBUG is off"
|
|
19
|
+
unset DEBUG
|
|
20
|
+
|
|
21
|
+
describe "some other command"
|
|
22
|
+
approve "$cli other"
|
|
23
|
+
approve "$cli other --help"
|
|
19
24
|
|
|
20
25
|
# ...more tests...
|
data/lib/bashly/version.rb
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
module Bashly
|
|
2
|
-
VERSION =
|
|
3
|
-
end
|
|
2
|
+
VERSION = '0.9.1'
|
|
3
|
+
end
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
= view_marker
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
>
|
|
5
|
-
>
|
|
6
|
-
>
|
|
7
|
-
>
|
|
8
|
-
>
|
|
3
|
+
if !default_command || default_command.default != 'force'
|
|
4
|
+
> "")
|
|
5
|
+
> {{ function_name }}_usage >&2
|
|
6
|
+
> exit 1
|
|
7
|
+
> ;;
|
|
8
|
+
>
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
> *)
|
|
9
12
|
|
|
10
13
|
if default_command
|
|
11
14
|
> action="{{ default_command.name }}"
|
|
@@ -4,22 +4,21 @@ if commands.any?
|
|
|
4
4
|
> action=${1:-}
|
|
5
5
|
>
|
|
6
6
|
> case $action in
|
|
7
|
-
>
|
|
8
|
-
> ;;
|
|
7
|
+
> -*) ;;
|
|
9
8
|
>
|
|
10
9
|
|
|
11
10
|
commands.each do |command|
|
|
12
|
-
>
|
|
13
|
-
>
|
|
14
|
-
>
|
|
15
|
-
>
|
|
16
|
-
>
|
|
17
|
-
>
|
|
11
|
+
> {{ command.aliases.join " | " }})
|
|
12
|
+
> action="{{ command.name }}"
|
|
13
|
+
> shift
|
|
14
|
+
> {{ command.function_name }}_parse_requirements "$@"
|
|
15
|
+
> shift $#
|
|
16
|
+
> ;;
|
|
18
17
|
>
|
|
19
18
|
|
|
20
19
|
end
|
|
21
20
|
|
|
22
|
-
= render
|
|
21
|
+
= render(:command_fallback).indent(2)
|
|
23
22
|
> esac
|
|
24
23
|
>
|
|
25
24
|
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
if dependencies
|
|
2
2
|
= view_marker
|
|
3
3
|
|
|
4
|
-
dependencies.each do |dependency|
|
|
5
|
-
> if !
|
|
4
|
+
dependencies.each do |dependency, message|
|
|
5
|
+
> if ! command -v {{ dependency }} >/dev/null 2>&1; then
|
|
6
6
|
> printf "{{ strings[:missing_dependency] % { dependency: dependency } }}\n" >&2
|
|
7
|
+
if message and !message.empty?
|
|
8
|
+
> printf "%s\n" "{{ message }}" >&2
|
|
9
|
+
end
|
|
7
10
|
> exit 1
|
|
8
11
|
> fi
|
|
12
|
+
>
|
|
9
13
|
end
|
|
10
14
|
end
|
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
= view_marker
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> while [[ $# -gt 0 ]]; do
|
|
4
|
+
> case "${1:-}" in
|
|
4
5
|
|
|
5
6
|
if root_command?
|
|
6
|
-
= short_flag_exist?("-v") ? "--version
|
|
7
|
-
>
|
|
8
|
-
>
|
|
9
|
-
>
|
|
7
|
+
= short_flag_exist?("-v") ? "--version)" : "--version | -v)".indent(4)
|
|
8
|
+
> version_command
|
|
9
|
+
> exit
|
|
10
|
+
> ;;
|
|
10
11
|
>
|
|
11
12
|
end
|
|
12
13
|
|
|
13
|
-
= short_flag_exist?("-h") ? "--help
|
|
14
|
-
>
|
|
15
|
-
>
|
|
16
|
-
>
|
|
17
|
-
>
|
|
14
|
+
= short_flag_exist?("-h") ? "--help)" : "--help | -h)".indent(4)
|
|
15
|
+
> long_usage=yes
|
|
16
|
+
> <%= function_name %>_usage
|
|
17
|
+
> exit
|
|
18
|
+
> ;;
|
|
18
19
|
>
|
|
19
20
|
|
|
20
21
|
if global_flags?
|
|
21
22
|
flags.each do |flag|
|
|
22
|
-
= flag.render(:case)
|
|
23
|
+
= flag.render(:case).indent(4)
|
|
23
24
|
end
|
|
24
25
|
end
|
|
25
26
|
|
|
26
|
-
>
|
|
27
|
+
> *)
|
|
28
|
+
> break
|
|
29
|
+
> ;;
|
|
30
|
+
>
|
|
31
|
+
> esac
|
|
32
|
+
> done
|
|
27
33
|
>
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
> inspect_args() {
|
|
4
4
|
> readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)
|
|
5
|
-
> if ((
|
|
5
|
+
> if ((${#args[@]})); then
|
|
6
6
|
> echo args:
|
|
7
7
|
> for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done
|
|
8
8
|
> else
|
|
9
9
|
> echo args: none
|
|
10
10
|
> fi
|
|
11
11
|
>
|
|
12
|
-
> if ((
|
|
12
|
+
> if ((${#other_args[@]})); then
|
|
13
13
|
> echo
|
|
14
14
|
> echo other_args:
|
|
15
15
|
> echo "- \${other_args[*]} = ${other_args[*]}"
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
if Settings.compact_short_flags
|
|
16
16
|
> elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then
|
|
17
17
|
> flags="${BASH_REMATCH[1]}"
|
|
18
|
-
> for ((
|
|
18
|
+
> for ((i = 0; i < ${#flags}; i++)); do
|
|
19
19
|
> input+=("-${flags:i:1}")
|
|
20
20
|
> done
|
|
21
21
|
end
|
|
@@ -6,29 +6,29 @@
|
|
|
6
6
|
|
|
7
7
|
unless global_flags?
|
|
8
8
|
flags.each do |flag|
|
|
9
|
-
= flag.render(:case).indent
|
|
9
|
+
= flag.render(:case).indent(4)
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
>
|
|
14
|
-
>
|
|
14
|
+
> -?*)
|
|
15
15
|
|
|
16
16
|
if catch_all.enabled?
|
|
17
|
-
>
|
|
18
|
-
>
|
|
19
|
-
>
|
|
17
|
+
> other_args+=("$1")
|
|
18
|
+
> shift
|
|
19
|
+
> ;;
|
|
20
20
|
|
|
21
21
|
else
|
|
22
|
-
>
|
|
23
|
-
>
|
|
24
|
-
>
|
|
22
|
+
> printf "<%= strings[:invalid_flag] %>\n" "$key" >&2
|
|
23
|
+
> exit 1
|
|
24
|
+
> ;;
|
|
25
25
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
>
|
|
29
|
-
>
|
|
30
|
-
= render(:parse_requirements_case).indent
|
|
31
|
-
>
|
|
29
|
+
> *)
|
|
30
|
+
= render(:parse_requirements_case).indent(6)
|
|
31
|
+
> ;;
|
|
32
32
|
>
|
|
33
33
|
> esac
|
|
34
34
|
> done
|
|
@@ -7,22 +7,25 @@
|
|
|
7
7
|
> normalize_input "$@"
|
|
8
8
|
> parse_requirements "${input[@]}"
|
|
9
9
|
>
|
|
10
|
+
> case "$action" in
|
|
10
11
|
|
|
11
|
-
condition = "if"
|
|
12
12
|
deep_commands.each do |command|
|
|
13
|
-
>
|
|
14
|
-
>
|
|
15
|
-
>
|
|
16
|
-
>
|
|
17
|
-
>
|
|
18
|
-
>
|
|
19
|
-
>
|
|
13
|
+
> "{{ command.action_name }}")
|
|
14
|
+
> if [[ ${args[--help]:-} ]]; then
|
|
15
|
+
> long_usage=yes
|
|
16
|
+
> {{ command.function_name }}_usage
|
|
17
|
+
> else
|
|
18
|
+
> {{ command.function_name }}_command
|
|
19
|
+
> fi
|
|
20
|
+
> ;;
|
|
20
21
|
>
|
|
21
|
-
|
|
22
|
-
condition = "elif"
|
|
23
22
|
end
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
>
|
|
27
|
-
>
|
|
24
|
+
if commands.empty?
|
|
25
|
+
> "root")
|
|
26
|
+
> root_command
|
|
27
|
+
> ;;
|
|
28
|
+
end
|
|
29
|
+
>
|
|
30
|
+
> esac
|
|
28
31
|
> }
|
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: 0.9.1
|
|
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-12-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: completely
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 0.5.
|
|
19
|
+
version: 0.5.1
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 0.5.
|
|
26
|
+
version: 0.5.1
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: gtx
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -86,14 +86,14 @@ dependencies:
|
|
|
86
86
|
requirements:
|
|
87
87
|
- - "~>"
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
|
-
version:
|
|
89
|
+
version: 0.7.2
|
|
90
90
|
type: :runtime
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
94
|
- - "~>"
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
|
-
version:
|
|
96
|
+
version: 0.7.2
|
|
97
97
|
- !ruby/object:Gem::Dependency
|
|
98
98
|
name: requires
|
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -139,10 +139,10 @@ files:
|
|
|
139
139
|
- lib/bashly/extensions/yaml.rb
|
|
140
140
|
- lib/bashly/libraries.yml
|
|
141
141
|
- lib/bashly/libraries/base.rb
|
|
142
|
-
- lib/bashly/libraries/completions.rb
|
|
143
142
|
- lib/bashly/libraries/completions_function.rb
|
|
144
143
|
- lib/bashly/libraries/completions_script.rb
|
|
145
144
|
- lib/bashly/libraries/completions_yaml.rb
|
|
145
|
+
- lib/bashly/libraries/help.rb
|
|
146
146
|
- lib/bashly/library.rb
|
|
147
147
|
- lib/bashly/message_strings.rb
|
|
148
148
|
- lib/bashly/refinements/compose_refinements.rb
|
|
@@ -155,6 +155,7 @@ files:
|
|
|
155
155
|
- lib/bashly/script/wrapper.rb
|
|
156
156
|
- lib/bashly/settings.rb
|
|
157
157
|
- lib/bashly/templates/bashly.yml
|
|
158
|
+
- lib/bashly/templates/help/help_command.sh
|
|
158
159
|
- lib/bashly/templates/lib/colors.sh
|
|
159
160
|
- lib/bashly/templates/lib/config.sh
|
|
160
161
|
- lib/bashly/templates/lib/sample_function.sh
|
|
@@ -230,6 +231,7 @@ metadata:
|
|
|
230
231
|
changelog_uri: https://github.com/DannyBen/bashly/blob/master/CHANGELOG.md
|
|
231
232
|
homepage_uri: https://bashly.dannyb.co/
|
|
232
233
|
source_code_uri: https://github.com/DannyBen/bashly
|
|
234
|
+
rubygems_mfa_required: 'true'
|
|
233
235
|
post_install_message:
|
|
234
236
|
rdoc_options: []
|
|
235
237
|
require_paths:
|
|
@@ -245,7 +247,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
245
247
|
- !ruby/object:Gem::Version
|
|
246
248
|
version: '0'
|
|
247
249
|
requirements: []
|
|
248
|
-
rubygems_version: 3.3.
|
|
250
|
+
rubygems_version: 3.3.26
|
|
249
251
|
signing_key:
|
|
250
252
|
specification_version: 4
|
|
251
253
|
summary: Bash Command Line Tool Generator
|