From c99b82882180734f46c85d5873c1f86a8249bc7b Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Wed, 18 Dec 2024 07:33:24 +0000 Subject: [PATCH] add `enable_env_var_names_array` setting --- lib/bashly/libraries/settings/settings.yml | 1 + .../command/environment_variables_filter.gtx | 6 ++++-- lib/bashly/views/command/inspect_args.gtx | 18 ++++++++++-------- lib/bashly/views/command/run.gtx | 4 +++- schemas/settings.json | 12 ++++++++++++ 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/lib/bashly/libraries/settings/settings.yml b/lib/bashly/libraries/settings/settings.yml index 3a5026df..57e6d61b 100644 --- a/lib/bashly/libraries/settings/settings.yml +++ b/lib/bashly/libraries/settings/settings.yml @@ -77,6 +77,7 @@ enable_bash3_bouncer: always enable_view_markers: development enable_inspect_args: development enable_deps_array: always +enable_env_var_names_array: always # Display various usage elements in color by providing the name of the color # function. The value for each property is a name of a function that is diff --git a/lib/bashly/views/command/environment_variables_filter.gtx b/lib/bashly/views/command/environment_variables_filter.gtx index f95fdf87..0689d7eb 100644 --- a/lib/bashly/views/command/environment_variables_filter.gtx +++ b/lib/bashly/views/command/environment_variables_filter.gtx @@ -2,8 +2,10 @@ if environment_variables.any? = view_marker = render(:environment_variables_default) - environment_variables.each do |env_var| - > env_var_names+=("{{ env_var.name.upcase }}") + if Settings.enabled? :env_var_names_array + environment_variables.each do |env_var| + > env_var_names+=("{{ env_var.name.upcase }}") + end end end diff --git a/lib/bashly/views/command/inspect_args.gtx b/lib/bashly/views/command/inspect_args.gtx index 34b4b4db..e9d52e99 100644 --- a/lib/bashly/views/command/inspect_args.gtx +++ b/lib/bashly/views/command/inspect_args.gtx @@ -31,13 +31,15 @@ if Settings.enabled? :deps_array > fi > end -> if ((${#env_var_names[@]})); then -> readarray -t sorted_names < <(printf '%s\n' "${env_var_names[@]}" | sort) -> echo -> echo "environment variables:" -> for k in "${sorted_names[@]}"; do -> echo "- \$$k = ${!k:-}" -> done -> fi +if Settings.enabled? :env_var_names_array + > if ((${#env_var_names[@]})); then + > readarray -t sorted_names < <(printf '%s\n' "${env_var_names[@]}" | sort) + > echo + > echo "environment variables:" + > for k in "${sorted_names[@]}"; do + > echo "- \$$k = ${!k:-}" + > done + > fi +end > } > diff --git a/lib/bashly/views/command/run.gtx b/lib/bashly/views/command/run.gtx index 423ac80d..9324c45a 100644 --- a/lib/bashly/views/command/run.gtx +++ b/lib/bashly/views/command/run.gtx @@ -6,7 +6,9 @@ if Settings.enabled? :deps_array > declare -g -A deps=() end > declare -g -a other_args=() -> declare -g -a env_var_names=() +if Settings.enabled? :env_var_names_array + > declare -g -a env_var_names=() +end > declare -g -a input=() if has_unique_args_or_flags? > declare -g -A unique_lookup=() diff --git a/schemas/settings.json b/schemas/settings.json index cc1d07eb..154d4da7 100644 --- a/schemas/settings.json +++ b/schemas/settings.json @@ -189,6 +189,18 @@ ], "default": "always" }, + "enable_env_var_names_array": { + "title": "enable_env_var_names_array", + "description": "Whether to include the code for the env_var_names array in the generated script\nhttps://bashly.dannyb.co/usage/settings/#enable_env_var_names_array", + "type": "string", + "enum": [ + "development", + "production", + "always", + "never" + ], + "default": "always" + }, "partials_extension": { "title": "partials extension", "description": "The extension to use when reading/writing partial script snippets\nhttps://bashly.dannyb.co/usage/settings/#partials_extension",