Skip to content

Commit 6ff4a10

Browse files
authored
Merge pull request #98 from DannyBen/update/erb-shorthand
Refactor erb views to use % shorthand
2 parents 14ce96d + ef9ca96 commit 6ff4a10

25 files changed

+115
-115
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# :argument.usage
22
echo " <%= name.upcase %>"
33
printf "<%= help.wrap(76).indent(4).sanitize_for_print %>\n"
4-
<%- if allowed -%>
4+
% if allowed
55
printf " <%= strings[:allowed] % { values: allowed.join(', ') } -%>\n"
6-
<%- end -%>
7-
<%- if default -%>
6+
% end
7+
% if default
88
printf " <%= strings[:default] % { value: default } -%>\n"
9-
<%- end -%>
9+
% end
1010
echo
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# :command.catch_all_filter
2-
<%- if catch_all_required? -%>
2+
% if catch_all_required?
33
if [[ ${#other_args[@]} -eq 0 ]]; then
44
printf "<%= strings[:missing_required_argument] % { arg: catch_all_label, usage: usage_string } %>\n"
55
exit 1
66
fi
7-
<%- end -%>
7+
% end

lib/bashly/views/command/command_fallback.erb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# :command.command_fallback
2-
<%- if default_command -%>
2+
% if default_command
33
"" )
44
<%= function_name %>_usage
55
exit 1
@@ -10,7 +10,7 @@
1010
<%= default_command.function_name %>_parse_requirements "$@"
1111
shift $#
1212
;;
13-
<%- elsif extensible.is_a? String -%>
13+
% elsif extensible.is_a? String
1414
"" )
1515
<%= function_name %>_usage
1616
exit 1
@@ -23,7 +23,7 @@
2323
<%= function_name %>_usage
2424
exit 1
2525
fi
26-
<%- elsif extensible -%>
26+
% elsif extensible
2727
"" )
2828
<%= function_name %>_usage
2929
exit 1
@@ -37,9 +37,9 @@
3737
<%= function_name %>_usage
3838
exit 1
3939
fi
40-
<%- else -%>
40+
% else
4141
* )
4242
<%= function_name %>_usage
4343
exit 1
4444
;;
45-
<%- end -%>
45+
% end
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# :command.command_filter
2-
<%- if commands.any? -%>
2+
% if commands.any?
33
action=$1
44

55
case $action in
66
-* )
77
;;
88

9-
<%- commands.each do |command| -%>
9+
% commands.each do |command|
1010
<%= command.aliases.join " | " %> )
1111
action="<%= command.name %>"
1212
shift
1313
<%= command.function_name %>_parse_requirements "$@"
1414
shift $#
1515
;;
1616

17-
<%- end -%>
17+
% end
1818
<%= render :command_fallback %>
1919
esac
20-
<%- else -%>
20+
% else
2121
action="<%= action_name %>"
22-
<%- end -%>
22+
% end
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# :command.command_functions
2-
<%- deep_commands.each do |command| -%>
2+
% deep_commands.each do |command|
33
<%= command.render :function unless command.commands.any? %>
4-
<%- end -%>
4+
% end
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# :command.default_assignments
2-
<%- default_args.each do |arg| -%>
2+
% default_args.each do |arg|
33
[[ -n ${args[<%= arg.name %>]} ]] || args[<%= arg.name %>]="<%= arg.default %>"
4-
<%- end -%>
5-
<%- default_flags.each do |flag| -%>
4+
% end
5+
% default_flags.each do |flag|
66
[[ -n ${args[<%= flag.long %>]} ]] || args[<%= flag.long %>]="<%= flag.default %>"
7-
<%- end -%>
7+
% end
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# :command.dependencies_filter
2-
<%- if dependencies -%>
3-
<%- dependencies.each do |dependency| -%>
2+
% if dependencies
3+
% dependencies.each do |dependency|
44
if ! [[ -x "$(command -v <%= dependency %>)" ]]; then
55
printf "<%= strings[:missing_dependency] % { dependency: dependency } -%>\n"
66
exit 1
77
fi
8-
<%- end -%>
9-
<%- end -%>
8+
% end
9+
% end
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# :command.environment_variables_filter
2-
<%- if default_environment_variables.any? -%>
3-
<%- default_environment_variables.each do |env_var| -%>
2+
% if default_environment_variables.any?
3+
% default_environment_variables.each do |env_var|
44
export <%= env_var.name.upcase %>="${<%= env_var.name.upcase %>:-<%= env_var.default %>}"
5-
<%- end -%>
6-
<%- end -%>
7-
<%- if required_environment_variables.any? -%>
8-
<%- required_environment_variables.each do |env_var| -%>
5+
% end
6+
% end
7+
% if required_environment_variables.any?
8+
% required_environment_variables.each do |env_var|
99
if [[ -z "$<%= env_var.name.upcase %>" ]]; then
10-
printf "<%= strings[:missing_required_environment_variable] % { var: env_var.name.upcase } -%>\n"
10+
printf "<%= strings[:missing_required_environment_variable] % { var: env_var.name.upcase } %>\n"
1111
exit 1
1212
fi
13-
<%- end -%>
14-
<%- end -%>
13+
% end
14+
% end

lib/bashly/views/command/fixed_flags_filter.erb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# :command.fixed_flag_filter
22
case "$1" in
3-
<%- if short_flag_exist? "-v" -%>
3+
% if short_flag_exist? "-v"
44
--version )
5-
<%- else -%>
5+
% else
66
--version | -v )
7-
<%- end -%>
7+
% end
88
version_command
99
exit
1010
;;
1111

12-
<%- if short_flag_exist? "-h" -%>
12+
% if short_flag_exist? "-h"
1313
--help )
14-
<%- else -%>
14+
% else
1515
--help | -h )
16-
<%- end -%>
16+
% end
1717
long_usage=yes
1818
<%= function_name %>_usage
1919
exit
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# :command.parse_requirements
2-
<%- if root_command? -%>
2+
% if root_command?
33
parse_requirements() {
4-
<%- else -%>
4+
% else
55
<%= function_name %>_parse_requirements() {
6-
<%- end -%>
6+
% end
77
<%= render(:fixed_flags_filter).indent 2 %>
88
<%= render(:environment_variables_filter).indent 2 %>
99
<%= render(:dependencies_filter).indent 2 %>
@@ -16,6 +16,6 @@ parse_requirements() {
1616
<%= render(:whitelist_filter).indent 2 %>
1717
}
1818

19-
<%- commands.each do |command| %>
19+
% commands.each do |command|
2020
<%= command.render :parse_requirements %>
21-
<%- end -%>
21+
% end

0 commit comments

Comments
 (0)