Skip to content

Commit cf8257d

Browse files
committed
- Allow generating script without file marker comments
1 parent 563a958 commit cf8257d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+51
-42
lines changed

lib/bashly/concerns/renderable.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ module Bashly
44
module Renderable
55
def render(view)
66
template = File.read view_path(view)
7-
ERB.new(template, trim_mode: '%-').result(binding)
7+
erb = ERB.new(template, trim_mode: '%-')
8+
erb.filename = "#{views_subfolder}.#{view}"
9+
erb.result binding
810
end
911

1012
def strings
1113
@strings ||= MessageStrings.new
1214
end
1315

16+
def view_marker(id = nil)
17+
id ||= ":#{caller_locations.first.path}"
18+
"# #{id}" unless ENV['BASHLY_PRODUCTION']
19+
end
20+
1421
private
1522

1623
def view_path(view)

lib/bashly/script/command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def load_user_file(file, placeholder: true)
102102
default_content
103103
end
104104

105-
"# :#{path}\n#{content}"
105+
ENV['BASHLY_PRODUCTION'] ? content : "#{view_marker path}\n#{content}"
106106
end
107107

108108
# Returns an array of all parents. For example, the command

lib/bashly/views/argument/usage.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# :argument.usage
1+
<%= view_marker %>
22
echo " <%= label %>"
33
printf "<%= help.wrap(76).indent(4).sanitize_for_print %>\n"
44
% if allowed

lib/bashly/views/argument/validations.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# :argument.validations
1+
<%= view_marker %>
22
% if validate
33
if [[ -n $(validate_<%= validate %> "$1") ]]; then
44
printf "<%= strings[:validation_error] %>\n" "<%= name.upcase %>" "$(validate_<%= validate %> "$1")"

lib/bashly/views/command/catch_all_filter.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# :command.catch_all_filter
1+
<%= view_marker %>
22
% 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"

lib/bashly/views/command/command_fallback.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# :command.command_fallback
1+
<%= view_marker %>
22
% if default_command
33
"" )
44
<%= function_name %>_usage

lib/bashly/views/command/command_filter.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# :command.command_filter
1+
<%= view_marker %>
22
% if commands.any?
33
action=${1:-}
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# :command.command_functions
1+
<%= view_marker %>
22
% deep_commands.each do |command|
33
<%= command.render :function unless command.commands.any? %>
44
% end

lib/bashly/views/command/default_assignments.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# :command.default_assignments
1+
<%= view_marker %>
22
% default_args.each do |arg|
33
[[ -n ${args[<%= arg.name %>]:-} ]] || args[<%= arg.name %>]="<%= arg.default %>"
44
% end

lib/bashly/views/command/dependencies_filter.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# :command.dependencies_filter
1+
<%= view_marker %>
22
% if dependencies
33
% dependencies.each do |dependency|
44
if ! [[ -x "$(command -v <%= dependency %>)" ]]; then

0 commit comments

Comments
 (0)