Skip to content

Commit c23d705

Browse files
committed
- Add support for tweaking production/development output
1 parent c1aa6f5 commit c23d705

File tree

16 files changed

+97
-36
lines changed

16 files changed

+97
-36
lines changed

examples/render-mandoc/docs/download.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" Automatically generated by Pandoc 3.2
22
.\"
3-
.TH "download" "1" "November 2024" "Version 0.1.0" "Sample application"
3+
.TH "download" "1" "December 2024" "Version 0.1.0" "Sample application"
44
.SH NAME
55
\f[B]download\f[R] \- Sample application
66
.SH SYNOPSIS

examples/render-mandoc/docs/download.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
% download(1) Version 0.1.0 | Sample application
22
% Lana Lang
3-
% November 2024
3+
% December 2024
44

55
NAME
66
==================================================

lib/bashly/concerns/renderable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def strings
1616
# Outputs a comment that describes the view unless in production mode
1717
def view_marker(id = nil)
1818
id ||= ":#{caller_locations(1..1).first.path}"
19-
"# #{id}" unless Settings.production?
19+
"# #{id}" if Settings.enabled? :view_markers
2020
end
2121

2222
# Reads a file from the userspace (Settings.source_dir) and returns

lib/bashly/libraries/settings/settings.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ compact_short_flags: true
4747
# respectively.
4848
conjoined_flag_args: true
4949

50-
# Set to 'production' or 'development':
51-
# env: production Generate a smaller script, without file markers
52-
# env: development Generate with file markers
53-
env: development
54-
5550
# The extension to use when reading/writing partial script snippets
5651
partials_extension: sh
5752

@@ -64,6 +59,25 @@ show_examples_on_error: false
6459
# all the private elements in the usage texts, as if they were public.
6560
private_reveal_key: ~
6661

62+
# Set to 'production' or 'development'.
63+
# Determines which features are enabled in the rendered script.
64+
# Use the `enable_*` options below to adjust settings for each environment.
65+
# It is recommended to leave this set to 'development' and run
66+
# `bashly generate --production` when the slimmer production script is needed.
67+
env: development
68+
69+
# Tweak the script output by enabling or disabling some script output.
70+
# These options accept one of the following strings:
71+
# - production render this feature only when env == production
72+
# - development render this feature only when env == development
73+
# - always render this feature in any environment
74+
# - never do not render this feature
75+
enable_header_comment: always
76+
enable_bash3_bouncer: always
77+
enable_view_markers: development
78+
enable_inspect_args: development
79+
enable_deps_array: always
80+
6781
# Display various usage elements in color by providing the name of the color
6882
# function. The value for each property is a name of a function that is
6983
# available in your script, for example: `green` or `bold`.
@@ -75,3 +89,4 @@ usage_colors:
7589
arg: ~
7690
flag: ~
7791
environment_variable: ~
92+

lib/bashly/script/dependency.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Bashly
22
module Script
3-
class Dependency
3+
class Dependency < Base
44
attr_reader :label, :commands, :help
55

66
class << self

lib/bashly/script/wrapper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def header!
4040

4141
def default_header
4242
result = render 'header'
43-
result += render('bash3_bouncer') unless function_name
43+
result += render('bash3_bouncer') unless function_name || !Settings.enabled?(:bash3_bouncer)
4444
result
4545
end
4646

lib/bashly/settings.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ class << self
88
:compact_short_flags,
99
:conjoined_flag_args,
1010
:config_path,
11+
:enable_header_comment,
12+
:enable_bash3_bouncer,
13+
:enable_view_markers,
14+
:enable_inspect_args,
15+
:enable_deps_array,
1116
:lib_dir,
1217
:partials_extension,
1318
:private_reveal_key,
@@ -35,6 +40,32 @@ def config_path
3540
@config_path ||= get(:config_path) % { source_dir: source_dir }
3641
end
3742

43+
def enabled?(feature)
44+
send(:"enable_#{feature}") == 'always' ||
45+
(send(:"enable_#{feature}") == 'production' && production?) ||
46+
(send(:"enable_#{feature}") == 'development' && !production?)
47+
end
48+
49+
def enable_header_comment
50+
@enable_header_comment ||= get :enable_header_comment
51+
end
52+
53+
def enable_bash3_bouncer
54+
@enable_bash3_bouncer ||= get :enable_bash3_bouncer
55+
end
56+
57+
def enable_view_markers
58+
@enable_view_markers ||= get :enable_view_markers
59+
end
60+
61+
def enable_inspect_args
62+
@enable_inspect_args ||= get :enable_inspect_args
63+
end
64+
65+
def enable_deps_array
66+
@enable_deps_array ||= get :enable_deps_array
67+
end
68+
3869
def env
3970
@env ||= get(:env)&.to_sym
4071
end
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
> echo "# this file is located in '{{ "#{Settings.source_dir}/#{filename}" }}'"
22
> echo "# you can edit it freely and regenerate (it will not be overwritten)"
3-
> inspect_args
3+
if Settings.enabled? :inspect_args
4+
> inspect_args
5+
end
46
>
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
> echo "# this file is located in '{{ "#{Settings.source_dir}/#{filename}" }}'"
22
> echo "# code for '{{ full_name }}' goes here"
33
> echo "# you can edit it freely and regenerate (it will not be overwritten)"
4-
> inspect_args
4+
if Settings.enabled? :inspect_args
5+
> inspect_args
6+
end
57
>

lib/bashly/views/command/dependencies_filter.gtx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@ if dependencies.any?
22
= view_marker
33

44
dependencies.each do |dependency|
5-
> if command -v {{ dependency.commands.join(' ') }} >/dev/null 2>&1; then
6-
> deps['{{ dependency.label }}']="$(command -v {{ dependency.commands.join(' ') }} | head -n1)"
7-
> else
8-
> printf "{{ strings[:missing_dependency] % { dependency: dependency.name } }}\n" >&2
9-
if dependency.help
10-
> printf "%s\n" "{{ dependency.help.sanitize_for_print }}" >&2
11-
end
12-
> exit 1
13-
> fi
14-
>
5+
= dependency.render :filter
156
end
167
end

0 commit comments

Comments
 (0)