From c49d94df1d34403be20aef73fea69bdaedf45d71 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Thu, 15 Aug 2024 09:06:46 +0000 Subject: [PATCH] - Update mandoc/markdown library to consider private visibility setting --- lib/bashly/concerns/completions.rb | 2 +- lib/bashly/libraries/render/mandoc/mandoc.gtx | 8 ++++---- lib/bashly/libraries/render/markdown/markdown.gtx | 4 ++-- lib/bashly/script/introspection/commands.rb | 4 ++-- .../script/introspection/environment_variables.rb | 6 ++++++ lib/bashly/views/argument/usage.gtx | 2 +- spec/README.md | 13 ++++++++++++- spec/approvals/examples/command-private | 4 ++-- 8 files changed, 30 insertions(+), 13 deletions(-) diff --git a/lib/bashly/concerns/completions.rb b/lib/bashly/concerns/completions.rb index ed822433d..a8e0b25b2 100644 --- a/lib/bashly/concerns/completions.rb +++ b/lib/bashly/concerns/completions.rb @@ -62,7 +62,7 @@ def completion_generator end def completion_flag_names - visible_flags.map(&:name) + public_flags.map(&:short) + visible_flags.map(&:name) + visible_flags.map(&:short) end def completion_allowed_args diff --git a/lib/bashly/libraries/render/mandoc/mandoc.gtx b/lib/bashly/libraries/render/mandoc/mandoc.gtx index b2819d439..5a680f26e 100644 --- a/lib/bashly/libraries/render/mandoc/mandoc.gtx +++ b/lib/bashly/libraries/render/mandoc/mandoc.gtx @@ -43,7 +43,7 @@ if extensible end > -if public_commands.any? +if visible_commands.any? grouped_commands.each do |group, commands| > {{ group.gsub(/:$/, '').upcase }} > ================================================== @@ -150,11 +150,11 @@ if dependencies.any? end end -if public_environment_variables.any? +if visible_environment_variables.any? > ENVIRONMENT VARIABLES > ================================================== > - public_environment_variables.each do |environment_variable| + visible_environment_variables.each do |environment_variable| > {{ environment_variable.name.upcase }} > -------------------------------------------------- > @@ -186,7 +186,7 @@ end see_also = [] see_also << parents.first if parents.any? -see_also += public_commands.map { |x| x.full_name.to_hyphen } if public_commands.any? +see_also += visible_commands.map { |x| x.full_name.to_hyphen } if visible_commands.any? see_also += x_mandoc_see_also if x_mandoc_see_also && x_mandoc_see_also.is_a?(Array) see_also.map! do |item| item.match(/(.+)(\(\d\))/) ? "**#{$1}**#{$2}" : "**#{item}**(1)" diff --git a/lib/bashly/libraries/render/markdown/markdown.gtx b/lib/bashly/libraries/render/markdown/markdown.gtx index 2663e4b6a..76dfd840c 100644 --- a/lib/bashly/libraries/render/markdown/markdown.gtx +++ b/lib/bashly/libraries/render/markdown/markdown.gtx @@ -62,10 +62,10 @@ end # === Environment Variables -if public_environment_variables.any? +if visible_environment_variables.any? > ## Environment Variables > - public_environment_variables.each do |environment_variable| + visible_environment_variables.each do |environment_variable| attributes = environment_variable.required || environment_variable.default > #### *{{ environment_variable.name.upcase }}* diff --git a/lib/bashly/script/introspection/commands.rb b/lib/bashly/script/introspection/commands.rb index d1dc7ec9b..299fd23a8 100644 --- a/lib/bashly/script/introspection/commands.rb +++ b/lib/bashly/script/introspection/commands.rb @@ -72,12 +72,12 @@ def default_command def grouped_commands result = {} - public_commands.each do |command| + visible_commands.each do |command| result[command.group_string] ||= [] result[command.group_string] << command next unless command.expose - command.public_commands.each do |subcommand| + command.visible_commands.each do |subcommand| result[command.group_string] << subcommand end end diff --git a/lib/bashly/script/introspection/environment_variables.rb b/lib/bashly/script/introspection/environment_variables.rb index 512204f9e..502be4bb2 100644 --- a/lib/bashly/script/introspection/environment_variables.rb +++ b/lib/bashly/script/introspection/environment_variables.rb @@ -31,6 +31,12 @@ def validated_environment_variables environment_variables.select(&:validate) end + # Returns only public environment variables, or both public and private + # environment variables if Settings.private_reveal_key is set + def visible_environment_variables + Settings.private_reveal_key ? environment_variables : public_environment_variables + end + # Returns an array of all the environment_variables with a whitelist arg def whitelisted_environment_variables environment_variables.select(&:allowed) diff --git a/lib/bashly/views/argument/usage.gtx b/lib/bashly/views/argument/usage.gtx index 3df87dbb7..1b8d992c7 100644 --- a/lib/bashly/views/argument/usage.gtx +++ b/lib/bashly/views/argument/usage.gtx @@ -4,7 +4,7 @@ > printf "{{ help.wrap(76).indent(4).sanitize_for_print }}\n" if allowed - > printf " %s\n" "{{ strings[:allowed] % { values: allowed.join(', ') } }}\n" + > printf " %s\n" "{{ strings[:allowed] % { values: allowed.join(', ') } }}" end if default diff --git a/spec/README.md b/spec/README.md index 4cbcaf2b5..c86641def 100644 --- a/spec/README.md +++ b/spec/README.md @@ -18,10 +18,21 @@ Some specs have tags for convenience: - `:stable` - specs of features that rarely change - `:noci` - specs that are disabled in CI -For example, to run only specs that are not :slow and not :stable, run: +## Useful respec commands + ```bash +# smoke test; run only specs that are not :slow and not :stable $ respec tagged ~stable ~slow + +# test examples only +$ respec only examples + +# test a specific example only +$ EXAMPLE=whitelist respec only examples + +# test only specs that changed recently, and repeat on change +$ respec refactor # or respec r ``` ## Notes about Example Tests diff --git a/spec/approvals/examples/command-private b/spec/approvals/examples/command-private index 2273ad49d..563bf1e3c 100644 --- a/spec/approvals/examples/command-private +++ b/spec/approvals/examples/command-private @@ -14,7 +14,7 @@ Usage: cli --version | -v Commands: - connect Connect to the metaverse + connect Connect to the metaverse + ./cli -h cli - Sample application with private commands @@ -25,7 +25,7 @@ Usage: cli --version | -v Commands: - connect Connect to the metaverse + connect Connect to the metaverse Options: --help, -h