From c23d7053bc678a0112af32316acf6b42369c3cb8 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Wed, 18 Dec 2024 06:59:01 +0000 Subject: [PATCH 1/9] - Add support for tweaking production/development output --- examples/render-mandoc/docs/download.1 | 2 +- examples/render-mandoc/docs/download.md | 2 +- lib/bashly/concerns/renderable.rb | 2 +- lib/bashly/libraries/settings/settings.yml | 25 ++++++++++++--- lib/bashly/script/dependency.rb | 2 +- lib/bashly/script/wrapper.rb | 2 +- lib/bashly/settings.rb | 31 +++++++++++++++++++ .../views/command/default_root_script.gtx | 4 ++- lib/bashly/views/command/default_script.gtx | 4 ++- .../views/command/dependencies_filter.gtx | 11 +------ lib/bashly/views/command/inspect_args.gtx | 20 ++++++------ lib/bashly/views/command/master_script.gtx | 2 +- lib/bashly/views/command/run.gtx | 4 ++- lib/bashly/views/dependency/filter.gtx | 14 +++++++++ lib/bashly/views/wrapper/header.gtx | 6 ++-- spec/approvals/examples/render-mandoc | 2 +- 16 files changed, 97 insertions(+), 36 deletions(-) create mode 100644 lib/bashly/views/dependency/filter.gtx diff --git a/examples/render-mandoc/docs/download.1 b/examples/render-mandoc/docs/download.1 index f600827e..502b828c 100644 --- a/examples/render-mandoc/docs/download.1 +++ b/examples/render-mandoc/docs/download.1 @@ -1,6 +1,6 @@ .\" Automatically generated by Pandoc 3.2 .\" -.TH "download" "1" "November 2024" "Version 0.1.0" "Sample application" +.TH "download" "1" "December 2024" "Version 0.1.0" "Sample application" .SH NAME \f[B]download\f[R] \- Sample application .SH SYNOPSIS diff --git a/examples/render-mandoc/docs/download.md b/examples/render-mandoc/docs/download.md index 99c93073..8e93e65a 100644 --- a/examples/render-mandoc/docs/download.md +++ b/examples/render-mandoc/docs/download.md @@ -1,6 +1,6 @@ % download(1) Version 0.1.0 | Sample application % Lana Lang -% November 2024 +% December 2024 NAME ================================================== diff --git a/lib/bashly/concerns/renderable.rb b/lib/bashly/concerns/renderable.rb index 2a971ad3..3a096169 100644 --- a/lib/bashly/concerns/renderable.rb +++ b/lib/bashly/concerns/renderable.rb @@ -16,7 +16,7 @@ def strings # Outputs a comment that describes the view unless in production mode def view_marker(id = nil) id ||= ":#{caller_locations(1..1).first.path}" - "# #{id}" unless Settings.production? + "# #{id}" if Settings.enabled? :view_markers end # Reads a file from the userspace (Settings.source_dir) and returns diff --git a/lib/bashly/libraries/settings/settings.yml b/lib/bashly/libraries/settings/settings.yml index 84e517ab..3a5026df 100644 --- a/lib/bashly/libraries/settings/settings.yml +++ b/lib/bashly/libraries/settings/settings.yml @@ -47,11 +47,6 @@ compact_short_flags: true # respectively. conjoined_flag_args: true -# Set to 'production' or 'development': -# env: production Generate a smaller script, without file markers -# env: development Generate with file markers -env: development - # The extension to use when reading/writing partial script snippets partials_extension: sh @@ -64,6 +59,25 @@ show_examples_on_error: false # all the private elements in the usage texts, as if they were public. private_reveal_key: ~ +# Set to 'production' or 'development'. +# Determines which features are enabled in the rendered script. +# Use the `enable_*` options below to adjust settings for each environment. +# It is recommended to leave this set to 'development' and run +# `bashly generate --production` when the slimmer production script is needed. +env: development + +# Tweak the script output by enabling or disabling some script output. +# These options accept one of the following strings: +# - production render this feature only when env == production +# - development render this feature only when env == development +# - always render this feature in any environment +# - never do not render this feature +enable_header_comment: always +enable_bash3_bouncer: always +enable_view_markers: development +enable_inspect_args: development +enable_deps_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 # available in your script, for example: `green` or `bold`. @@ -75,3 +89,4 @@ usage_colors: arg: ~ flag: ~ environment_variable: ~ + diff --git a/lib/bashly/script/dependency.rb b/lib/bashly/script/dependency.rb index 43a53338..7c048d44 100644 --- a/lib/bashly/script/dependency.rb +++ b/lib/bashly/script/dependency.rb @@ -1,6 +1,6 @@ module Bashly module Script - class Dependency + class Dependency < Base attr_reader :label, :commands, :help class << self diff --git a/lib/bashly/script/wrapper.rb b/lib/bashly/script/wrapper.rb index 58ff41f1..dd59e198 100644 --- a/lib/bashly/script/wrapper.rb +++ b/lib/bashly/script/wrapper.rb @@ -40,7 +40,7 @@ def header! def default_header result = render 'header' - result += render('bash3_bouncer') unless function_name + result += render('bash3_bouncer') unless function_name || !Settings.enabled?(:bash3_bouncer) result end diff --git a/lib/bashly/settings.rb b/lib/bashly/settings.rb index 6fb73b4b..c22cac7c 100644 --- a/lib/bashly/settings.rb +++ b/lib/bashly/settings.rb @@ -8,6 +8,11 @@ class << self :compact_short_flags, :conjoined_flag_args, :config_path, + :enable_header_comment, + :enable_bash3_bouncer, + :enable_view_markers, + :enable_inspect_args, + :enable_deps_array, :lib_dir, :partials_extension, :private_reveal_key, @@ -35,6 +40,32 @@ def config_path @config_path ||= get(:config_path) % { source_dir: source_dir } end + def enabled?(feature) + send(:"enable_#{feature}") == 'always' || + (send(:"enable_#{feature}") == 'production' && production?) || + (send(:"enable_#{feature}") == 'development' && !production?) + end + + def enable_header_comment + @enable_header_comment ||= get :enable_header_comment + end + + def enable_bash3_bouncer + @enable_bash3_bouncer ||= get :enable_bash3_bouncer + end + + def enable_view_markers + @enable_view_markers ||= get :enable_view_markers + end + + def enable_inspect_args + @enable_inspect_args ||= get :enable_inspect_args + end + + def enable_deps_array + @enable_deps_array ||= get :enable_deps_array + end + def env @env ||= get(:env)&.to_sym end diff --git a/lib/bashly/views/command/default_root_script.gtx b/lib/bashly/views/command/default_root_script.gtx index 56ce3f80..1edef2e1 100644 --- a/lib/bashly/views/command/default_root_script.gtx +++ b/lib/bashly/views/command/default_root_script.gtx @@ -1,4 +1,6 @@ > echo "# this file is located in '{{ "#{Settings.source_dir}/#{filename}" }}'" > echo "# you can edit it freely and regenerate (it will not be overwritten)" -> inspect_args +if Settings.enabled? :inspect_args + > inspect_args +end > diff --git a/lib/bashly/views/command/default_script.gtx b/lib/bashly/views/command/default_script.gtx index 0828c187..1ec5c4f1 100644 --- a/lib/bashly/views/command/default_script.gtx +++ b/lib/bashly/views/command/default_script.gtx @@ -1,5 +1,7 @@ > echo "# this file is located in '{{ "#{Settings.source_dir}/#{filename}" }}'" > echo "# code for '{{ full_name }}' goes here" > echo "# you can edit it freely and regenerate (it will not be overwritten)" -> inspect_args +if Settings.enabled? :inspect_args + > inspect_args +end > diff --git a/lib/bashly/views/command/dependencies_filter.gtx b/lib/bashly/views/command/dependencies_filter.gtx index f8d5c670..279c4f02 100644 --- a/lib/bashly/views/command/dependencies_filter.gtx +++ b/lib/bashly/views/command/dependencies_filter.gtx @@ -2,15 +2,6 @@ if dependencies.any? = view_marker dependencies.each do |dependency| - > if command -v {{ dependency.commands.join(' ') }} >/dev/null 2>&1; then - > deps['{{ dependency.label }}']="$(command -v {{ dependency.commands.join(' ') }} | head -n1)" - > else - > printf "{{ strings[:missing_dependency] % { dependency: dependency.name } }}\n" >&2 - if dependency.help - > printf "%s\n" "{{ dependency.help.sanitize_for_print }}" >&2 - end - > exit 1 - > fi - > + = dependency.render :filter end end diff --git a/lib/bashly/views/command/inspect_args.gtx b/lib/bashly/views/command/inspect_args.gtx index 3b788705..34b4b4db 100644 --- a/lib/bashly/views/command/inspect_args.gtx +++ b/lib/bashly/views/command/inspect_args.gtx @@ -20,15 +20,17 @@ > done > fi > -> if ((${#deps[@]})); then -> readarray -t sorted_keys < <(printf '%s\n' "${!deps[@]}" | sort) -> echo -> echo deps: -> for k in "${sorted_keys[@]}"; do -> echo "- \${deps[$k]} = ${deps[$k]}" -> done -> fi -> +if Settings.enabled? :deps_array + > if ((${#deps[@]})); then + > readarray -t sorted_keys < <(printf '%s\n' "${!deps[@]}" | sort) + > echo + > echo deps: + > for k in "${sorted_keys[@]}"; do + > echo "- \${deps[$k]} = ${deps[$k]}" + > done + > fi + > +end > if ((${#env_var_names[@]})); then > readarray -t sorted_names < <(printf '%s\n' "${env_var_names[@]}" | sort) > echo diff --git a/lib/bashly/views/command/master_script.gtx b/lib/bashly/views/command/master_script.gtx index f3fc6b52..09b894d5 100644 --- a/lib/bashly/views/command/master_script.gtx +++ b/lib/bashly/views/command/master_script.gtx @@ -4,7 +4,7 @@ = render :version_command = render :usage = render :normalize_input -= render :inspect_args unless Settings.production? += render :inspect_args if Settings.enabled? :inspect_args = render :user_lib if user_lib.any? = render :command_functions = render :parse_requirements diff --git a/lib/bashly/views/command/run.gtx b/lib/bashly/views/command/run.gtx index 6afedb5f..423ac80d 100644 --- a/lib/bashly/views/command/run.gtx +++ b/lib/bashly/views/command/run.gtx @@ -2,7 +2,9 @@ > run() { > declare -g -A args=() -> declare -g -A deps=() +if Settings.enabled? :deps_array + > declare -g -A deps=() +end > declare -g -a other_args=() > declare -g -a env_var_names=() > declare -g -a input=() diff --git a/lib/bashly/views/dependency/filter.gtx b/lib/bashly/views/dependency/filter.gtx new file mode 100644 index 00000000..7aa46e7b --- /dev/null +++ b/lib/bashly/views/dependency/filter.gtx @@ -0,0 +1,14 @@ += view_marker + +> if ! command -v {{ commands.join(' ') }} >/dev/null 2>&1; then +> printf "{{ strings[:missing_dependency] % { dependency: name } }}\n" >&2 +if help + > printf "%s\n" "{{ help.sanitize_for_print }}" >&2 +end +> exit 1 +if Settings.enabled? :deps_array + > else + > deps['{{ label }}']="$(command -v {{ commands.join(' ') }} | head -n1)" +end +> fi +> \ No newline at end of file diff --git a/lib/bashly/views/wrapper/header.gtx b/lib/bashly/views/wrapper/header.gtx index 2dd10f68..787275ab 100644 --- a/lib/bashly/views/wrapper/header.gtx +++ b/lib/bashly/views/wrapper/header.gtx @@ -1,5 +1,7 @@ > #!/usr/bin/env bash -> # This script was generated by bashly {{ Bashly::VERSION }} (https://bashly.dannyb.co) -> # Modifying it manually is not recommended +if Settings.enabled? :header_comment + > # This script was generated by bashly {{ Bashly::VERSION }} (https://bashly.dannyb.co) + > # Modifying it manually is not recommended +end > > diff --git a/spec/approvals/examples/render-mandoc b/spec/approvals/examples/render-mandoc index 5c3d0ca3..49a8c85b 100644 --- a/spec/approvals/examples/render-mandoc +++ b/spec/approvals/examples/render-mandoc @@ -44,4 +44,4 @@ ISSUE TRACKER AUTHORS Lana Lang. -Version 0.1.0 November 2024 download(1) +Version 0.1.0 December 2024 download(1) From 109600213cce1ea3bbefe3f9f4efd7d4c958b6a2 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Wed, 18 Dec 2024 07:10:34 +0000 Subject: [PATCH 2/9] update settings.json schema --- lib/bashly/settings.rb | 6 ++--- schemas/settings.json | 60 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/lib/bashly/settings.rb b/lib/bashly/settings.rb index c22cac7c..b36c69bf 100644 --- a/lib/bashly/settings.rb +++ b/lib/bashly/settings.rb @@ -8,11 +8,11 @@ class << self :compact_short_flags, :conjoined_flag_args, :config_path, - :enable_header_comment, :enable_bash3_bouncer, - :enable_view_markers, - :enable_inspect_args, :enable_deps_array, + :enable_header_comment, + :enable_inspect_args, + :enable_view_markers, :lib_dir, :partials_extension, :private_reveal_key, diff --git a/schemas/settings.json b/schemas/settings.json index d91d732f..cc1d07eb 100644 --- a/schemas/settings.json +++ b/schemas/settings.json @@ -129,6 +129,66 @@ ], "default": "development" }, + "enable_header_comment": { + "title": "enable_header_comment", + "description": "Whether to include the header comment in the generated script\nhttps://bashly.dannyb.co/usage/settings/#enable_header_comment", + "type": "string", + "enum": [ + "development", + "production", + "always", + "never" + ], + "default": "always" + }, + "enable_bash3_bouncer": { + "title": "enable_bash3_bouncer", + "description": "Whether to include the code snippet that aborts when an old version of bash is detected in the generated script\nhttps://bashly.dannyb.co/usage/settings/#enable_bash3_bouncer", + "type": "string", + "enum": [ + "development", + "production", + "always", + "never" + ], + "default": "always" + }, + "enable_view_markers": { + "title": "enable_view_markers", + "description": "Whether to include view marker comments in the generated script\nhttps://bashly.dannyb.co/usage/settings/#enable_view_markers", + "type": "string", + "enum": [ + "development", + "production", + "always", + "never" + ], + "default": "development" + }, + "enable_inspect_args": { + "title": "enable_inspect_args", + "description": "Whether to include the inspect_args function in the generated script\nhttps://bashly.dannyb.co/usage/settings/#enable_inspect_args", + "type": "string", + "enum": [ + "development", + "production", + "always", + "never" + ], + "default": "development" + }, + "enable_deps_array": { + "title": "enable_deps_array", + "description": "Whether to include the code for the dependencies array in the generated script\nhttps://bashly.dannyb.co/usage/settings/#enable_deps_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", From c99b82882180734f46c85d5873c1f86a8249bc7b Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Wed, 18 Dec 2024 07:33:24 +0000 Subject: [PATCH 3/9] 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", From d922dbcae60559d7a8165f94a71084fea56162f3 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Wed, 18 Dec 2024 07:48:33 +0000 Subject: [PATCH 4/9] fix settings --- lib/bashly/settings.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/bashly/settings.rb b/lib/bashly/settings.rb index b36c69bf..1a3bc0cd 100644 --- a/lib/bashly/settings.rb +++ b/lib/bashly/settings.rb @@ -10,6 +10,7 @@ class << self :config_path, :enable_bash3_bouncer, :enable_deps_array, + :enable_env_var_names_array, :enable_header_comment, :enable_inspect_args, :enable_view_markers, @@ -66,6 +67,10 @@ def enable_deps_array @enable_deps_array ||= get :enable_deps_array end + def enable_env_var_names_array + @enable_env_var_names_array ||= get :enable_env_var_names_array + end + def env @env ||= get(:env)&.to_sym end From 632226be54e1e0e0247b8ae3663312afca4613c8 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Wed, 18 Dec 2024 08:21:24 +0000 Subject: [PATCH 5/9] add specs for Settings.enabled? --- spec/bashly/settings_spec.rb | 68 +++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/spec/bashly/settings_spec.rb b/spec/bashly/settings_spec.rb index 1cf3935e..07a513cb 100644 --- a/spec/bashly/settings_spec.rb +++ b/spec/bashly/settings_spec.rb @@ -97,7 +97,73 @@ end end - describe 'strict_string' do + describe '::enabled?' do + context 'when the value is always' do + before { subject.enable_header_comment = 'always' } + + it 'returns true' do + expect(subject.enabled? :header_comment).to be true + end + end + + context 'when the value is never' do + before { subject.enable_header_comment = 'never' } + + it 'returns false' do + expect(subject.enabled? :header_comment).to be false + end + end + + context 'when the value is production in a production env' do + before do + subject.enable_header_comment = 'production' + subject.env = :production + end + + it 'returns true' do + expect(subject.enabled? :header_comment).to be true + end + end + + context 'when the value is production in a development env' do + before do + subject.enable_header_comment = 'production' + subject.env = :development + end + + after { subject.env = nil } + + it 'returns false' do + expect(subject.enabled? :header_comment).to be false + end + end + + context 'when the value is development in a production env' do + before do + subject.enable_header_comment = 'development' + subject.env = :production + end + + it 'returns false' do + expect(subject.enabled? :header_comment).to be false + end + end + + context 'when the value is development in a development env' do + before do + subject.enable_header_comment = 'development' + subject.env = :development + end + + after { subject.env = nil } + + it 'returns true' do + expect(subject.enabled? :header_comment).to be true + end + end + end + + describe '::strict_string' do context 'when strict is true' do before { subject.strict = true } From de8731edee2a7844de4772262718bcafb4c6c12a Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Wed, 18 Dec 2024 08:23:43 +0000 Subject: [PATCH 6/9] specs cleanup --- spec/bashly/settings_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/bashly/settings_spec.rb b/spec/bashly/settings_spec.rb index 07a513cb..efa4f743 100644 --- a/spec/bashly/settings_spec.rb +++ b/spec/bashly/settings_spec.rb @@ -120,6 +120,8 @@ subject.env = :production end + after { subject.env = nil } + it 'returns true' do expect(subject.enabled? :header_comment).to be true end @@ -144,6 +146,8 @@ subject.env = :production end + after { subject.env = nil } + it 'returns false' do expect(subject.enabled? :header_comment).to be false end From 8c63fcc16d4977cb7406b3c8161bcfaec0c3f092 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Wed, 18 Dec 2024 09:38:37 +0000 Subject: [PATCH 7/9] organize settings into subtopics --- lib/bashly/libraries/settings/settings.yml | 51 +++++++++++++++------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/lib/bashly/libraries/settings/settings.yml b/lib/bashly/libraries/settings/settings.yml index 57e6d61b..797b87c5 100644 --- a/lib/bashly/libraries/settings/settings.yml +++ b/lib/bashly/libraries/settings/settings.yml @@ -9,6 +9,11 @@ # If you wish to change the path to this file, set the environment variable # BASHLY_SETTINGS_PATH. + +#------------------------------------------------------------------------------- +# PATH OPTIONS +#------------------------------------------------------------------------------- + # The path containing the bashly source files source_dir: src @@ -27,6 +32,14 @@ lib_dir: lib # directory, and each command will get its own subdirectory commands_dir: ~ +# The extension to use when reading/writing partial script snippets +partials_extension: sh + + +#------------------------------------------------------------------------------- +# FORMAT OPTIONS +#------------------------------------------------------------------------------- + # Configure the bash options that will be added to the initialize function: # strict: true Bash strict mode (set -euo pipefail) # strict: false Only exit on errors (set -e) @@ -38,6 +51,11 @@ strict: false # (every 2 leading spaces will be converted to a tab character) tab_indent: false + +#------------------------------------------------------------------------------- +# INTERFACE OPTIONS +#------------------------------------------------------------------------------- + # When true, the generated script will consider any argument in the form of # `-abc` as if it is `-a -b -c`. compact_short_flags: true @@ -47,9 +65,6 @@ compact_short_flags: true # respectively. conjoined_flag_args: true -# The extension to use when reading/writing partial script snippets -partials_extension: sh - # Show command examples (if any) whenever the user does not provide the # required arguments show_examples_on_error: false @@ -59,6 +74,23 @@ show_examples_on_error: false # all the private elements in the usage texts, as if they were public. private_reveal_key: ~ +# 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 +# available in your script, for example: `green` or `bold`. +# You can run `bashly add colors` to add a standard colors library. +# This option cannot be set via environment variables. +usage_colors: + caption: ~ + command: ~ + arg: ~ + flag: ~ + environment_variable: ~ + + +#------------------------------------------------------------------------------- +# FEATURE TOGGLES +#------------------------------------------------------------------------------- + # Set to 'production' or 'development'. # Determines which features are enabled in the rendered script. # Use the `enable_*` options below to adjust settings for each environment. @@ -78,16 +110,3 @@ 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 -# available in your script, for example: `green` or `bold`. -# You can run `bashly add colors` to add a standard colors library. -# This option cannot be set via environment variables. -usage_colors: - caption: ~ - command: ~ - arg: ~ - flag: ~ - environment_variable: ~ - From 1b631b1e2829a47ce413ab8050dfad1646d83892 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Wed, 18 Dec 2024 19:09:00 +0000 Subject: [PATCH 8/9] generate settings.json schema using YAML source --- schemas/settings.json | 496 ++++++++++++++++---------------- schemas/strings.json | 506 ++++++++++++++++----------------- support/runfile/schema.runfile | 5 + support/schema/README.md | 6 +- support/schema/settings.yml | 231 +++++++++++++++ 5 files changed, 741 insertions(+), 503 deletions(-) create mode 100644 support/schema/settings.yml diff --git a/schemas/settings.json b/schemas/settings.json index 154d4da7..b78c9c92 100644 --- a/schemas/settings.json +++ b/schemas/settings.json @@ -1,259 +1,259 @@ { - "$schema": "https://json.schemastore.org/metaschema-draft-07-unofficial-strict.json", - "definitions": { - "color": { - "oneOf": [ - { - "type": "string", - "examples": [ - "red", - "green", - "yellow", - "blue", - "magenta", - "cyan", - "bold", - "underlined", - "red_bold", - "green_bold", - "yellow_bold", - "blue_bold", - "magenta_bold", - "cyan_bold", - "red_underlined", - "green_underlined", - "yellow_underlined", - "blue_underlined", - "magenta_underlined", - "cyan_underlined" - ] - }, - { - "type": "null" - } - ] + "$schema": "https://json.schemastore.org/metaschema-draft-07-unofficial-strict.json", + "definitions": { + "color": { + "oneOf": [ + { + "type": "string", + "examples": [ + "red", + "green", + "yellow", + "blue", + "magenta", + "cyan", + "bold", + "underlined", + "red_bold", + "green_bold", + "yellow_bold", + "blue_bold", + "magenta_bold", + "cyan_bold", + "red_underlined", + "green_underlined", + "yellow_underlined", + "blue_underlined", + "magenta_underlined", + "cyan_underlined" + ] + }, + { + "type": "null" } + ] + } + }, + "title": "settings", + "description": "Settings of the current application\nhttps://bashly.dannyb.co/usage/settings/#settings", + "type": "object", + "properties": { + "source_dir": { + "title": "source dir", + "description": "The path containing the bashly source files\nhttps://bashly.dannyb.co/usage/settings/#source_dir", + "type": "string", + "minLength": 1, + "default": "src" }, - "title": "settings", - "description": "Settings of the current application\nhttps://bashly.dannyb.co/usage/settings/#settings", - "type": "object", - "properties": { - "source_dir": { - "title": "source dir", - "description": "The path containing the bashly source files\nhttps://bashly.dannyb.co/usage/settings/#source_dir", - "type": "string", - "minLength": 1, - "default": "src" - }, - "config_path": { - "title": "config path", - "description": "The path to bashly.yml\nhttps://bashly.dannyb.co/usage/settings/#config_path", - "type": "string", - "minLength": 1, - "default": "%{source_dir}/bashly.yml" - }, - "target_dir": { - "title": "target dir", - "description": "The path to use for creating the bash script\nhttps://bashly.dannyb.co/usage/settings/#target_dir", - "type": "string", - "minLength": 1, - "default": "." - }, - "lib_dir": { - "title": "lib dir", - "description": "The path to use for common library files, relative to source_dir\nhttps://bashly.dannyb.co/usage/settings/#lib_dir", - "type": "string", - "minLength": 1, - "default": "lib" - }, - "commands_dir": { - "title": "commands dir", - "description": "The path to use for command files, relative to source_dir\nhttps://bashly.dannyb.co/usage/settings/#commands_dir", - "oneOf": [ - { - "type": "string", - "minLength": 1 - }, - { - "type": "null" - } - ] - }, - "strict": { - "title": "strict", - "description": "Configure the bash options that will be added to the initialize function\nhttps://bashly.dannyb.co/usage/settings/#strict", - "oneOf": [ - { - "type": "boolean" - }, - { - "type": "string", - "examples": [ - "set -o pipefail" - ] - } - ], - "default": false - }, - "tab_indent": { - "title": "tab indent", - "description": "Whether to use tabs or spaces in the generated script\nhttps://bashly.dannyb.co/usage/settings/#tab_indent", - "type": "boolean", - "default": false - }, - "compact_short_flags": { - "title": "compact short flags", - "description": "Whether to expand -abc to -a -b -c in the input line\nhttps://bashly.dannyb.co/usage/settings/#compact_short_flags", - "type": "boolean", - "default": true - }, - "conjoined_flag_args": { - "title": "conjoined flag args", - "description": "Whether to expand --flag=value to --flag value in the input line\nhttps://bashly.dannyb.co/usage/settings/#conjoined_flag_args", - "type": "boolean", - "default": true - }, - "show_examples_on_error": { - "title": "show examples on error", - "description": "Whether to show command examples when the input line is missing required arguments\nhttps://bashly.dannyb.co/usage/settings/#show_examples_on_error", - "type": "boolean", - "default": true - }, - "env": { - "title": "env", - "description": "Whether to include development related comments in the generated script\nhttps://bashly.dannyb.co/usage/settings/#env", - "type": "string", - "enum": [ - "development", - "production" - ], - "default": "development" - }, - "enable_header_comment": { - "title": "enable_header_comment", - "description": "Whether to include the header comment in the generated script\nhttps://bashly.dannyb.co/usage/settings/#enable_header_comment", - "type": "string", - "enum": [ - "development", - "production", - "always", - "never" - ], - "default": "always" - }, - "enable_bash3_bouncer": { - "title": "enable_bash3_bouncer", - "description": "Whether to include the code snippet that aborts when an old version of bash is detected in the generated script\nhttps://bashly.dannyb.co/usage/settings/#enable_bash3_bouncer", - "type": "string", - "enum": [ - "development", - "production", - "always", - "never" - ], - "default": "always" + "config_path": { + "title": "config path", + "description": "The path to bashly.yml\nhttps://bashly.dannyb.co/usage/settings/#config_path", + "type": "string", + "minLength": 1, + "default": "%{source_dir}/bashly.yml" + }, + "target_dir": { + "title": "target dir", + "description": "The path to use for creating the bash script\nhttps://bashly.dannyb.co/usage/settings/#target_dir", + "type": "string", + "minLength": 1, + "default": "." + }, + "lib_dir": { + "title": "lib dir", + "description": "The path to use for common library files, relative to source_dir\nhttps://bashly.dannyb.co/usage/settings/#lib_dir", + "type": "string", + "minLength": 1, + "default": "lib" + }, + "commands_dir": { + "title": "commands dir", + "description": "The path to use for command files, relative to source_dir\nhttps://bashly.dannyb.co/usage/settings/#commands_dir", + "oneOf": [ + { + "type": "string", + "minLength": 1 }, - "enable_view_markers": { - "title": "enable_view_markers", - "description": "Whether to include view marker comments in the generated script\nhttps://bashly.dannyb.co/usage/settings/#enable_view_markers", - "type": "string", - "enum": [ - "development", - "production", - "always", - "never" - ], - "default": "development" + { + "type": "null" + } + ] + }, + "strict": { + "title": "strict", + "description": "Configure the bash options that will be added to the initialize function\nhttps://bashly.dannyb.co/usage/settings/#strict", + "oneOf": [ + { + "type": "boolean" }, - "enable_inspect_args": { - "title": "enable_inspect_args", - "description": "Whether to include the inspect_args function in the generated script\nhttps://bashly.dannyb.co/usage/settings/#enable_inspect_args", - "type": "string", - "enum": [ - "development", - "production", - "always", - "never" - ], - "default": "development" + { + "type": "string", + "examples": [ + "set -o pipefail" + ] + } + ], + "default": false + }, + "tab_indent": { + "title": "tab indent", + "description": "Whether to use tabs or spaces in the generated script\nhttps://bashly.dannyb.co/usage/settings/#tab_indent", + "type": "boolean", + "default": false + }, + "compact_short_flags": { + "title": "compact short flags", + "description": "Whether to expand -abc to -a -b -c in the input line\nhttps://bashly.dannyb.co/usage/settings/#compact_short_flags", + "type": "boolean", + "default": true + }, + "conjoined_flag_args": { + "title": "conjoined flag args", + "description": "Whether to expand --flag=value to --flag value in the input line\nhttps://bashly.dannyb.co/usage/settings/#conjoined_flag_args", + "type": "boolean", + "default": true + }, + "show_examples_on_error": { + "title": "show examples on error", + "description": "Whether to show command examples when the input line is missing required arguments\nhttps://bashly.dannyb.co/usage/settings/#show_examples_on_error", + "type": "boolean", + "default": true + }, + "env": { + "title": "env", + "description": "Whether to include development related comments in the generated script\nhttps://bashly.dannyb.co/usage/settings/#env", + "type": "string", + "enum": [ + "development", + "production" + ], + "default": "development" + }, + "enable_header_comment": { + "title": "enable_header_comment", + "description": "Whether to include the header comment in the generated script\nhttps://bashly.dannyb.co/usage/settings/#enable_header_comment", + "type": "string", + "enum": [ + "development", + "production", + "always", + "never" + ], + "default": "always" + }, + "enable_bash3_bouncer": { + "title": "enable_bash3_bouncer", + "description": "Whether to include the code snippet that aborts when an old version of bash is detected in the generated script\nhttps://bashly.dannyb.co/usage/settings/#enable_bash3_bouncer", + "type": "string", + "enum": [ + "development", + "production", + "always", + "never" + ], + "default": "always" + }, + "enable_view_markers": { + "title": "enable_view_markers", + "description": "Whether to include view marker comments in the generated script\nhttps://bashly.dannyb.co/usage/settings/#enable_view_markers", + "type": "string", + "enum": [ + "development", + "production", + "always", + "never" + ], + "default": "development" + }, + "enable_inspect_args": { + "title": "enable_inspect_args", + "description": "Whether to include the inspect_args function in the generated script\nhttps://bashly.dannyb.co/usage/settings/#enable_inspect_args", + "type": "string", + "enum": [ + "development", + "production", + "always", + "never" + ], + "default": "development" + }, + "enable_deps_array": { + "title": "enable_deps_array", + "description": "Whether to include the code for the dependencies array in the generated script\nhttps://bashly.dannyb.co/usage/settings/#enable_deps_array", + "type": "string", + "enum": [ + "development", + "production", + "always", + "never" + ], + "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", + "type": "string", + "minLength": 1, + "default": "sh" + }, + "private_reveal_key": { + "title": "private reveal key", + "description": "The name of the environment variable (case sensitive) that, if set, will reveal private commands, flags and environment variables\nhttps://bashly.dannyb.co/usage/settings/#private_reveal_key", + "oneOf": [ + { + "type": "string", + "minLength": 1 }, - "enable_deps_array": { - "title": "enable_deps_array", - "description": "Whether to include the code for the dependencies array in the generated script\nhttps://bashly.dannyb.co/usage/settings/#enable_deps_array", - "type": "string", - "enum": [ - "development", - "production", - "always", - "never" - ], - "default": "always" + { + "type": "null" + } + ] + }, + "usage_colors": { + "title": "usage colors", + "description": "Enable and configure colorful output for --help\nhttps://bashly.dannyb.co/usage/settings/#usage_colors", + "type": "object", + "properties": { + "caption": { + "title": "caption", + "description": "Color for captions\nhttps://bashly.dannyb.co/usage/settings/#usage_colors", + "$ref": "#/definitions/color" }, - "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" + "command": { + "title": "command", + "description": "Color for commands\nhttps://bashly.dannyb.co/usage/settings/#usage_colors", + "$ref": "#/definitions/color" }, - "partials_extension": { - "title": "partials extension", - "description": "The extension to use when reading/writing partial script snippets\nhttps://bashly.dannyb.co/usage/settings/#partials_extension", - "type": "string", - "minLength": 1, - "default": "sh" + "arg": { + "title": "arg", + "description": "Color for positional arguments\nhttps://bashly.dannyb.co/usage/settings/#usage_colors", + "$ref": "#/definitions/color" }, - "private_reveal_key": { - "title": "private reveal key", - "description": "The name of the environment variable (case sensitive) that, if set, will reveal private commands, flags and environment variables\nhttps://bashly.dannyb.co/usage/settings/#private_reveal_key", - "oneOf": [ - { - "type": "string", - "minLength": 1 - }, - { - "type": "null" - } - ] + "flag": { + "title": "flag", + "description": "Color for flags\nhttps://bashly.dannyb.co/usage/settings/#usage_colors", + "$ref": "#/definitions/color" }, - "usage_colors": { - "title": "usage colors", - "description": "Enable and configure colorful output for --help\nhttps://bashly.dannyb.co/usage/settings/#usage_colors", - "type": "object", - "properties": { - "caption": { - "title": "caption", - "description": "Color for captions\nhttps://bashly.dannyb.co/usage/settings/#usage_colors", - "$ref": "#/definitions/color" - }, - "command": { - "title": "command", - "description": "Color for commands\nhttps://bashly.dannyb.co/usage/settings/#usage_colors", - "$ref": "#/definitions/color" - }, - "arg": { - "title": "arg", - "description": "Color for positional arguments\nhttps://bashly.dannyb.co/usage/settings/#usage_colors", - "$ref": "#/definitions/color" - }, - "flag": { - "title": "flag", - "description": "Color for flags\nhttps://bashly.dannyb.co/usage/settings/#usage_colors", - "$ref": "#/definitions/color" - }, - "environment_variable": { - "title": "environment variable", - "description": "Color for env environment variables\nhttps://bashly.dannyb.co/usage/settings/#usage_colors", - "$ref": "#/definitions/color" - } - }, - "additionalProperties": false + "environment_variable": { + "title": "environment variable", + "description": "Color for env environment variables\nhttps://bashly.dannyb.co/usage/settings/#usage_colors", + "$ref": "#/definitions/color" } - }, - "additionalProperties": false -} \ No newline at end of file + }, + "additionalProperties": false + } + }, + "additionalProperties": false +} diff --git a/schemas/strings.json b/schemas/strings.json index 60a864b9..3b740aa2 100644 --- a/schemas/strings.json +++ b/schemas/strings.json @@ -1,254 +1,254 @@ { - "$schema": "https://json.schemastore.org/metaschema-draft-07-unofficial-strict.json", - "title": "strings", - "description": "Strings of the generated script\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "object", - "properties": { - "usage": { - "title": "usage", - "description": "The caption for the usage patterns\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "Usage:" - }, - "options": { - "title": "options", - "description": "The caption for the options section\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "Options:" - }, - "global_options": { - "title": "global_options", - "description": "The caption for the options section, when a command has flags and sub-commands\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "Options:" - }, - "arguments": { - "title": "arguments", - "description": "The caption for the argument section\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "Arguments:" - }, - "commands": { - "title": "commands", - "description": "The caption for the command section\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "Commands:" - }, - "examples": { - "title": "examples", - "description": "The caption for the examples section\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "Examples:" - }, - "environment_variables": { - "title": "environment variables", - "description": "The caption for the environment variables section\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "Environment Variables:" - }, - "group": { - "title": "group", - "description": "The caption template for custom command groups\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "%{group} Commands:" - }, - "command_alias": { - "title": "command alias", - "description": "The string template for a command alias\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "Alias: %{alias}" - }, - "default_command_summary": { - "title": "default command summary", - "description": "The string template for the summary of a default command\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "%{summary} (default)" - }, - "required": { - "title": "required", - "description": "The string suffix for required arguments, flags, or commands\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "(required)" - }, - "repeatable": { - "title": "repeatable", - "description": "The string suffix for repeatable arguments, flags, or commands\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "(repeatable)" - }, - "default": { - "title": "default", - "description": "The string template for a default argument or flag\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "Default: %{value}" - }, - "allowed": { - "title": "allowed", - "description": "The string template for the list of allowed values\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "Allowed: %{values}" - }, - "needs": { - "title": "needs", - "description": "The string template for the list of needed flags\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "Needs: %{values}" - }, - "conflicts": { - "title": "conflicts", - "description": "The string template for the list of conflicting flags\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "Conflicts: %{values}" - }, - "help_flag_text": { - "title": "help flag text", - "description": "The help message for --help\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "Show this help" - }, - "version_flag_text": { - "title": "version flag text", - "description": "The help message for --version\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "Show version number" - }, - "flag_requires_an_argument": { - "title": "flag requires an argument", - "description": "The error message template for missing flag argument\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "%{name} requires an argument: %{usage}" - }, - "flag_needs_another": { - "title": "flag needs another flag", - "description": "The error message template for missing flag needs\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "%{name} needs %{need}" - }, - "invalid_argument": { - "title": "invalid argument", - "description": "The error message template for invalid argument\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "invalid argument: %s" - }, - "invalid_flag": { - "title": "invalid flag", - "description": "The error message template for invalid flag\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "invalid option: %s" - }, - "invalid_command": { - "title": "invalid command", - "description": "The error message template for invalid command\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "invalid command: %s" - }, - "conflicting_flags": { - "title": "conflicting flags", - "description": "The error message template for conflicting flags\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "conflicting options: %s cannot be used with %s" - }, - "missing_required_argument": { - "title": "missing required argument", - "description": "The error message template for missing required argument\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "missing required argument: %{arg}\\nusage: %{usage}" - }, - "missing_required_flag": { - "title": "missing required flag", - "description": "The error message template for missing required flag\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "missing required flag: %{usage}" - }, - "missing_required_environment_variable": { - "title": "missing required environment variable", - "description": "The error message template for missing required environment variable\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "missing required environment variable: %{var}" - }, - "missing_dependency": { - "title": "missing dependency", - "description": "The error message template for missing dependency\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "missing dependency: %{dependency}" - }, - "examples_caption_on_error": { - "title": "examples caption on error", - "description": "The string to show before the examples when show_examples_on_error is enabled\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "examples:" - }, - "disallowed_flag": { - "title": "disallowed flag", - "description": "The error message template for forbidden flag\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "%{name} must be one of: %{allowed}" - }, - "disallowed_argument": { - "title": "disallowed argument", - "description": "The error message template for forbidden argument\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "%{name} must be one of: %{allowed}" - }, - "disallowed_environment_variable": { - "title": "disallowed_environment_variable", - "description": "The error message template for forbidden environment variable\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "%{name} environment variable must be one of: %{allowed}" - }, - "unsupported_bash_version": { - "title": "unsupported bash version", - "description": "The error message for unsupported Bash version\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "bash version 4 or higher is required" - }, - "validation_error": { - "title": "validation error", - "description": "The error message template for failed custom validation\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "validation error in %s:\\n%s" - }, - "environment_variable_validation_error": { - "title": "environment variable validation error", - "description": "The error message template for failed custom validation for environment variables\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", - "type": "string", - "minLength": 1, - "default": "validation error in environment variable %s:\\n%s" - } - }, - "additionalProperties": false -} \ No newline at end of file + "$schema": "https://json.schemastore.org/metaschema-draft-07-unofficial-strict.json", + "title": "strings", + "description": "Strings of the generated script\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "object", + "properties": { + "usage": { + "title": "usage", + "description": "The caption for the usage patterns\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "Usage:" + }, + "options": { + "title": "options", + "description": "The caption for the options section\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "Options:" + }, + "global_options": { + "title": "global_options", + "description": "The caption for the options section, when a command has flags and sub-commands\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "Options:" + }, + "arguments": { + "title": "arguments", + "description": "The caption for the argument section\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "Arguments:" + }, + "commands": { + "title": "commands", + "description": "The caption for the command section\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "Commands:" + }, + "examples": { + "title": "examples", + "description": "The caption for the examples section\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "Examples:" + }, + "environment_variables": { + "title": "environment variables", + "description": "The caption for the environment variables section\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "Environment Variables:" + }, + "group": { + "title": "group", + "description": "The caption template for custom command groups\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "%{group} Commands:" + }, + "command_alias": { + "title": "command alias", + "description": "The string template for a command alias\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "Alias: %{alias}" + }, + "default_command_summary": { + "title": "default command summary", + "description": "The string template for the summary of a default command\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "%{summary} (default)" + }, + "required": { + "title": "required", + "description": "The string suffix for required arguments, flags, or commands\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "(required)" + }, + "repeatable": { + "title": "repeatable", + "description": "The string suffix for repeatable arguments, flags, or commands\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "(repeatable)" + }, + "default": { + "title": "default", + "description": "The string template for a default argument or flag\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "Default: %{value}" + }, + "allowed": { + "title": "allowed", + "description": "The string template for the list of allowed values\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "Allowed: %{values}" + }, + "needs": { + "title": "needs", + "description": "The string template for the list of needed flags\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "Needs: %{values}" + }, + "conflicts": { + "title": "conflicts", + "description": "The string template for the list of conflicting flags\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "Conflicts: %{values}" + }, + "help_flag_text": { + "title": "help flag text", + "description": "The help message for --help\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "Show this help" + }, + "version_flag_text": { + "title": "version flag text", + "description": "The help message for --version\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "Show version number" + }, + "flag_requires_an_argument": { + "title": "flag requires an argument", + "description": "The error message template for missing flag argument\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "%{name} requires an argument: %{usage}" + }, + "flag_needs_another": { + "title": "flag needs another flag", + "description": "The error message template for missing flag needs\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "%{name} needs %{need}" + }, + "invalid_argument": { + "title": "invalid argument", + "description": "The error message template for invalid argument\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "invalid argument: %s" + }, + "invalid_flag": { + "title": "invalid flag", + "description": "The error message template for invalid flag\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "invalid option: %s" + }, + "invalid_command": { + "title": "invalid command", + "description": "The error message template for invalid command\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "invalid command: %s" + }, + "conflicting_flags": { + "title": "conflicting flags", + "description": "The error message template for conflicting flags\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "conflicting options: %s cannot be used with %s" + }, + "missing_required_argument": { + "title": "missing required argument", + "description": "The error message template for missing required argument\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "missing required argument: %{arg}\\nusage: %{usage}" + }, + "missing_required_flag": { + "title": "missing required flag", + "description": "The error message template for missing required flag\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "missing required flag: %{usage}" + }, + "missing_required_environment_variable": { + "title": "missing required environment variable", + "description": "The error message template for missing required environment variable\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "missing required environment variable: %{var}" + }, + "missing_dependency": { + "title": "missing dependency", + "description": "The error message template for missing dependency\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "missing dependency: %{dependency}" + }, + "examples_caption_on_error": { + "title": "examples caption on error", + "description": "The string to show before the examples when show_examples_on_error is enabled\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "examples:" + }, + "disallowed_flag": { + "title": "disallowed flag", + "description": "The error message template for forbidden flag\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "%{name} must be one of: %{allowed}" + }, + "disallowed_argument": { + "title": "disallowed argument", + "description": "The error message template for forbidden argument\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "%{name} must be one of: %{allowed}" + }, + "disallowed_environment_variable": { + "title": "disallowed_environment_variable", + "description": "The error message template for forbidden environment variable\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "%{name} environment variable must be one of: %{allowed}" + }, + "unsupported_bash_version": { + "title": "unsupported bash version", + "description": "The error message for unsupported Bash version\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "bash version 4 or higher is required" + }, + "validation_error": { + "title": "validation error", + "description": "The error message template for failed custom validation\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "validation error in %s:\\n%s" + }, + "environment_variable_validation_error": { + "title": "environment variable validation error", + "description": "The error message template for failed custom validation for environment variables\nhttps://bashly.dannyb.co/advanced/strings/#custom-strings", + "type": "string", + "minLength": 1, + "default": "validation error in environment variable %s:\\n%s" + } + }, + "additionalProperties": false +} diff --git a/support/runfile/schema.runfile b/support/runfile/schema.runfile index a5fd4bd0..b233e6cc 100644 --- a/support/runfile/schema.runfile +++ b/support/runfile/schema.runfile @@ -6,6 +6,11 @@ action :generate do say "gb`$` #{cmd}" success = system cmd abort 'Failed' unless success + + cmd = 'yq -p yaml -o json support/schema/settings.yml > schemas/settings.json' + say "gb`$` #{cmd}" + success = system cmd + abort 'Failed' unless success end help 'Run all the test actions in this runfile' diff --git a/support/schema/README.md b/support/schema/README.md index 68af4d86..9540bf98 100644 --- a/support/schema/README.md +++ b/support/schema/README.md @@ -1,4 +1,5 @@ -This is the source file for the `schemas/bashly.json` schema. +This is the source file for `schemas/bashly.json` and `schemas/settings.json` +schemas. To regenerate the bashly.json schema, simply run: @@ -8,8 +9,9 @@ $ run scheme generate from the root directory of the project. -Alternatively, run the `yq` command directly: +Alternatively, run the `yq` commands directly: ``` $ yq -p yaml -o json support/schema/bashly.yml > schemas/bashly.json +$ yq -p yaml -o json support/schema/settings.yml > schemas/settings.json ``` diff --git a/support/schema/settings.yml b/support/schema/settings.yml new file mode 100644 index 00000000..0a01aa14 --- /dev/null +++ b/support/schema/settings.yml @@ -0,0 +1,231 @@ +$schema: https://json.schemastore.org/metaschema-draft-07-unofficial-strict.json +definitions: + color: + oneOf: + - type: string + examples: + - red + - green + - yellow + - blue + - magenta + - cyan + - bold + - underlined + - red_bold + - green_bold + - yellow_bold + - blue_bold + - magenta_bold + - cyan_bold + - red_underlined + - green_underlined + - yellow_underlined + - blue_underlined + - magenta_underlined + - cyan_underlined + - type: "null" +title: settings +description: |- + Settings of the current application + https://bashly.dannyb.co/usage/settings/#settings +type: object +properties: + source_dir: + title: source dir + description: |- + The path containing the bashly source files + https://bashly.dannyb.co/usage/settings/#source_dir + type: string + minLength: 1 + default: src + config_path: + title: config path + description: |- + The path to bashly.yml + https://bashly.dannyb.co/usage/settings/#config_path + type: string + minLength: 1 + default: '%{source_dir}/bashly.yml' + target_dir: + title: target dir + description: |- + The path to use for creating the bash script + https://bashly.dannyb.co/usage/settings/#target_dir + type: string + minLength: 1 + default: . + lib_dir: + title: lib dir + description: |- + The path to use for common library files, relative to source_dir + https://bashly.dannyb.co/usage/settings/#lib_dir + type: string + minLength: 1 + default: lib + commands_dir: + title: commands dir + description: |- + The path to use for command files, relative to source_dir + https://bashly.dannyb.co/usage/settings/#commands_dir + oneOf: + - type: string + minLength: 1 + - type: "null" + strict: + title: strict + description: |- + Configure the bash options that will be added to the initialize function + https://bashly.dannyb.co/usage/settings/#strict + oneOf: + - type: boolean + - type: string + examples: + - set -o pipefail + default: false + tab_indent: + title: tab indent + description: |- + Whether to use tabs or spaces in the generated script + https://bashly.dannyb.co/usage/settings/#tab_indent + type: boolean + default: false + compact_short_flags: + title: compact short flags + description: |- + Whether to expand -abc to -a -b -c in the input line + https://bashly.dannyb.co/usage/settings/#compact_short_flags + type: boolean + default: true + conjoined_flag_args: + title: conjoined flag args + description: |- + Whether to expand --flag=value to --flag value in the input line + https://bashly.dannyb.co/usage/settings/#conjoined_flag_args + type: boolean + default: true + show_examples_on_error: + title: show examples on error + description: |- + Whether to show command examples when the input line is missing required arguments + https://bashly.dannyb.co/usage/settings/#show_examples_on_error + type: boolean + default: true + env: + title: env + description: |- + Whether to include development related comments in the generated script + https://bashly.dannyb.co/usage/settings/#env + type: string + enum: + - development + - production + default: development + enable_header_comment: + title: enable_header_comment + description: |- + Whether to include the header comment in the generated script + https://bashly.dannyb.co/usage/settings/#enable_header_comment + type: string + enum: &feature_toggles + - development + - production + - always + - never + default: always + enable_bash3_bouncer: + title: enable_bash3_bouncer + description: |- + Whether to include the code snippet that aborts when an old version of bash is detected in the generated script + https://bashly.dannyb.co/usage/settings/#enable_bash3_bouncer + type: string + enum: *feature_toggles + default: always + enable_view_markers: + title: enable_view_markers + description: |- + Whether to include view marker comments in the generated script + https://bashly.dannyb.co/usage/settings/#enable_view_markers + type: string + enum: *feature_toggles + default: development + enable_inspect_args: + title: enable_inspect_args + description: |- + Whether to include the inspect_args function in the generated script + https://bashly.dannyb.co/usage/settings/#enable_inspect_args + type: string + enum: *feature_toggles + default: development + enable_deps_array: + title: enable_deps_array + description: |- + Whether to include the code for the dependencies array in the generated script + https://bashly.dannyb.co/usage/settings/#enable_deps_array + type: string + enum: *feature_toggles + 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 + https://bashly.dannyb.co/usage/settings/#enable_env_var_names_array + type: string + enum: *feature_toggles + default: always + partials_extension: + title: partials extension + description: |- + The extension to use when reading/writing partial script snippets + https://bashly.dannyb.co/usage/settings/#partials_extension + type: string + minLength: 1 + default: sh + private_reveal_key: + title: private reveal key + description: |- + The name of the environment variable (case sensitive) that, if set, will reveal private commands, flags and environment variables + https://bashly.dannyb.co/usage/settings/#private_reveal_key + oneOf: + - type: string + minLength: 1 + - type: "null" + usage_colors: + title: usage colors + description: |- + Enable and configure colorful output for --help + https://bashly.dannyb.co/usage/settings/#usage_colors + type: object + properties: + caption: + title: caption + description: |- + Color for captions + https://bashly.dannyb.co/usage/settings/#usage_colors + $ref: '#/definitions/color' + command: + title: command + description: |- + Color for commands + https://bashly.dannyb.co/usage/settings/#usage_colors + $ref: '#/definitions/color' + arg: + title: arg + description: |- + Color for positional arguments + https://bashly.dannyb.co/usage/settings/#usage_colors + $ref: '#/definitions/color' + flag: + title: flag + description: |- + Color for flags + https://bashly.dannyb.co/usage/settings/#usage_colors + $ref: '#/definitions/color' + environment_variable: + title: environment variable + description: |- + Color for env environment variables + https://bashly.dannyb.co/usage/settings/#usage_colors + $ref: '#/definitions/color' + additionalProperties: false +additionalProperties: false From af6ce2bc29c4e1b44a80c4eeb272f530592ba0e4 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Wed, 18 Dec 2024 19:11:36 +0000 Subject: [PATCH 9/9] readme fix --- support/schema/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/schema/README.md b/support/schema/README.md index 9540bf98..e2f7c841 100644 --- a/support/schema/README.md +++ b/support/schema/README.md @@ -1,7 +1,7 @@ This is the source file for `schemas/bashly.json` and `schemas/settings.json` schemas. -To regenerate the bashly.json schema, simply run: +To regenerate the, simply run: ``` $ run scheme generate