Skip to content

Commit 16568b7

Browse files
authored
Merge pull request #577 from DannyBen/add/settings-tweaks
Add support for tweaking production/development output
2 parents c1aa6f5 + af6ce2b commit 16568b7

File tree

23 files changed

+955
-483
lines changed

23 files changed

+955
-483
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: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
# If you wish to change the path to this file, set the environment variable
1010
# BASHLY_SETTINGS_PATH.
1111

12+
13+
#-------------------------------------------------------------------------------
14+
# PATH OPTIONS
15+
#-------------------------------------------------------------------------------
16+
1217
# The path containing the bashly source files
1318
source_dir: src
1419

@@ -27,6 +32,14 @@ lib_dir: lib
2732
# directory, and each command will get its own subdirectory
2833
commands_dir: ~
2934

35+
# The extension to use when reading/writing partial script snippets
36+
partials_extension: sh
37+
38+
39+
#-------------------------------------------------------------------------------
40+
# FORMAT OPTIONS
41+
#-------------------------------------------------------------------------------
42+
3043
# Configure the bash options that will be added to the initialize function:
3144
# strict: true Bash strict mode (set -euo pipefail)
3245
# strict: false Only exit on errors (set -e)
@@ -38,6 +51,11 @@ strict: false
3851
# (every 2 leading spaces will be converted to a tab character)
3952
tab_indent: false
4053

54+
55+
#-------------------------------------------------------------------------------
56+
# INTERFACE OPTIONS
57+
#-------------------------------------------------------------------------------
58+
4159
# When true, the generated script will consider any argument in the form of
4260
# `-abc` as if it is `-a -b -c`.
4361
compact_short_flags: true
@@ -47,14 +65,6 @@ compact_short_flags: true
4765
# respectively.
4866
conjoined_flag_args: true
4967

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-
55-
# The extension to use when reading/writing partial script snippets
56-
partials_extension: sh
57-
5868
# Show command examples (if any) whenever the user does not provide the
5969
# required arguments
6070
show_examples_on_error: false
@@ -75,3 +85,28 @@ usage_colors:
7585
arg: ~
7686
flag: ~
7787
environment_variable: ~
88+
89+
90+
#-------------------------------------------------------------------------------
91+
# FEATURE TOGGLES
92+
#-------------------------------------------------------------------------------
93+
94+
# Set to 'production' or 'development'.
95+
# Determines which features are enabled in the rendered script.
96+
# Use the `enable_*` options below to adjust settings for each environment.
97+
# It is recommended to leave this set to 'development' and run
98+
# `bashly generate --production` when the slimmer production script is needed.
99+
env: development
100+
101+
# Tweak the script output by enabling or disabling some script output.
102+
# These options accept one of the following strings:
103+
# - production render this feature only when env == production
104+
# - development render this feature only when env == development
105+
# - always render this feature in any environment
106+
# - never do not render this feature
107+
enable_header_comment: always
108+
enable_bash3_bouncer: always
109+
enable_view_markers: development
110+
enable_inspect_args: development
111+
enable_deps_array: always
112+
enable_env_var_names_array: always

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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ class << self
88
:compact_short_flags,
99
:conjoined_flag_args,
1010
:config_path,
11+
:enable_bash3_bouncer,
12+
:enable_deps_array,
13+
:enable_env_var_names_array,
14+
:enable_header_comment,
15+
:enable_inspect_args,
16+
:enable_view_markers,
1117
:lib_dir,
1218
:partials_extension,
1319
:private_reveal_key,
@@ -35,6 +41,36 @@ def config_path
3541
@config_path ||= get(:config_path) % { source_dir: source_dir }
3642
end
3743

44+
def enabled?(feature)
45+
send(:"enable_#{feature}") == 'always' ||
46+
(send(:"enable_#{feature}") == 'production' && production?) ||
47+
(send(:"enable_#{feature}") == 'development' && !production?)
48+
end
49+
50+
def enable_header_comment
51+
@enable_header_comment ||= get :enable_header_comment
52+
end
53+
54+
def enable_bash3_bouncer
55+
@enable_bash3_bouncer ||= get :enable_bash3_bouncer
56+
end
57+
58+
def enable_view_markers
59+
@enable_view_markers ||= get :enable_view_markers
60+
end
61+
62+
def enable_inspect_args
63+
@enable_inspect_args ||= get :enable_inspect_args
64+
end
65+
66+
def enable_deps_array
67+
@enable_deps_array ||= get :enable_deps_array
68+
end
69+
70+
def enable_env_var_names_array
71+
@enable_env_var_names_array ||= get :enable_env_var_names_array
72+
end
73+
3874
def env
3975
@env ||= get(:env)&.to_sym
4076
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)