bashly 0.8.2 → 0.8.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bashly/concerns/renderable.rb +3 -6
- data/lib/bashly/extensions/string.rb +2 -2
- data/lib/bashly/templates/strings.yml +1 -0
- data/lib/bashly/version.rb +1 -1
- data/lib/bashly/views/README.md +6 -0
- data/lib/bashly/views/argument/usage.gtx +15 -0
- data/lib/bashly/views/argument/validations.gtx +11 -0
- data/lib/bashly/views/command/catch_all_filter.gtx +10 -0
- data/lib/bashly/views/command/command_fallback.gtx +42 -0
- data/lib/bashly/views/command/command_filter.gtx +29 -0
- data/lib/bashly/views/command/command_functions.gtx +5 -0
- data/lib/bashly/views/command/default_assignments.gtx +13 -0
- data/lib/bashly/views/command/default_initialize_script.gtx +7 -0
- data/lib/bashly/views/command/default_root_script.gtx +4 -0
- data/lib/bashly/views/command/default_script.gtx +5 -0
- data/lib/bashly/views/command/dependencies_filter.gtx +10 -0
- data/lib/bashly/views/command/environment_variables_filter.gtx +18 -0
- data/lib/bashly/views/command/fixed_flags_filter.gtx +20 -0
- data/lib/bashly/views/command/footer.gtx +5 -0
- data/lib/bashly/views/command/function.gtx +6 -0
- data/lib/bashly/views/command/initialize.gtx +12 -0
- data/lib/bashly/views/command/inspect_args.gtx +21 -0
- data/lib/bashly/views/command/long_usage.gtx +13 -0
- data/lib/bashly/views/command/master_script.gtx +17 -0
- data/lib/bashly/views/command/normalize_input.gtx +25 -0
- data/lib/bashly/views/command/parse_requirements.gtx +26 -0
- data/lib/bashly/views/command/parse_requirements_case.gtx +11 -0
- data/lib/bashly/views/command/parse_requirements_case_catch_all.gtx +23 -0
- data/lib/bashly/views/command/parse_requirements_case_repeatable.gtx +24 -0
- data/lib/bashly/views/command/parse_requirements_case_simple.gtx +25 -0
- data/lib/bashly/views/command/parse_requirements_while.gtx +33 -0
- data/lib/bashly/views/command/required_args_filter.gtx +13 -0
- data/lib/bashly/views/command/required_flags_filter.gtx +12 -0
- data/lib/bashly/views/command/root_command.gtx +6 -0
- data/lib/bashly/views/command/run.gtx +28 -0
- data/lib/bashly/views/command/usage.gtx +50 -0
- data/lib/bashly/views/command/usage_args.gtx +20 -0
- data/lib/bashly/views/command/usage_commands.gtx +18 -0
- data/lib/bashly/views/command/usage_environment_variables.gtx +10 -0
- data/lib/bashly/views/command/usage_examples.gtx +10 -0
- data/lib/bashly/views/command/usage_fixed_flags.gtx +13 -0
- data/lib/bashly/views/command/usage_flags.gtx +7 -0
- data/lib/bashly/views/command/user_filter.gtx +13 -0
- data/lib/bashly/views/command/user_lib.gtx +11 -0
- data/lib/bashly/views/command/version_command.gtx +6 -0
- data/lib/bashly/views/command/whitelist_filter.gtx +41 -0
- data/lib/bashly/views/environment_variable/usage.gtx +11 -0
- data/lib/bashly/views/flag/case.gtx +6 -0
- data/lib/bashly/views/flag/case_arg.gtx +25 -0
- data/lib/bashly/views/flag/case_no_arg.gtx +11 -0
- data/lib/bashly/views/flag/conflicts.gtx +22 -0
- data/lib/bashly/views/flag/usage.gtx +15 -0
- data/lib/bashly/views/flag/validations.gtx +11 -0
- data/lib/bashly/views/wrapper/bash3_bouncer.gtx +7 -0
- data/lib/bashly/views/wrapper/header.gtx +5 -0
- data/lib/bashly/views/wrapper/wrapper.gtx +8 -0
- metadata +76 -60
- data/lib/bashly/views/argument/usage.erb +0 -10
- data/lib/bashly/views/argument/validations.erb +0 -8
- data/lib/bashly/views/command/catch_all_filter.erb +0 -7
- data/lib/bashly/views/command/command_fallback.erb +0 -45
- data/lib/bashly/views/command/command_filter.erb +0 -22
- data/lib/bashly/views/command/command_functions.erb +0 -4
- data/lib/bashly/views/command/default_assignments.erb +0 -7
- data/lib/bashly/views/command/default_initialize_script.erb +0 -6
- data/lib/bashly/views/command/default_root_script.erb +0 -3
- data/lib/bashly/views/command/default_script.erb +0 -4
- data/lib/bashly/views/command/dependencies_filter.erb +0 -9
- data/lib/bashly/views/command/environment_variables_filter.erb +0 -14
- data/lib/bashly/views/command/fixed_flags_filter.erb +0 -24
- data/lib/bashly/views/command/footer.erb +0 -3
- data/lib/bashly/views/command/function.erb +0 -4
- data/lib/bashly/views/command/initialize.erb +0 -8
- data/lib/bashly/views/command/inspect_args.erb +0 -19
- data/lib/bashly/views/command/master_script.erb +0 -14
- data/lib/bashly/views/command/normalize_input.erb +0 -24
- data/lib/bashly/views/command/parse_requirements.erb +0 -22
- data/lib/bashly/views/command/parse_requirements_case.erb +0 -8
- data/lib/bashly/views/command/parse_requirements_case_catch_all.erb +0 -18
- data/lib/bashly/views/command/parse_requirements_case_repeatable.erb +0 -18
- data/lib/bashly/views/command/parse_requirements_case_simple.erb +0 -18
- data/lib/bashly/views/command/parse_requirements_while.erb +0 -26
- data/lib/bashly/views/command/required_args_filter.erb +0 -7
- data/lib/bashly/views/command/required_flags_filter.erb +0 -7
- data/lib/bashly/views/command/root_command.erb +0 -4
- data/lib/bashly/views/command/run.erb +0 -23
- data/lib/bashly/views/command/usage.erb +0 -50
- data/lib/bashly/views/command/usage_args.erb +0 -14
- data/lib/bashly/views/command/usage_commands.erb +0 -13
- data/lib/bashly/views/command/usage_environment_variables.erb +0 -6
- data/lib/bashly/views/command/usage_examples.erb +0 -7
- data/lib/bashly/views/command/usage_fixed_flags.erb +0 -17
- data/lib/bashly/views/command/usage_flags.erb +0 -4
- data/lib/bashly/views/command/user_filter.erb +0 -11
- data/lib/bashly/views/command/user_lib.erb +0 -6
- data/lib/bashly/views/command/version_command.erb +0 -4
- data/lib/bashly/views/command/whitelist_filter.erb +0 -33
- data/lib/bashly/views/environment_variable/usage.erb +0 -7
- data/lib/bashly/views/flag/case.erb +0 -4
- data/lib/bashly/views/flag/case_arg.erb +0 -19
- data/lib/bashly/views/flag/case_no_arg.erb +0 -8
- data/lib/bashly/views/flag/conflicts.erb +0 -18
- data/lib/bashly/views/flag/usage.erb +0 -10
- data/lib/bashly/views/flag/validations.erb +0 -8
- data/lib/bashly/views/wrapper/bash3_bouncer.erb +0 -5
- data/lib/bashly/views/wrapper/header.erb +0 -4
- data/lib/bashly/views/wrapper/wrapper.erb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47591327725b9e1265c7c4b7a38d7992a939ee47956e3a1ff1bb764edd0da282
|
4
|
+
data.tar.gz: 3911b50fe1c23add51a538f0ed7b078b7ce23df5a6959f0f1dbe4451ebec3e39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1aab1a02d6648e28ba7274350b68a2a1e6fd5719939f0c5e340604637573ef3069f4800719ec6c1923d18b2c9e602f2366d5bc54ca12330dc962526ae2dbb71
|
7
|
+
data.tar.gz: 577f8eed84b30bd7fdbdb864f97487cc9ed22b8e8f768b43a8b61091511e56dbeeac9b10d0030dbaac54e06bcb6fdcdd1b5c2d4207f8c68c28923f2f382c8e27
|
@@ -1,12 +1,9 @@
|
|
1
|
-
require '
|
1
|
+
require 'gtx'
|
2
2
|
|
3
3
|
module Bashly
|
4
4
|
module Renderable
|
5
5
|
def render(view)
|
6
|
-
|
7
|
-
erb = ERB.new(template, trim_mode: '%-')
|
8
|
-
erb.filename = "#{views_subfolder}.#{view}"
|
9
|
-
erb.result binding
|
6
|
+
GTX.render_file view_path(view), context: binding, filename: "#{views_subfolder}.#{view}"
|
10
7
|
end
|
11
8
|
|
12
9
|
def strings
|
@@ -37,7 +34,7 @@ module Bashly
|
|
37
34
|
private
|
38
35
|
|
39
36
|
def view_path(view)
|
40
|
-
"#{self_views_path}/#{view}.
|
37
|
+
"#{self_views_path}/#{view}.gtx"
|
41
38
|
end
|
42
39
|
|
43
40
|
def self_views_path
|
@@ -5,7 +5,7 @@ class String
|
|
5
5
|
|
6
6
|
def indent(offset)
|
7
7
|
return self unless offset > 0
|
8
|
-
|
8
|
+
lines.indent(offset).join
|
9
9
|
end
|
10
10
|
|
11
11
|
def to_underscore
|
@@ -24,7 +24,7 @@ class String
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def lint
|
27
|
-
gsub(/\s+\n/m, "\n\n").lines.reject { |l| l =~ /^\s*##/ }.join
|
27
|
+
gsub(/\s+\n/m, "\n\n").lines.reject { |l| l =~ /^\s*##/ }.join
|
28
28
|
end
|
29
29
|
|
30
30
|
def remove_front_matter
|
@@ -26,6 +26,7 @@ version_flag_text: Show version number
|
|
26
26
|
flag_requires_an_argument: "%{name} requires an argument: %{usage}"
|
27
27
|
invalid_argument: "invalid argument: %s"
|
28
28
|
invalid_flag: "invalid option: %s"
|
29
|
+
invalid_command: "invalid command: %s"
|
29
30
|
conflicting_flags: "conflicting options: %s cannot be used with %s"
|
30
31
|
missing_required_argument: "missing required argument: %{arg}\\nusage: %{usage}"
|
31
32
|
missing_required_flag: "missing required flag: %{usage}"
|
data/lib/bashly/version.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
= view_marker
|
2
|
+
|
3
|
+
> echo " {{ label }}"
|
4
|
+
> printf "{{ help.wrap(76).indent(4).sanitize_for_print }}\n"
|
5
|
+
|
6
|
+
if allowed
|
7
|
+
> printf " {{ strings[:allowed] % { values: allowed.join(', ') } }}\n"
|
8
|
+
end
|
9
|
+
|
10
|
+
if default
|
11
|
+
> printf " {{ strings[:default] % { value: default } }}\n"
|
12
|
+
end
|
13
|
+
|
14
|
+
> echo
|
15
|
+
>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
= view_marker
|
2
|
+
|
3
|
+
> "" )
|
4
|
+
> {{ function_name }}_usage
|
5
|
+
> exit 1
|
6
|
+
> ;;
|
7
|
+
>
|
8
|
+
> * )
|
9
|
+
|
10
|
+
if default_command
|
11
|
+
> action="{{ default_command.name }}"
|
12
|
+
> {{ default_command.function_name }}_parse_requirements "$@"
|
13
|
+
> shift $#
|
14
|
+
> ;;
|
15
|
+
>
|
16
|
+
|
17
|
+
elsif extensible.is_a? String
|
18
|
+
> if [[ -x "$(command -v "{{ extensible }}")" ]]; then
|
19
|
+
> exec {{ extensible }} "$@"
|
20
|
+
> else
|
21
|
+
> printf "{{ strings[:invalid_command] }}\n" "$action"
|
22
|
+
> exit 1
|
23
|
+
> fi
|
24
|
+
>
|
25
|
+
|
26
|
+
elsif extensible
|
27
|
+
> if [[ -x "$(command -v "{{ function_name }}-$action")" ]]; then
|
28
|
+
> shift
|
29
|
+
> exec "{{ function_name }}-$action" "$@"
|
30
|
+
> else
|
31
|
+
> printf "{{ strings[:invalid_command] }}\n" "$action"
|
32
|
+
> exit 1
|
33
|
+
> fi
|
34
|
+
>
|
35
|
+
|
36
|
+
else
|
37
|
+
> printf "{{ strings[:invalid_command] }}\n" "$action"
|
38
|
+
> exit 1
|
39
|
+
> ;;
|
40
|
+
>
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
= view_marker
|
2
|
+
|
3
|
+
if commands.any?
|
4
|
+
> action=${1:-}
|
5
|
+
>
|
6
|
+
> case $action in
|
7
|
+
> -* )
|
8
|
+
> ;;
|
9
|
+
>
|
10
|
+
|
11
|
+
commands.each do |command|
|
12
|
+
> {{ command.aliases.join " | " }} )
|
13
|
+
> action="{{ command.name }}"
|
14
|
+
> shift
|
15
|
+
> {{ command.function_name }}_parse_requirements "$@"
|
16
|
+
> shift $#
|
17
|
+
> ;;
|
18
|
+
>
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
= render :command_fallback
|
23
|
+
> esac
|
24
|
+
>
|
25
|
+
|
26
|
+
else
|
27
|
+
> action="{{ action_name }}"
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
if default_args.any? or default_flags.any?
|
2
|
+
= view_marker
|
3
|
+
|
4
|
+
default_args.each do |arg|
|
5
|
+
> [[ -n ${args[{{ arg.name }}]:-} ]] || args[{{ arg.name }}]="{{ arg.default }}"
|
6
|
+
end
|
7
|
+
|
8
|
+
default_flags.each do |flag|
|
9
|
+
> [[ -n ${args[{{ flag.long }}]:-} ]] || args[{{ flag.long }}]="{{ flag.default }}"
|
10
|
+
end
|
11
|
+
|
12
|
+
>
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
if default_environment_variables.any? or required_environment_variables.any?
|
2
|
+
= view_marker
|
3
|
+
|
4
|
+
if default_environment_variables.any?
|
5
|
+
default_environment_variables.each do |env_var|
|
6
|
+
> export {{ env_var.name.upcase }}="${<%= env_var.name.upcase %>:-<%= env_var.default %>}"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
if required_environment_variables.any?
|
11
|
+
required_environment_variables.each do |env_var|
|
12
|
+
> if [[ -z "${<%= env_var.name.upcase %>:-}" ]]; then
|
13
|
+
> printf "{{ strings[:missing_required_environment_variable] % { var: env_var.name.upcase } }}\n"
|
14
|
+
> exit 1
|
15
|
+
> fi
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
= view_marker
|
2
|
+
|
3
|
+
> case "${1:-}" in
|
4
|
+
|
5
|
+
if root_command?
|
6
|
+
= short_flag_exist?("-v") ? "--version )" : "--version | -v )"
|
7
|
+
> version_command
|
8
|
+
> exit
|
9
|
+
> ;;
|
10
|
+
>
|
11
|
+
end
|
12
|
+
|
13
|
+
= short_flag_exist?("-h") ? "--help )" : "--help | -h )"
|
14
|
+
> long_usage=yes
|
15
|
+
> <%= function_name %>_usage
|
16
|
+
> exit
|
17
|
+
> ;;
|
18
|
+
>
|
19
|
+
> esac
|
20
|
+
>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
= view_marker
|
2
|
+
|
3
|
+
> inspect_args() {
|
4
|
+
> readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)
|
5
|
+
> if (( ${#args[@]} )); then
|
6
|
+
> echo args:
|
7
|
+
> for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done
|
8
|
+
> else
|
9
|
+
> echo args: none
|
10
|
+
> fi
|
11
|
+
>
|
12
|
+
> if (( ${#other_args[@]} )); then
|
13
|
+
> echo
|
14
|
+
> echo other_args:
|
15
|
+
> echo "- \${other_args[*]} = ${other_args[*]}"
|
16
|
+
> for i in "${!other_args[@]}"; do
|
17
|
+
> echo "- \${other_args[$i]} = ${other_args[$i]}"
|
18
|
+
> done
|
19
|
+
> fi
|
20
|
+
> }
|
21
|
+
>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
= view_marker
|
2
|
+
|
3
|
+
> if [[ -n $long_usage ]]; then
|
4
|
+
> printf "{{ strings[:options] }}\n"
|
5
|
+
>
|
6
|
+
= render(:usage_fixed_flags).indent 2
|
7
|
+
= render(:usage_flags).indent 2 if flags.any?
|
8
|
+
= render(:usage_args).indent 2 if args.any? or catch_all.help
|
9
|
+
= render(:usage_environment_variables).indent 2 if environment_variables.any?
|
10
|
+
= render(:usage_examples).indent 2 if examples
|
11
|
+
= render(:footer).indent 2 if footer
|
12
|
+
>
|
13
|
+
> fi
|
@@ -0,0 +1,17 @@
|
|
1
|
+
= view_marker
|
2
|
+
|
3
|
+
= render :root_command if commands.empty?
|
4
|
+
= render :version_command
|
5
|
+
= render :usage
|
6
|
+
= render :normalize_input
|
7
|
+
= render :inspect_args
|
8
|
+
= render :user_lib if user_lib.any?
|
9
|
+
= render :command_functions
|
10
|
+
= render :parse_requirements
|
11
|
+
= render :initialize
|
12
|
+
= render :run
|
13
|
+
|
14
|
+
>
|
15
|
+
> initialize
|
16
|
+
> run "$@"
|
17
|
+
>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
= view_marker
|
2
|
+
|
3
|
+
> normalize_input() {
|
4
|
+
> local arg flags
|
5
|
+
>
|
6
|
+
> while [[ $# -gt 0 ]]; do
|
7
|
+
> arg="$1"
|
8
|
+
> if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then
|
9
|
+
> input+=("${BASH_REMATCH[1]}")
|
10
|
+
> input+=("${BASH_REMATCH[2]}")
|
11
|
+
> elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then
|
12
|
+
> input+=("${BASH_REMATCH[1]}")
|
13
|
+
> input+=("${BASH_REMATCH[2]}")
|
14
|
+
> elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then
|
15
|
+
> flags="${BASH_REMATCH[1]}"
|
16
|
+
> for (( i=0 ; i < ${#flags} ; i++ )); do
|
17
|
+
> input+=("-${flags:i:1}")
|
18
|
+
> done
|
19
|
+
> else
|
20
|
+
> input+=("$arg")
|
21
|
+
> fi
|
22
|
+
>
|
23
|
+
> shift
|
24
|
+
> done
|
25
|
+
> }
|
@@ -0,0 +1,26 @@
|
|
1
|
+
= view_marker
|
2
|
+
|
3
|
+
if root_command?
|
4
|
+
> parse_requirements() {
|
5
|
+
else
|
6
|
+
> {{ function_name }}_parse_requirements() {
|
7
|
+
end
|
8
|
+
|
9
|
+
= render(:fixed_flags_filter).indent 2
|
10
|
+
= render(:environment_variables_filter).indent 2
|
11
|
+
= render(:dependencies_filter).indent 2
|
12
|
+
= render(:command_filter).indent 2
|
13
|
+
= render(:parse_requirements_while).indent 2
|
14
|
+
= render(:required_args_filter).indent 2
|
15
|
+
= render(:required_flags_filter).indent 2
|
16
|
+
= render(:catch_all_filter).indent 2
|
17
|
+
= render(:default_assignments).indent 2
|
18
|
+
= render(:whitelist_filter).indent 2
|
19
|
+
= render(:user_filter).indent 2
|
20
|
+
|
21
|
+
> }
|
22
|
+
>
|
23
|
+
|
24
|
+
commands.each do |command|
|
25
|
+
= command.render :parse_requirements
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
= view_marker
|
2
|
+
|
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
|
+
> args[{{ arg.name }}]=$1
|
9
|
+
> shift
|
10
|
+
|
11
|
+
condition = "elif"
|
12
|
+
end
|
13
|
+
|
14
|
+
> else
|
15
|
+
> other_args+=("$1")
|
16
|
+
> shift
|
17
|
+
> fi
|
18
|
+
|
19
|
+
else
|
20
|
+
> other_args+=("$1")
|
21
|
+
> shift
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
= view_marker
|
2
|
+
|
3
|
+
condition = "if"
|
4
|
+
args.each do |arg|
|
5
|
+
> {{ condition }} [[ -z ${args[{{ arg.name }}]+x} ]]; then
|
6
|
+
= arg.render(:validations).indent 2
|
7
|
+
|
8
|
+
if arg.repeatable
|
9
|
+
> args[{{ arg.name }}]="\"$1\""
|
10
|
+
> shift
|
11
|
+
> else
|
12
|
+
> args[{{ arg.name }}]="${args[{{ arg.name }}]} \"$1\""
|
13
|
+
> shift
|
14
|
+
|
15
|
+
else
|
16
|
+
> args[{{ arg.name }}]=$1
|
17
|
+
> shift
|
18
|
+
|
19
|
+
end
|
20
|
+
condition = "elif"
|
21
|
+
end
|
22
|
+
|
23
|
+
> fi
|
24
|
+
>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
= view_marker
|
2
|
+
|
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
|
+
> args[{{ arg.name }}]=$1
|
9
|
+
> shift
|
10
|
+
|
11
|
+
condition = "elif"
|
12
|
+
end
|
13
|
+
|
14
|
+
> else
|
15
|
+
> printf "{{ strings[:invalid_argument] }}\n" "$key"
|
16
|
+
> exit 1
|
17
|
+
> fi
|
18
|
+
|
19
|
+
else
|
20
|
+
> printf "{{ strings[:invalid_argument] }}\n" "$key"
|
21
|
+
> exit 1
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
= view_marker
|
2
|
+
|
3
|
+
> while [[ $# -gt 0 ]]; do
|
4
|
+
> key="$1"
|
5
|
+
> case "$key" in
|
6
|
+
|
7
|
+
flags.each do |flag|
|
8
|
+
= flag.render(:case).indent 2
|
9
|
+
end
|
10
|
+
|
11
|
+
>
|
12
|
+
> -?* )
|
13
|
+
|
14
|
+
if catch_all.enabled?
|
15
|
+
> other_args+=("$1")
|
16
|
+
> shift
|
17
|
+
> ;;
|
18
|
+
|
19
|
+
else
|
20
|
+
> printf "<%= strings[:invalid_flag] %>\n" "$key"
|
21
|
+
> exit 1
|
22
|
+
> ;;
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
>
|
27
|
+
> * )
|
28
|
+
= render(:parse_requirements_case).indent 4
|
29
|
+
> ;;
|
30
|
+
>
|
31
|
+
> esac
|
32
|
+
> done
|
33
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
if required_args.any?
|
2
|
+
= view_marker
|
3
|
+
|
4
|
+
required_args.each do |arg|
|
5
|
+
> if [[ -z ${args[{{ arg.name }}]+x} ]]; then
|
6
|
+
> printf "{{ strings[:missing_required_argument] % { arg: arg.name.upcase, usage: usage_string } }}\n"
|
7
|
+
> exit 1
|
8
|
+
> fi
|
9
|
+
end
|
10
|
+
|
11
|
+
>
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
= view_marker
|
2
|
+
|
3
|
+
> run() {
|
4
|
+
> declare -A args=()
|
5
|
+
> declare -a other_args=()
|
6
|
+
> declare -a input=()
|
7
|
+
> normalize_input "$@"
|
8
|
+
> parse_requirements "${input[@]}"
|
9
|
+
>
|
10
|
+
|
11
|
+
condition = "if"
|
12
|
+
deep_commands.each do |command|
|
13
|
+
> {{ condition }} [[ $action == "{{ command.action_name }}" ]]; then
|
14
|
+
> if [[ ${args[--help]:-} ]]; then
|
15
|
+
> long_usage=yes
|
16
|
+
> {{ command.function_name }}_usage
|
17
|
+
> else
|
18
|
+
> {{ command.function_name }}_command
|
19
|
+
> fi
|
20
|
+
>
|
21
|
+
|
22
|
+
condition = "elif"
|
23
|
+
end
|
24
|
+
|
25
|
+
> {{ condition }} [[ $action == "root" ]]; then
|
26
|
+
> root_command
|
27
|
+
> fi
|
28
|
+
> }
|
@@ -0,0 +1,50 @@
|
|
1
|
+
= view_marker
|
2
|
+
|
3
|
+
> {{ function_name }}_usage() {
|
4
|
+
> if [[ -n $long_usage ]]; then
|
5
|
+
|
6
|
+
if summary == help
|
7
|
+
> printf "{{ caption_string }}\n"
|
8
|
+
> echo
|
9
|
+
else
|
10
|
+
> printf "{{ full_name }}\n"
|
11
|
+
> echo
|
12
|
+
> printf "{{ help.wrap(78).indent(2).sanitize_for_print }}\n"
|
13
|
+
> echo
|
14
|
+
end
|
15
|
+
|
16
|
+
> else
|
17
|
+
> printf "{{ caption_string }}\n"
|
18
|
+
> echo
|
19
|
+
> fi
|
20
|
+
>
|
21
|
+
|
22
|
+
if alt&.any?
|
23
|
+
> printf "{{ strings[:command_alias] % { alias: alt.join(', ') } }}\n"
|
24
|
+
> echo
|
25
|
+
end
|
26
|
+
|
27
|
+
>
|
28
|
+
> printf "{{ strings[:usage] }}\n"
|
29
|
+
> printf " {{ usage_string }}\n"
|
30
|
+
|
31
|
+
if commands.any?
|
32
|
+
> printf " {{ full_name }} [command] --help{{ " | -h" unless short_flag_exist? "-h" }}\n"
|
33
|
+
else
|
34
|
+
> printf " {{ full_name }} --help{{ " | -h" unless short_flag_exist? "-h" }}\n"
|
35
|
+
end
|
36
|
+
|
37
|
+
if root_command?
|
38
|
+
> printf " {{ full_name }} --version{{ " | -v" unless short_flag_exist? "-v" }}\n"
|
39
|
+
end
|
40
|
+
> echo
|
41
|
+
|
42
|
+
= render(:usage_commands).indent 2 if commands.any?
|
43
|
+
>
|
44
|
+
= render(:long_usage).indent 2
|
45
|
+
> }
|
46
|
+
>
|
47
|
+
|
48
|
+
commands.each do |command|
|
49
|
+
= command.render 'usage'
|
50
|
+
end
|