bashly 0.8.1 → 0.8.4
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/generate.rb +40 -4
- data/lib/bashly/concerns/renderable.rb +19 -6
- data/lib/bashly/config_validator.rb +11 -0
- data/lib/bashly/extensions/string.rb +2 -2
- data/lib/bashly/script/command.rb +126 -24
- 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 +89 -60
- data/lib/bashly/concerns/command_scopes.rb +0 -83
- 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 -18
- 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
@@ -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
|
@@ -0,0 +1,20 @@
|
|
1
|
+
= view_marker
|
2
|
+
|
3
|
+
> printf "{{ strings[:arguments] }}\n"
|
4
|
+
|
5
|
+
if args.any?
|
6
|
+
>
|
7
|
+
args.each do |arg|
|
8
|
+
= arg.render(:usage)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
if catch_all.help
|
13
|
+
>
|
14
|
+
> echo " {{ catch_all.label }}"
|
15
|
+
> printf "{{ catch_all.help.wrap(76).indent(4).sanitize_for_print }}\n"
|
16
|
+
> echo
|
17
|
+
end
|
18
|
+
|
19
|
+
>
|
20
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
= view_marker
|
2
|
+
|
3
|
+
maxlen = command_help_data.values.map(&:keys).flatten.map(&:size).max
|
4
|
+
|
5
|
+
command_help_data.each do |group, commands|
|
6
|
+
> printf "{{ group }}\n"
|
7
|
+
|
8
|
+
commands.each do |command, info|
|
9
|
+
if info[:help_only]
|
10
|
+
> [[ -n $long_usage ]] && echo " {{ command.ljust maxlen }} {{ info[:summary] }}"
|
11
|
+
else
|
12
|
+
> echo " {{ command.ljust maxlen }} {{ info[:summary] }}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
> echo
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
= view_marker
|
2
|
+
|
3
|
+
= short_flag_exist?("-h") ? 'echo " --help"' : 'echo " --help, -h"'
|
4
|
+
> printf " {{ strings[:help_flag_text] }}\n"
|
5
|
+
> echo
|
6
|
+
|
7
|
+
if root_command?
|
8
|
+
= short_flag_exist?("-v") ? 'echo " --version"' : 'echo " --version, -v"'
|
9
|
+
> printf " {{ strings[:version_flag_text] }}\n"
|
10
|
+
> echo
|
11
|
+
end
|
12
|
+
|
13
|
+
>
|
@@ -0,0 +1,41 @@
|
|
1
|
+
if whitelisted_args.any? or whitelisted_flags.any?
|
2
|
+
= view_marker
|
3
|
+
|
4
|
+
whitelisted_args.each do |arg|
|
5
|
+
if arg.repeatable
|
6
|
+
> eval "input_array=(${args[{{ arg.name }}]})"
|
7
|
+
> for i in "${input_array[@]}"; do
|
8
|
+
> if [[ ! $i =~ ^({{ arg.allowed.join '|' }})$ ]]; then
|
9
|
+
> printf "%s\n" "{{ strings[:disallowed_argument] % { name: arg.name, allowed: arg.allowed.join(', ') } }}"
|
10
|
+
> exit 1
|
11
|
+
> fi
|
12
|
+
> done
|
13
|
+
|
14
|
+
else
|
15
|
+
> if [[ ! ${args[{{ arg.name }}]} =~ ^({{ arg.allowed.join '|' }})$ ]]; then
|
16
|
+
> printf "%s\n" "{{ strings[:disallowed_argument] % { name: arg.name, allowed: arg.allowed.join(', ') } }}"
|
17
|
+
> exit 1
|
18
|
+
> fi
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
whitelisted_flags.each do |flag|
|
24
|
+
if flag.repeatable
|
25
|
+
> eval "input_array=(${args[{{ flag.name }}]})"
|
26
|
+
> for i in "${input_array[@]}"; do
|
27
|
+
> if [[ ! $i =~ ^({{ flag.allowed.join '|' }})$ ]]; then
|
28
|
+
> printf "%s\n" "{{ strings[:disallowed_flag] % { name: flag.name, allowed: flag.allowed.join(', ') } }}"
|
29
|
+
> exit 1
|
30
|
+
> fi
|
31
|
+
> done
|
32
|
+
|
33
|
+
else
|
34
|
+
> if [[ ! ${args[{{ flag.name }}]} =~ ^({{ flag.allowed.join '|' }})$ ]]; then
|
35
|
+
> printf "%s\n" "{{ strings[:disallowed_flag] % { name: flag.name, allowed: flag.allowed.join(', ') } }}"
|
36
|
+
> exit 1
|
37
|
+
> fi
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
= view_marker
|
2
|
+
|
3
|
+
> if [[ -n ${2+x} ]]; then
|
4
|
+
= render(:validations).indent 2
|
5
|
+
|
6
|
+
if repeatable
|
7
|
+
> if [[ -z ${args[{{ name }}]+x} ]]; then
|
8
|
+
> args[{{ name }}]="\"$2\""
|
9
|
+
> else
|
10
|
+
> args[{{ name }}]="${args[{{ name }}]} \"$2\""
|
11
|
+
> fi
|
12
|
+
|
13
|
+
else
|
14
|
+
> args[{{ name }}]="$2"
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
> shift
|
19
|
+
> shift
|
20
|
+
> else
|
21
|
+
> printf "%s\n" "{{ strings[:flag_requires_an_argument] % { name: name, usage: usage_string } }}"
|
22
|
+
> exit 1
|
23
|
+
> fi
|
24
|
+
> ;;
|
25
|
+
>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
if conflicts
|
2
|
+
|
3
|
+
= view_marker
|
4
|
+
|
5
|
+
if conflicts.count == 1
|
6
|
+
> if [[ -n "${args[{{ conflicts.first }}]:-}" ]]; then
|
7
|
+
> printf "{{ strings[:conflicting_flags] }}\n" "$key" "{{ conflicts.first }}"
|
8
|
+
> exit 1
|
9
|
+
> fi
|
10
|
+
>
|
11
|
+
|
12
|
+
else
|
13
|
+
> for conflict in {{ conflicts.join ' ' }}; do
|
14
|
+
> if [[ -n "${args[$conflict]:-}" ]]; then
|
15
|
+
> printf "{{ strings[:conflicting_flags] }}\n" "$key" "$conflict"
|
16
|
+
> exit 1
|
17
|
+
> fi
|
18
|
+
> done
|
19
|
+
>
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
= view_marker
|
2
|
+
|
3
|
+
> echo " {{ usage_string extended: true }}"
|
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
|
+
>
|