Skip to content

Commit f9768b4

Browse files
authored
Merge pull request #241 from DannyBen/refactor/templates
Normalize templates
2 parents c35d057 + 53e6342 commit f9768b4

39 files changed

+265
-235
lines changed

lib/bashly/views/argument/usage.gtx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
= view_marker
2+
23
> echo " {{ label }}"
34
> printf "{{ help.wrap(76).indent(4).sanitize_for_print }}\n"
45

56
if allowed
6-
> printf " {{ strings[:allowed] % { values: allowed.join(', ') } }}\n"
7+
> printf " {{ strings[:allowed] % { values: allowed.join(', ') } }}\n"
78
end
89

910
if default
10-
> printf " {{ strings[:default] % { value: default } }}\n"
11+
> printf " {{ strings[:default] % { value: default } }}\n"
1112
end
1213

1314
> echo
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
if validate
2+
13
= view_marker
24

3-
if validate
45
> if [[ -n $(validate_{{ validate }} "$1") ]]; then
56
> printf "{{ strings[:validation_error] }}\n" "{{ name.upcase }}" "$(validate_{{ validate }} "$1")"
67
> exit 1
78
> fi
89
>
910

10-
end
11+
end
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
= view_marker
2-
31
if catch_all.required?
4-
> if [[ ${#other_args[@]} -eq 0 ]]; then
5-
> printf "{{ strings[:missing_required_argument] % { arg: catch_all.label, usage: usage_string } }}\n"
6-
> exit 1
7-
> fi
8-
end
2+
= view_marker
93

10-
>
4+
> if [[ ${#other_args[@]} -eq 0 ]]; then
5+
> printf "{{ strings[:missing_required_argument] % { arg: catch_all.label, usage: usage_string } }}\n"
6+
> exit 1
7+
> fi
8+
>
9+
10+
end

lib/bashly/views/command/command_fallback.gtx

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
11
= view_marker
22

33
if default_command
4-
> "" )
5-
> {{ function_name }}_usage
6-
> exit 1
7-
> ;;
8-
>
9-
> * )
10-
> action="{{ default_command.name }}"
11-
> {{ default_command.function_name }}_parse_requirements "$@"
12-
> shift $#
13-
> ;;
14-
>
4+
> "" )
5+
> {{ function_name }}_usage
6+
> exit 1
7+
> ;;
8+
>
9+
> * )
10+
> action="{{ default_command.name }}"
11+
> {{ default_command.function_name }}_parse_requirements "$@"
12+
> shift $#
13+
> ;;
14+
>
1515

1616
elsif extensible.is_a? String
17-
> "" )
18-
> {{ function_name }}_usage
19-
> exit 1
20-
> ;;
21-
>
22-
> * )
23-
> if [[ -x "$(command -v "{{ extensible }}")" ]]; then
24-
> exec {{ extensible }} "$@"
25-
> else
26-
> {{ function_name }}_usage
27-
> exit 1
28-
> fi
29-
>
17+
> "" )
18+
> {{ function_name }}_usage
19+
> exit 1
20+
> ;;
21+
>
22+
> * )
23+
> if [[ -x "$(command -v "{{ extensible }}")" ]]; then
24+
> exec {{ extensible }} "$@"
25+
> else
26+
> {{ function_name }}_usage
27+
> exit 1
28+
> fi
29+
>
3030

3131
elsif extensible
32-
> "" )
33-
> {{ function_name }}_usage
34-
> exit 1
35-
> ;;
36-
>
37-
> * )
38-
> if [[ -x "$(command -v "{{ function_name }}-$action")" ]]; then
39-
> shift
40-
> exec "{{ function_name }}-$action" "$@"
41-
> else
42-
> {{ function_name }}_usage
43-
> exit 1
44-
> fi
45-
>
32+
> "" )
33+
> {{ function_name }}_usage
34+
> exit 1
35+
> ;;
36+
>
37+
> * )
38+
> if [[ -x "$(command -v "{{ function_name }}-$action")" ]]; then
39+
> shift
40+
> exec "{{ function_name }}-$action" "$@"
41+
> else
42+
> {{ function_name }}_usage
43+
> exit 1
44+
> fi
45+
>
4646

4747
else
48-
> * )
49-
> {{ function_name }}_usage
50-
> exit 1
51-
> ;;
52-
>
48+
> * )
49+
> {{ function_name }}_usage
50+
> exit 1
51+
> ;;
52+
>
5353

5454
end
5555

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
= view_marker
22

33
if commands.any?
4-
> action=${1:-}
5-
>
6-
> case $action in
7-
> -* )
8-
> ;;
9-
>
4+
> action=${1:-}
5+
>
6+
> case $action in
7+
> -* )
8+
> ;;
9+
>
1010

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-
>
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+
>
1919

20-
end
20+
end
2121

22-
= render :command_fallback
23-
> esac
24-
>
22+
= render :command_fallback
23+
> esac
24+
>
2525

2626
else
27-
> action="{{ action_name }}"
27+
> action="{{ action_name }}"
28+
2829
end
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
= view_marker
2+
23
deep_commands.each do |command|
3-
= command.render :function unless command.commands.any?
4+
= command.render :function unless command.commands.any?
45
end
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
= view_marker
1+
if default_args.any? or default_flags.any?
2+
= view_marker
23

3-
default_args.each do |arg|
4-
> [[ -n ${args[{{ arg.name }}]:-} ]] || args[{{ arg.name }}]="{{ arg.default }}"
5-
end
4+
default_args.each do |arg|
5+
> [[ -n ${args[{{ arg.name }}]:-} ]] || args[{{ arg.name }}]="{{ arg.default }}"
6+
end
67

7-
default_flags.each do |flag|
8-
> [[ -n ${args[{{ flag.long }}]:-} ]] || args[{{ flag.long }}]="{{ flag.default }}"
9-
end
8+
default_flags.each do |flag|
9+
> [[ -n ${args[{{ flag.long }}]:-} ]] || args[{{ flag.long }}]="{{ flag.default }}"
10+
end
1011

11-
>
12+
>
13+
end

lib/bashly/views/command/dependencies_filter.gtx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
= view_marker
2-
31
if dependencies
2+
= view_marker
3+
44
dependencies.each do |dependency|
55
> if ! [[ -x "$(command -v {{ dependency }})" ]]; then
66
> printf "{{ strings[:missing_dependency] % { dependency: dependency } }}\n"
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
= view_marker
1+
if default_environment_variables.any? or required_environment_variables.any?
2+
= view_marker
23

3-
if default_environment_variables.any?
4-
default_environment_variables.each do |env_var|
5-
> export {{ env_var.name.upcase }}="${<%= env_var.name.upcase %>:-<%= env_var.default %>}"
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
68
end
7-
end
89

9-
if required_environment_variables.any?
10-
required_environment_variables.each do |env_var|
11-
> if [[ -z "${<%= env_var.name.upcase %>:-}" ]]; then
12-
> printf "{{ strings[:missing_required_environment_variable] % { var: env_var.name.upcase } }}\n"
13-
> exit 1
14-
> fi
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
1517
end
16-
end
18+
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
= view_marker
2+
23
> printf "{{ footer.gsub("\n", '\n').gsub('"', '\"') }}\n"
34
> echo
45
>

0 commit comments

Comments
 (0)