From d37244d9bf56e77c76820e1d230eb9ad90b77e76 Mon Sep 17 00:00:00 2001 From: Julien Caillon Date: Sat, 22 Jun 2024 18:19:27 +0200 Subject: [PATCH] :sparkles: add default for opts/args --- .../docs/025.command-properties/_index.md | 54 ++++ docs/content/docs/800.roadmap/_index.md | 6 +- examples.d/showcase/showcase.sh | 1 + .../1001-main-functions/results.approved.md | 14 + tests.d/1100-self-config/01.self-config.sh | 2 +- .../00.self-build-utils.sh | 101 +++++-- .../1101-self-build-utils/results.approved.md | 275 ++++++++++++++---- tests.d/1102-self-build/01.self-build.sh | 2 +- tests.d/1102-self-build/results.approved.md | 229 ++++++++------- tests.d/1103-self-release/results.approved.md | 7 +- tests.d/1300-valet-cli/results.approved.md | 2 + tests.d/1301-profiler/results.approved.md | 24 +- valet.d/commands.d/self-build-utils | 3 +- valet.d/commands.d/self-build.sh | 6 +- valet.d/main | 11 +- valet.d/version | 2 +- 16 files changed, 533 insertions(+), 206 deletions(-) diff --git a/docs/content/docs/025.command-properties/_index.md b/docs/content/docs/025.command-properties/_index.md index fda684c..27adcd1 100644 --- a/docs/content/docs/025.command-properties/_index.md +++ b/docs/content/docs/025.command-properties/_index.md @@ -8,6 +8,38 @@ url: /docs/command-properties This page describes the properties available to define a command. +Here is a definition example that uses all the properties: + +```yaml {linenos=table,linenostart=1} +command: command +function: functionName +shortDescription: A short sentence. +description: |- + A long description that can use ⌜quotes⌝. +sudo: false +hideInMenu: false +arguments: +- name: firstArg + description: |- + First argument. +- name: more... + description: |- + Will be an an array of strings. +options: +- name: -o, --option1 + description: |- + First option. + noEnvironmentVariable: true +- name: -2, --this-is-option2 + description: |- + An option with a value. + noEnvironmentVariable: false +examples: +- name: command -o -2 value1 arg1 more1 more2 + description: |- + Call command with option1, option2 and some arguments. +``` + You can check the [showcase commands][showcase-examples] to get definition examples. ## 🫚 Top level properties @@ -164,6 +196,28 @@ The description for this option. It will be used to display the help/usage of th |----------|---------------| | yes βœ”οΈ | N/A | +### noEnvironmentVariable + +By default, an option that can have a value (e.g. `--option `) will be parsed to a local variable which default to a global variable if not value was passed by the user. + +For instance, the option `--option1` will be parsed to the local variable `option1` with the following definition: `local option1="${VALET_OPTION1:-}"`. This allows to define options through environment variable. + +This behavior can be changed by setting `noEnvironmentVariable: true` which will always make the local variable for the option empty. + +| Mandatory? | Default value? | +|----------|---------------| +| no | false | + +### default + +The default value to give to the local variable parsed from the option. The global variable will take precedence (see noEnvironmentVariable). + +The local variable will be defined like this: `local option1="${VALET_OPTION1:-"default value"}"`. Where `default value` is the value of this option. + +| Mandatory? | Default value? | +|----------|---------------| +| no | N/A | + ## 🎈 Examples Examples are used in the command help/usage and let the user quickly understand how to use the command. diff --git a/docs/content/docs/800.roadmap/_index.md b/docs/content/docs/800.roadmap/_index.md index 0e8d68d..ac65dc5 100644 --- a/docs/content/docs/800.roadmap/_index.md +++ b/docs/content/docs/800.roadmap/_index.md @@ -8,21 +8,21 @@ url: /docs/roadmap This page lists the features that I would like to implement in Valet. They come in addition to new features described in the [issues][valet-issues]. +- Add a default value for options. - We can have fuzzy matching on options too; just make sure it is not ambiguous. +- Show the arguments required when a command parsing fails. +- Allow to regroup single letter options (e.g. -fsSL). - Add full support for interactive mode. - For dropdown with a set list of options, we can verify that the input value is one of the expected value. - Generate an autocompletion script for bash and zsh. - Self-command to create a new command interactively. - Create a valet-community-commands where everyone can contribute to new default commands for Valet. - head / tail from file. -- Allow to regroup single letter options (e.g. -fsSL). - Add a command self package that build the user commands into a single script file. - fix running tests with verbose mode on. - Have a consistent look and feel for interactive functions. - Reimplement usage of main::sortCommands / main::addLastChoice. -- Add a default value for options. - Implement regex replace in pure bash. -- Show the arguments required when a command parsing fails. - Betters checks in self build! - Support alternative single comments `### VALET COMMAND` instead of multiline comments for command declaration (see we can have help in autocompletion). - A command can declare dependencies to auto check if some tools are installed before running the command. diff --git a/examples.d/showcase/showcase.sh b/examples.d/showcase/showcase.sh index a94e326..0ddacf2 100644 --- a/examples.d/showcase/showcase.sh +++ b/examples.d/showcase/showcase.sh @@ -29,6 +29,7 @@ options: - name: -2, --this-is-option2 description: |- An option with a value. + default: two examples: - name: showcase command1 -o -2 value1 arg1 more1 more2 description: |- diff --git a/tests.d/1001-main-functions/results.approved.md b/tests.d/1001-main-functions/results.approved.md index 9a773fe..799a87f 100644 --- a/tests.d/1001-main-functions/results.approved.md +++ b/tests.d/1001-main-functions/results.approved.md @@ -108,7 +108,9 @@ Exit code: `0` β†’ main::parseFunctionArguments selfMock2 local parsingErrors option1 thisIsOption2 help firstArg local -a more +option1="" thisIsOption2="${VALET_THIS_IS_OPTION2:-}" +help="" parsingErrors="Expecting ⌜2⌝ argument(s) but got ⌜0⌝." more=( ) @@ -116,6 +118,7 @@ more=( β†’ main::parseFunctionArguments selfMock2 -o -2 optionValue2 arg1 more1 more2 local parsingErrors option1 thisIsOption2 help firstArg local -a more +help="" parsingErrors="" option1="true" thisIsOption2="optionValue2" @@ -128,6 +131,7 @@ more=( β†’ main::parseFunctionArguments selfMock2 -o -2 optionValue2 arg1 local parsingErrors option1 thisIsOption2 help firstArg local -a more +help="" parsingErrors="Expecting ⌜2⌝ argument(s) but got ⌜1⌝." option1="true" thisIsOption2="optionValue2" @@ -138,7 +142,9 @@ more=( β†’ main::parseFunctionArguments selfMock2 -unknown -what optionValue2 arg local parsingErrors option1 thisIsOption2 help firstArg local -a more +option1="" thisIsOption2="${VALET_THIS_IS_OPTION2:-}" +help="" parsingErrors="Unknown option ⌜-unknown⌝. Unknown option ⌜-what⌝." firstArg="optionValue2" @@ -150,6 +156,7 @@ more=( local parsingErrors option1 thisIsOption2 help firstArg local -a more thisIsOption2="${VALET_THIS_IS_OPTION2:-}" +help="" parsingErrors="" firstArg="arg" option1="true" @@ -161,7 +168,9 @@ more=( β†’ main::parseFunctionArguments selfMock2 -this arg more1 local parsingErrors option1 thisIsOption2 help firstArg local -a more +option1="" thisIsOption2="${VALET_THIS_IS_OPTION2:-}" +help="" parsingErrors="Unknown option ⌜-this⌝ (did you mean ⌜--this-is-option2⌝?)." firstArg="arg" more=( @@ -171,6 +180,8 @@ more=( β†’ main::parseFunctionArguments selfMock2 --this-is-option2 --option1 arg more1 local parsingErrors option1 thisIsOption2 help firstArg local -a more +option1="" +help="" parsingErrors="" thisIsOption2="--option1" firstArg="arg" @@ -180,6 +191,7 @@ more=( β†’ main::parseFunctionArguments selfMock4 arg1 arg2 local parsingErrors help firstArg secondArg +help="" parsingErrors="" firstArg="arg1" secondArg="arg2" @@ -188,7 +200,9 @@ secondArg="arg2" β†’ main::parseFunctionArguments selfMock2 -- --arg1-- --arg2-- local parsingErrors option1 thisIsOption2 help firstArg local -a more +option1="" thisIsOption2="${VALET_THIS_IS_OPTION2:-}" +help="" parsingErrors="" firstArg="--arg1--" more=( diff --git a/tests.d/1100-self-config/01.self-config.sh b/tests.d/1100-self-config/01.self-config.sh index 6e69980..3c4e64e 100644 --- a/tests.d/1100-self-config/01.self-config.sh +++ b/tests.d/1100-self-config/01.self-config.sh @@ -30,7 +30,7 @@ function testSelfConfig() { echo "β†’ (selfConfig --override --export-current-values)" ( - unset ${!VALET_CONFIG_*} VALET_USER_DIRECTORY + unset -v ${!VALET_CONFIG_*} VALET_USER_DIRECTORY export VALET_CONFIG_FILE="${configFile}" export VALET_CONFIG_COLOR_DEBUG=$'\e[44m' export VALET_CONFIG_LOG_COLUMNS=20 diff --git a/tests.d/1101-self-build-utils/00.self-build-utils.sh b/tests.d/1101-self-build-utils/00.self-build-utils.sh index f7a21a5..ef75cf9 100644 --- a/tests.d/1101-self-build-utils/00.self-build-utils.sh +++ b/tests.d/1101-self-build-utils/00.self-build-utils.sh @@ -3,20 +3,7 @@ # shellcheck source=../../valet.d/commands.d/self-build-utils source "${GLOBAL_VALET_HOME}/valet.d/commands.d/self-build-utils" -function testExtractCommandYamls() { - - extractCommandYamls "resources/extract-command-yamls-test-file" - - local content - for content in "${RETURNED_ARRAY[@]}"; do - echo "content:"$'\n'"⌜${content}⌝" - done - - test::endTest "Testing extractCommandYamls" 0 -} - -function testExtractCommandDefinitionToVariables() { - local content=" +_VALID_YAML=" command: test author: github.com/jcaillon fileToSource: source @@ -27,6 +14,8 @@ description: |- In a multi-line string. With 3 paragraphs. +sudo: false +hideInMenu: false arguments: - name: arg1 description: Description of arg 1. @@ -37,31 +26,50 @@ arguments: description: Description of arg 3. fourthProp: ok3 options: -- name: option1 +- name: --option1 description: |- Description of option 1. Another line. -- name: option2 + noEnvironmentVariable: true + default: true +- name: --option2 description: |- Description of option 2. Another line. + noEnvironmentVariable: false - description: |- Description of option 3. Another line. + default: default value +examples: +- name: command -o -2 value1 arg1 more1 more2 + description: |- + Call command with option1, option2 and some arguments. " - echo "${content}" - extractCommandDefinitionToVariables "${content}" +function testExtractCommandYamls() { - local varName var - for varName in ${!TEMP_CMD_BUILD_*}; do - local -n var="${varName}" - echo "${varName}=${var@Q}" + extractCommandYamls "resources/extract-command-yamls-test-file" + + local content + for content in "${RETURNED_ARRAY[@]}"; do + log::info "content:" + log::printFileString "${content}" done + test::endTest "Testing extractCommandYamls" 0 +} + +function testExtractCommandDefinitionToVariables() { + log::printFileString "${_VALID_YAML}" + + extractCommandDefinitionToVariables "${_VALID_YAML}" + + printVars ${!TEMP_CMD_BUILD_*} + test::endTest "Testing extractCommandDefinitionToVariables" 0 } @@ -75,9 +83,58 @@ function testExtractFirstLongNameFromOptionString() { test::endTest "Testing extractFirstLongNameFromOptionString" 0 } +function testDeclareFinalVariables() { + log::printFileString "${_VALID_YAML}" + + # declare common variables + declareFinalCommandDefinitionCommonVariables "func" "cmd" + + # declare help variables + declareFinalCommandDefinitionHelpVariables "func" + + # declare options and arguments for the parser + declareFinalCommandDefinitionParserVariables "func" + + printVars ${!CMD_*} + + test::endTest "Testing declareFinalCommandDefinition*" 0 +} + +function testVerifyCommandDefinition() { + log::printFileString "${_VALID_YAML}" + + # verify that the command definition is valid + verifyCommandDefinition "func" "cmd" + echo + echo "${SELF_BUILD_ERRORS:-}" + + test::endTest "Testing verifyCommandDefinition" 0 +} + +function printVars() { + local varName var + for varName in "$@"; do + local -n var="${varName}" + echo "${varName}=${var[*]@K}" + done +} + function main() { testExtractCommandYamls testExtractCommandDefinitionToVariables testExtractFirstLongNameFromOptionString + + testDeclareFinalVariables + testVerifyCommandDefinition } +# save all CMD_* variables into a temporary string +io::invoke declare -p ${!CMD_*} +_ALL_CMD_VARIABLES="${RETURNED_VALUE//declare -? /}" +unset -v ${!CMD_*} _LINE + main + +# reset all CMD_* as they were +unset -v _VALID_YAML +unset -v ${!CMD_*} +eval "${_ALL_CMD_VARIABLES}" \ No newline at end of file diff --git a/tests.d/1101-self-build-utils/results.approved.md b/tests.d/1101-self-build-utils/results.approved.md index d6a6cbe..2ab10cc 100644 --- a/tests.d/1101-self-build-utils/results.approved.md +++ b/tests.d/1101-self-build-utils/results.approved.md @@ -6,19 +6,19 @@ Exit code: `0` -**Standard** output: +**Error** output: -```plaintext -content: -⌜A content between tags -array: - - item1 - - item2 - - item3 -⌝ -content: -⌜And another one! -⌝ +```log +INFO content: + 1 β–‘ A content between tags + 2 β–‘ array: + 3 β–‘ - item1 + 4 β–‘ - item2 + 5 β–‘ - item3 + 6 β–‘ +INFO content: + 1 β–‘ And another one! + 2 β–‘ ``` ### Testing extractCommandDefinitionToVariables @@ -28,53 +28,74 @@ Exit code: `0` **Standard** output: ```plaintext - -command: test -author: github.com/jcaillon -fileToSource: source -shortDescription: Short description. -description: |- - A long description. - - In a multi-line string. - - With 3 paragraphs. -arguments: -- name: arg1 - description: Description of arg 1. -- name: arg2 - description: Description of arg 2. - thirdProp: ok2 -- name: arg3 - description: Description of arg 3. - fourthProp: ok3 -options: -- name: option1 - description: |- - Description of option 1. - - Another line. -- name: option2 - description: |- - Description of option 2. - - Another line. -- description: |- - Description of option 3. - - Another line. - -TEMP_CMD_BUILD_arguments_description='Description of arg 1.' -TEMP_CMD_BUILD_arguments_fourthProp='' -TEMP_CMD_BUILD_arguments_name='arg1' -TEMP_CMD_BUILD_arguments_thirdProp='' +TEMP_CMD_BUILD_arguments_description=0 "Description of arg 1." 1 "Description of arg 2." 2 "Description of arg 3." +TEMP_CMD_BUILD_arguments_fourthProp=0 "" 1 "" 2 "ok3" +TEMP_CMD_BUILD_arguments_name=0 "arg1" 1 "arg2" 2 "arg3" +TEMP_CMD_BUILD_arguments_thirdProp=0 "" 1 "ok2" TEMP_CMD_BUILD_author='github.com/jcaillon' TEMP_CMD_BUILD_command='test' TEMP_CMD_BUILD_description=$'A long description.\n\nIn a multi-line string.\n\nWith 3 paragraphs.' +TEMP_CMD_BUILD_examples_description=0 $'Call command with option1, option2 and some arguments.\n' +TEMP_CMD_BUILD_examples_name=0 "command -o -2 value1 arg1 more1 more2" TEMP_CMD_BUILD_fileToSource='source' -TEMP_CMD_BUILD_options_description=$'Description of option 1.\n\nAnother line.' -TEMP_CMD_BUILD_options_name='option1' +TEMP_CMD_BUILD_hideInMenu='false' +TEMP_CMD_BUILD_options_default=0 "true" 1 "" 2 "default value" +TEMP_CMD_BUILD_options_description=0 $'Description of option 1.\n\nAnother line.' 1 $'Description of option 2.\n\nAnother line.' 2 $'Description of option 3.\n\nAnother line.' +TEMP_CMD_BUILD_options_name=0 "--option1" 1 "--option2" +TEMP_CMD_BUILD_options_noEnvironmentVariable=0 "true" 1 "false" TEMP_CMD_BUILD_shortDescription='Short description.' +TEMP_CMD_BUILD_sudo='false' +``` + +**Error** output: + +```log + 1 β–‘ + 2 β–‘ command: test + 3 β–‘ author: github.com/jcaillon + 4 β–‘ fileToSource: source + 5 β–‘ shortDescription: Short description. + 6 β–‘ description: |- + 7 β–‘ A long description. + 8 β–‘ + 9 β–‘ In a multi-line string. + 10 β–‘ + 11 β–‘ With 3 paragraphs. + 12 β–‘ sudo: false + 13 β–‘ hideInMenu: false + 14 β–‘ arguments: + 15 β–‘ - name: arg1 + 16 β–‘ description: Description of arg 1. + 17 β–‘ - name: arg2 + 18 β–‘ description: Description of arg 2. + 19 β–‘ thirdProp: ok2 + 20 β–‘ - name: arg3 + 21 β–‘ description: Description of arg 3. + 22 β–‘ fourthProp: ok3 + 23 β–‘ options: + 24 β–‘ - name: --option1 + 25 β–‘ description: |- + 26 β–‘ Description of option 1. + 27 β–‘ + 28 β–‘ Another line. + 29 β–‘ noEnvironmentVariable: true + 30 β–‘ default: true + 31 β–‘ - name: --option2 + 32 β–‘ description: |- + 33 β–‘ Description of option 2. + 34 β–‘ + 35 β–‘ Another line. + 36 β–‘ noEnvironmentVariable: false + 37 β–‘ - description: |- + 38 β–‘ Description of option 3. + 39 β–‘ + 40 β–‘ Another line. + 41 β–‘ default: default value + 42 β–‘ examples: + 43 β–‘ - name: command -o -2 value1 arg1 more1 more2 + 44 β–‘ description: |- + 45 β–‘ Call command with option1, option2 and some arguments. + 46 β–‘ ``` ### Testing extractFirstLongNameFromOptionString @@ -88,3 +109,149 @@ Exit code: `0` --profiling ``` +### Testing declareFinalCommandDefinition* + +Exit code: `0` + +**Standard** output: + +```plaintext +CMD_ALL_COMMANDS_ARRAY=0 "cmd" +CMD_ALL_FUNCTIONS_ARRAY=0 "func" +CMD_ARGS_LAST_IS_ARRAY_func='false' +CMD_ARGS_NAME_func=0 "arg1" 1 "arg2" 2 "arg3" +CMD_ARGS_NB_OPTIONAL_func='0' +CMD_ARGUMENTS_DESCRIPTION_func=0 "Description of arg 1." 1 "Description of arg 2." 2 "Description of arg 3." +CMD_ARGUMENTS_NAME_func=0 "arg1" 1 "arg2" 2 "arg3" +CMD_COMMAND_func='cmd' +CMD_DESCRIPTION_func=$'A long description.\n\nIn a multi-line string.\n\nWith 3 paragraphs.' +CMD_EXAMPLES_DESCRIPTION_func=0 $'Call command with option1, option2 and some arguments.\n' +CMD_EXAMPLES_NAME_func=0 "command -o -2 value1 arg1 more1 more2" +CMD_FILETOSOURCE_func='source' +CMD_FUNCTION_NAME_cmd='func' +CMD_MAX_COMMAND_WIDTH='3' +CMD_MAX_SUB_COMMAND_LEVEL='0' +CMD_OPTIONS_DESCRIPTION_func=0 $'Description of option 1.\n\nAnother line.' 1 $'Description of option 2.\n\nAnother line.\nThis option can be set by exporting the variable VALET_OPTION2=\'true\'.' 2 $'Description of option 3.\n\nAnother line.' 3 "Display the help for this command." +CMD_OPTIONS_NAME_func=0 "--option1" 1 "--option2" 2 "-h, --help" +CMD_OPTS_DEFAULT_func=0 "true" 1 "" 2 "default value" +CMD_OPTS_HAS_VALUE_func=0 "false" 1 "false" 2 "false" +CMD_OPTS_NAME_SC_func=0 "" 1 "VALET_OPTION2" 2 "" +CMD_OPTS_NAME_func=0 "option1" 1 "option2" 2 "help" +CMD_OPTS_func=0 "--option1" 1 "--option2" 2 "-h --help" +CMD_SHORT_DESCRIPTION_func='Short description.' +CMD_SUDO_func='false' +``` + +**Error** output: + +```log + 1 β–‘ + 2 β–‘ command: test + 3 β–‘ author: github.com/jcaillon + 4 β–‘ fileToSource: source + 5 β–‘ shortDescription: Short description. + 6 β–‘ description: |- + 7 β–‘ A long description. + 8 β–‘ + 9 β–‘ In a multi-line string. + 10 β–‘ + 11 β–‘ With 3 paragraphs. + 12 β–‘ sudo: false + 13 β–‘ hideInMenu: false + 14 β–‘ arguments: + 15 β–‘ - name: arg1 + 16 β–‘ description: Description of arg 1. + 17 β–‘ - name: arg2 + 18 β–‘ description: Description of arg 2. + 19 β–‘ thirdProp: ok2 + 20 β–‘ - name: arg3 + 21 β–‘ description: Description of arg 3. + 22 β–‘ fourthProp: ok3 + 23 β–‘ options: + 24 β–‘ - name: --option1 + 25 β–‘ description: |- + 26 β–‘ Description of option 1. + 27 β–‘ + 28 β–‘ Another line. + 29 β–‘ noEnvironmentVariable: true + 30 β–‘ default: true + 31 β–‘ - name: --option2 + 32 β–‘ description: |- + 33 β–‘ Description of option 2. + 34 β–‘ + 35 β–‘ Another line. + 36 β–‘ noEnvironmentVariable: false + 37 β–‘ - description: |- + 38 β–‘ Description of option 3. + 39 β–‘ + 40 β–‘ Another line. + 41 β–‘ default: default value + 42 β–‘ examples: + 43 β–‘ - name: command -o -2 value1 arg1 more1 more2 + 44 β–‘ description: |- + 45 β–‘ Call command with option1, option2 and some arguments. + 46 β–‘ +``` + +### Testing verifyCommandDefinition + +Exit code: `0` + +**Standard** output: + +```plaintext + + +``` + +**Error** output: + +```log + 1 β–‘ + 2 β–‘ command: test + 3 β–‘ author: github.com/jcaillon + 4 β–‘ fileToSource: source + 5 β–‘ shortDescription: Short description. + 6 β–‘ description: |- + 7 β–‘ A long description. + 8 β–‘ + 9 β–‘ In a multi-line string. + 10 β–‘ + 11 β–‘ With 3 paragraphs. + 12 β–‘ sudo: false + 13 β–‘ hideInMenu: false + 14 β–‘ arguments: + 15 β–‘ - name: arg1 + 16 β–‘ description: Description of arg 1. + 17 β–‘ - name: arg2 + 18 β–‘ description: Description of arg 2. + 19 β–‘ thirdProp: ok2 + 20 β–‘ - name: arg3 + 21 β–‘ description: Description of arg 3. + 22 β–‘ fourthProp: ok3 + 23 β–‘ options: + 24 β–‘ - name: --option1 + 25 β–‘ description: |- + 26 β–‘ Description of option 1. + 27 β–‘ + 28 β–‘ Another line. + 29 β–‘ noEnvironmentVariable: true + 30 β–‘ default: true + 31 β–‘ - name: --option2 + 32 β–‘ description: |- + 33 β–‘ Description of option 2. + 34 β–‘ + 35 β–‘ Another line. + 36 β–‘ noEnvironmentVariable: false + 37 β–‘ - description: |- + 38 β–‘ Description of option 3. + 39 β–‘ + 40 β–‘ Another line. + 41 β–‘ default: default value + 42 β–‘ examples: + 43 β–‘ - name: command -o -2 value1 arg1 more1 more2 + 44 β–‘ description: |- + 45 β–‘ Call command with option1, option2 and some arguments. + 46 β–‘ +``` + diff --git a/tests.d/1102-self-build/01.self-build.sh b/tests.d/1102-self-build/01.self-build.sh index cb9109f..26c219d 100644 --- a/tests.d/1102-self-build/01.self-build.sh +++ b/tests.d/1102-self-build/01.self-build.sh @@ -11,7 +11,7 @@ function testSelfBuild() { for varName in ${!CMD_*}; do local -n var="${varName}" var="${var//[βŒœβŒβ†’]/}" - echo "${varName}=${var@Q}" + echo "${varName}=${var[*]@K}" done ) diff --git a/tests.d/1102-self-build/results.approved.md b/tests.d/1102-self-build/results.approved.md index 40e94dd..30788e3 100644 --- a/tests.d/1102-self-build/results.approved.md +++ b/tests.d/1102-self-build/results.approved.md @@ -10,39 +10,39 @@ Exit code: `0` ```plaintext CMD_ALL_COMMANDS=$'self\nhelp\nself build\nself config\nself export\nself mock1\nself mock2\nself mock3\nself mock4\nself release\nself setup\nself test\nself update' -CMD_ALL_COMMANDS_ARRAY='help' -CMD_ALL_COMMAND_SELECTION_ITEMS_ARRAY='help Show the help this program or of a specific command.' +CMD_ALL_COMMANDS_ARRAY=0 "help" 1 "self build" 2 "self config" 3 "self export" 4 "self mock1" 5 "self mock2" 6 "self mock3" 7 "self mock4" 8 "self release" 9 "self setup" 10 "self test" 11 "self update" +CMD_ALL_COMMAND_SELECTION_ITEMS_ARRAY=0 "help Show the help this program or of a specific command." 1 "self build Re-build the menu of valet from your commands." 2 "self config Open the configuration file of Valet with your default editor." 3 "self test Test your valet custom commands." 4 "self update Update valet using the latest release on GitHub." CMD_ALL_FUNCTIONS=$'this\nshowCommandHelp\nselfBuild\nselfConfig\nselfExport\nselfUpdate\nselfMock1\nselfMock2\nselfMock3\nselfMock4\nselfRelease\nselfSetup\nselfTest' -CMD_ALL_FUNCTIONS_ARRAY='this' -CMD_ALL_MENU_COMMANDS_ARRAY='self' +CMD_ALL_FUNCTIONS_ARRAY=0 "this" 1 "showCommandHelp" 2 "selfBuild" 3 "selfConfig" 4 "selfExport" 5 "selfUpdate" 6 "selfMock1" 7 "selfMock2" 8 "selfMock3" 9 "selfMock4" 10 "selfRelease" 11 "selfSetup" 12 "selfTest" +CMD_ALL_MENU_COMMANDS_ARRAY=0 "self" CMD_ARGS_LAST_IS_ARRAY_selfConfig='false' CMD_ARGS_LAST_IS_ARRAY_selfMock1='false' CMD_ARGS_LAST_IS_ARRAY_selfMock2='true' CMD_ARGS_LAST_IS_ARRAY_selfMock4='false' CMD_ARGS_LAST_IS_ARRAY_showCommandHelp='true' CMD_ARGS_LAST_IS_ARRAY_this='true' -CMD_ARGS_NAME_selfMock1='action' -CMD_ARGS_NAME_selfMock2='firstArg' -CMD_ARGS_NAME_selfMock4='firstArg' -CMD_ARGS_NAME_showCommandHelp='commands' -CMD_ARGS_NAME_this='commands' +CMD_ARGS_NAME_selfMock1=0 "action" +CMD_ARGS_NAME_selfMock2=0 "firstArg" 1 "more" +CMD_ARGS_NAME_selfMock4=0 "firstArg" 1 "secondArg" +CMD_ARGS_NAME_showCommandHelp=0 "commands" +CMD_ARGS_NAME_this=0 "commands" CMD_ARGS_NB_OPTIONAL_selfMock1='0' CMD_ARGS_NB_OPTIONAL_selfMock2='0' CMD_ARGS_NB_OPTIONAL_selfMock4='0' CMD_ARGS_NB_OPTIONAL_showCommandHelp='1' CMD_ARGS_NB_OPTIONAL_this='1' -CMD_ARGUMENTS_DESCRIPTION_selfMock1=$'The action to perform.\nOne of the following options:\n\n- error\n- fail\n- fail2\n- exit\n- unknown-command\n- create-temp-files\n- logging-level\n- wait-indefinitely\n- show-help\n- print-raw-and-file\n' -CMD_ARGUMENTS_DESCRIPTION_selfMock2='First argument.' -CMD_ARGUMENTS_DESCRIPTION_selfMock4='First argument.' -CMD_ARGUMENTS_DESCRIPTION_showCommandHelp=$'The name of the command to show the help for.\nIf not provided, show the help for the program.' -CMD_ARGUMENTS_DESCRIPTION_this=$'The command or sub commands to execute.\nSee the commands section for more information.' -CMD_ARGUMENTS_NAME_selfMock1='action' -CMD_ARGUMENTS_NAME_selfMock2='firstArg' -CMD_ARGUMENTS_NAME_selfMock4='firstArg' -CMD_ARGUMENTS_NAME_showCommandHelp='commands?...' -CMD_ARGUMENTS_NAME_this='commands?...' -CMD_COMMANDS_DESCRIPTION_this='Show the help this program or of a specific command.' -CMD_COMMANDS_NAME_this='help' +CMD_ARGUMENTS_DESCRIPTION_selfMock1=0 $'The action to perform.\nOne of the following options:\n\n- error\n- fail\n- fail2\n- exit\n- unknown-command\n- create-temp-files\n- logging-level\n- wait-indefinitely\n- show-help\n- print-raw-and-file\n' +CMD_ARGUMENTS_DESCRIPTION_selfMock2=0 "First argument." 1 "Will be an an array of strings." +CMD_ARGUMENTS_DESCRIPTION_selfMock4=0 "First argument." 1 $'Second argument.\n' +CMD_ARGUMENTS_DESCRIPTION_showCommandHelp=0 $'The name of the command to show the help for.\nIf not provided, show the help for the program.' +CMD_ARGUMENTS_DESCRIPTION_this=0 $'The command or sub commands to execute.\nSee the commands section for more information.' +CMD_ARGUMENTS_NAME_selfMock1=0 "action" +CMD_ARGUMENTS_NAME_selfMock2=0 "firstArg" 1 "more..." +CMD_ARGUMENTS_NAME_selfMock4=0 "firstArg" 1 "secondArg" +CMD_ARGUMENTS_NAME_showCommandHelp=0 "commands?..." +CMD_ARGUMENTS_NAME_this=0 "commands?..." +CMD_COMMANDS_DESCRIPTION_this=0 "Show the help this program or of a specific command." 1 "Re-build the menu of valet from your commands." 2 "Open the configuration file of Valet with your default editor." 3 "Returns a string that can be evaluated to have Valet functions in bash." 4 "A command that only for testing valet core functions." 5 "A command that only for testing valet core functions." 6 "A command that only for testing valet core functions." 7 "A command that only for testing valet core functions." 8 "Release a new version of valet." 9 "The command run after the installation of Valet to setup the tool." 10 "Test your valet custom commands." 11 "Update valet using the latest release on GitHub." +CMD_COMMANDS_NAME_this=0 "help" 1 "self build" 2 "self config" 3 "self export" 4 "self mock1" 5 "self mock2" 6 "self mock3" 7 "self mock4" 8 "self release" 9 "self setup" 10 "self test" 11 "self update" CMD_COMMAND_selfBuild='self build' CMD_COMMAND_selfConfig='self config' CMD_COMMAND_selfExport='self export' @@ -70,12 +70,12 @@ CMD_DESCRIPTION_selfTest='Test your valet custom commands using approval tests a CMD_DESCRIPTION_selfUpdate=$'Update valet using the latest release on GitHub.\n' CMD_DESCRIPTION_showCommandHelp=$'Show the help this program or of the help of a specific command.\n\nYou can show the help with or without colors and set the maximum columns for the help text.' CMD_DESCRIPTION_this=$'Valet helps you browse, understand and execute your custom bash commands.\n\nOnline documentation is available at https://github.com/jcaillon/valet.\n\nYou can call valet without any commands to start an interactive session.\n\nExit codes:\n\n- 0: everything went well\n- 1+: an error occured\n\nCreate your own commands:\n\nYou can create your own commands and have them available in valet, please check https://github.com/jcaillon/valet/blob/main/docs/create-new-command.md or the examples under examples.d to do so.\nValet looks for commands in the valet user directory, which default to ~/.valet.d and can be overwritten using an environment variable (see below).\nOnce you have created your new command script, run the valet self build command to update the valet menu.\n\nConfiguration through environment variables:\n\nIn addition to the environment variables defined for each options, you can define environment variables to configure valet.\n\nThese variables are conviently defined in the valet user config file, located by default at ~/.config/valet/config (the path to this file can be configured using the VALET_CONFIG_FILE environment variable).\n\nYou can run valet self config to open the configuration file with your default editor (the file will get created if it does not yet exist).\n\nDeveloper notes:\n\nYou can enable debug mode with profiling for valet by setting the environment variable VALET_CONFIG_STARTUP_PROFILING to true (it will output to ~/valet-profiler-{PID}.txt).' -CMD_EXAMPLES_DESCRIPTION_selfMock2=$'Call command1 with option1, option2 and some arguments.\n' -CMD_EXAMPLES_DESCRIPTION_showCommandHelp='Shows the help for the command cmd' -CMD_EXAMPLES_DESCRIPTION_this='Displays this help text.' -CMD_EXAMPLES_NAME_selfMock2='self mock2 -o -2 value1 arg1 more1 more2' -CMD_EXAMPLES_NAME_showCommandHelp='help cmd' -CMD_EXAMPLES_NAME_this='--help' +CMD_EXAMPLES_DESCRIPTION_selfMock2=0 $'Call command1 with option1, option2 and some arguments.\n' +CMD_EXAMPLES_DESCRIPTION_showCommandHelp=0 "Shows the help for the command cmd" 1 "Shows the help for the sub command ⌜subCmd⌝ of the command ⌜cmd⌝" 2 $'Shows the help for the program without any color and with a maximum of 50 columns\n' +CMD_EXAMPLES_DESCRIPTION_this=0 "Displays this help text." 1 $'Active ⌜verbose⌝ mode and run the command ⌜a-command⌝ with the sub command ⌜and-sub-command⌝.\n' +CMD_EXAMPLES_NAME_selfMock2=0 "self mock2 -o -2 value1 arg1 more1 more2" +CMD_EXAMPLES_NAME_showCommandHelp=0 "help cmd" 1 "help cmd subCmd" 2 "help --no-colors --columns 50" +CMD_EXAMPLES_NAME_this=0 "--help" 1 "-v a-command and-sub-command" CMD_FILETOSOURCE_selfBuild='valet.d/commands.d/self-build.sh' CMD_FILETOSOURCE_selfConfig='valet.d/commands.d/self-config.sh' CMD_FILETOSOURCE_selfExport='valet.d/commands.d/self-export.sh' @@ -113,87 +113,100 @@ CMD_HIDEINMENU_selfSetup='true' CMD_MAX_COMMAND_WIDTH='12' CMD_MAX_SUB_COMMAND_LEVEL='1' CMD_OPTIONS_DESCRIPTION__menu='Display the help for this command.' -CMD_OPTIONS_DESCRIPTION_selfBuild=$'Specify the directory in which to look for your command scripts.\n\nThis defaults to the path defined in the environment variable VALET_USER_DIRECTORY=\\my/path\\ or to ~/.valet.d.\n\nCan be empty to only build the core commands.\nThis option can be set by exporting the variable VALET_USER_DIRECTORY=\'\'.' -CMD_OPTIONS_DESCRIPTION_selfConfig=$'Create the configuration file if it does not exist but do not open it.\nThis option can be set by exporting the variable VALET_NO_EDIT=\'true\'.' -CMD_OPTIONS_DESCRIPTION_selfExport=$'Export all the libraries.\n\nThis option can be set by exporting the variable VALET_EXPORT_ALL=\'true\'.' -CMD_OPTIONS_DESCRIPTION_selfMock1='Display the help for this command.' -CMD_OPTIONS_DESCRIPTION_selfMock2='First option.' -CMD_OPTIONS_DESCRIPTION_selfMock3='Display the help for this command.' -CMD_OPTIONS_DESCRIPTION_selfMock4='Display the help for this command.' -CMD_OPTIONS_DESCRIPTION_selfRelease=$'The token necessary to create the release on GitHub and upload artifacts.\nThis option can be set by exporting the variable VALET_GITHUB_RELEASE_TOKEN=\'\'.' -CMD_OPTIONS_DESCRIPTION_selfSetup='Display the help for this command.' -CMD_OPTIONS_DESCRIPTION_selfTest=$'The path to your valet directory.\n\nEach sub directory named .tests.d will be considered as a test directory containing a test.sh file.\nThis option can be set by exporting the variable VALET_USER_DIRECTORY=\'\'.' -CMD_OPTIONS_DESCRIPTION_selfUpdate='Display the help for this command.' -CMD_OPTIONS_DESCRIPTION_showCommandHelp=$'Do not use any colors in the output\nThis option can be set by exporting the variable VALET_NO_COLORS=\'true\'.' -CMD_OPTIONS_DESCRIPTION_this=$'Turn on profiling (with debug mode) before running the required command.\nIt will output to ~/valet-profiler-{PID}-command.txt.\nThis is useful to debug your command and understand what takes a long time to execute.\nThe profiler log will be cleanup to only keep lines relevant for your command script. You can disable this behavior by setting the environment variable VALET_CONFIG_KEEP_ALL_PROFILER_LINES to true.\nThis option can be set by exporting the variable VALET_PROFILING=\'true\'.' +CMD_OPTIONS_DESCRIPTION_selfBuild=0 $'Specify the directory in which to look for your command scripts.\n\nThis defaults to the path defined in the environment variable VALET_USER_DIRECTORY=\\my/path\\ or to ~/.valet.d.\n\nCan be empty to only build the core commands.\nThis option can be set by exporting the variable VALET_USER_DIRECTORY=\'\'.' 1 $'Specify the file path in which to write the command definition variables.\n\nThis defaults to the ⌜commands⌝ file in your Valet user directory.\n\nCan be empty to not write the file.\n\nThis option can be set by exporting the variable VALET_OUTPUT=\'\'.' 2 "Display the help for this command." +CMD_OPTIONS_DESCRIPTION_selfConfig=0 $'Create the configuration file if it does not exist but do not open it.\nThis option can be set by exporting the variable VALET_NO_EDIT=\'true\'.' 1 $'Override of the configuration file even if it already exists.\nUnless the option --export-current-values is used, the existing values will be reset.\nThis option can be set by exporting the variable VALET_OVERRIDE=\'true\'.' 2 $'When writing the configuration file, export the current values of the variables.\n\nThis option can be set by exporting the variable VALET_EXPORT_CURRENT_VALUES=\'true\'.' 3 "Display the help for this command." +CMD_OPTIONS_DESCRIPTION_selfExport=0 $'Export all the libraries.\n\nThis option can be set by exporting the variable VALET_EXPORT_ALL=\'true\'.' 1 "Display the help for this command." +CMD_OPTIONS_DESCRIPTION_selfMock1=0 "Display the help for this command." +CMD_OPTIONS_DESCRIPTION_selfMock2=0 "First option." 1 $'An option with a value.\nThis option can be set by exporting the variable VALET_THIS_IS_OPTION2=\'\'.' 2 "Display the help for this command." +CMD_OPTIONS_DESCRIPTION_selfMock3=0 "Display the help for this command." +CMD_OPTIONS_DESCRIPTION_selfMock4=0 "Display the help for this command." +CMD_OPTIONS_DESCRIPTION_selfRelease=0 $'The token necessary to create the release on GitHub and upload artifacts.\nThis option can be set by exporting the variable VALET_GITHUB_RELEASE_TOKEN=\'\'.' 1 $'The semver level to bump the version.\n\nCan be either: major or minor. Defaults to minor.\nThis option can be set by exporting the variable VALET_BUMP_LEVEL=\'\'.' 2 $'Do not perform the release, just show what would be done.\nThis option can be set by exporting the variable VALET_DRY_RUN=\'true\'.' 3 $'Do no create the release, just upload the artifacts to the latest release.\n\nThis option can be set by exporting the variable VALET_UPLOAD_ARTIFACTS_ONLY=\'true\'.' 4 "Display the help for this command." +CMD_OPTIONS_DESCRIPTION_selfSetup=0 "Display the help for this command." +CMD_OPTIONS_DESCRIPTION_selfTest=0 $'The path to your valet directory.\n\nEach sub directory named .tests.d will be considered as a test directory containing a test.sh file.\nThis option can be set by exporting the variable VALET_USER_DIRECTORY=\'\'.' 1 $'The received test result files will automatically be approved.\nThis option can be set by exporting the variable VALET_AUTO_APPROVE=\'true\'.' 2 $'Also test the valet core functions.\n\nThis is only if you modified valet core functions themselves.\nThis option can be set by exporting the variable VALET_WITH_CORE=\'true\'.' 3 $'Only test the valet core functions. Skips the tests for user commands.\nThis option can be set by exporting the variable VALET_ONLY_CORE=\'true\'.' 4 $'A regex pattern to include only the test suites that match the pattern.\n\nThe name of the test suite is given by the name of the directory containing the .sh test files.\n\nExample: --include \'(1|commands)\'\nThis option can be set by exporting the variable VALET_INCLUDE=\'\'.' 5 $'A regex pattern to exclude all the test suites that match the pattern.\n\nThe name of the test suite is given by the name of the directory containing the .sh test files.\n\nExample: --exclude \'(1|commands)\'\n\nThis option can be set by exporting the variable VALET_EXCLUDE=\'\'.' 6 "Display the help for this command." +CMD_OPTIONS_DESCRIPTION_selfUpdate=0 "Display the help for this command." +CMD_OPTIONS_DESCRIPTION_showCommandHelp=0 $'Do not use any colors in the output\nThis option can be set by exporting the variable VALET_NO_COLORS=\'true\'.' 1 $'Set the maximum columns for the help text\nThis option can be set by exporting the variable VALET_COLUMNS=\'\'.' 2 "Display the help for this command." +CMD_OPTIONS_DESCRIPTION_this=0 $'Turn on profiling (with debug mode) before running the required command.\nIt will output to ~/valet-profiler-{PID}-command.txt.\nThis is useful to debug your command and understand what takes a long time to execute.\nThe profiler log will be cleanup to only keep lines relevant for your command script. You can disable this behavior by setting the environment variable VALET_CONFIG_KEEP_ALL_PROFILER_LINES to true.\nThis option can be set by exporting the variable VALET_PROFILING=\'true\'.' 1 $'Set the log level of valet (defaults to info).\nPossible values are: trace, debug, success, info, success, warning, error.\nThis option can be set by exporting the variable VALET_LOG_LEVEL,=\'\'.' 2 $'Output verbose information.\nThis is the equivalent of setting the log level to debug.\nThis option can be set by exporting the variable VALET_VERBOSE=\'true\'.' 3 $'Output very verbose information.\nThis is the equivalent of setting the log level to trace.\nThis option can be set by exporting the variable VALET_VERY_VERBOSE=\'true\'.' 4 $'Enter interactive mode for commands even if arguments are not required or provided.\nThis option can be set by exporting the variable VALET_FORCE_INTERACTIVE_MODE=\'true\'.' 5 "Display the current version of valet." 6 "Display the help for this command." CMD_OPTIONS_NAME__menu='-h, --help' -CMD_OPTIONS_NAME_selfBuild='-d, --user-directory ' -CMD_OPTIONS_NAME_selfConfig='--no-edit' -CMD_OPTIONS_NAME_selfExport='-a, --export-all' -CMD_OPTIONS_NAME_selfMock1='-h, --help' -CMD_OPTIONS_NAME_selfMock2='-o, --option1' -CMD_OPTIONS_NAME_selfMock3='-h, --help' -CMD_OPTIONS_NAME_selfMock4='-h, --help' -CMD_OPTIONS_NAME_selfRelease='-t, --github-release-token ' -CMD_OPTIONS_NAME_selfSetup='-h, --help' -CMD_OPTIONS_NAME_selfTest='-d, --user-directory ' -CMD_OPTIONS_NAME_selfUpdate='-h, --help' -CMD_OPTIONS_NAME_showCommandHelp='-n, --no-colors' -CMD_OPTIONS_NAME_this='-x, --profiling' -CMD_OPTS_HAS_VALUE_selfBuild='true' -CMD_OPTS_HAS_VALUE_selfConfig='false' -CMD_OPTS_HAS_VALUE_selfExport='false' -CMD_OPTS_HAS_VALUE_selfMock1='false' -CMD_OPTS_HAS_VALUE_selfMock2='false' -CMD_OPTS_HAS_VALUE_selfMock3='false' -CMD_OPTS_HAS_VALUE_selfMock4='false' -CMD_OPTS_HAS_VALUE_selfRelease='true' -CMD_OPTS_HAS_VALUE_selfSetup='false' -CMD_OPTS_HAS_VALUE_selfTest='true' -CMD_OPTS_HAS_VALUE_selfUpdate='false' -CMD_OPTS_HAS_VALUE_showCommandHelp='false' -CMD_OPTS_HAS_VALUE_this='false' -CMD_OPTS_NAME_SC_selfBuild='VALET_USER_DIRECTORY' -CMD_OPTS_NAME_SC_selfConfig='VALET_NO_EDIT' -CMD_OPTS_NAME_SC_selfExport='VALET_EXPORT_ALL' -CMD_OPTS_NAME_SC_selfMock1='' -CMD_OPTS_NAME_SC_selfMock2='' -CMD_OPTS_NAME_SC_selfMock3='' -CMD_OPTS_NAME_SC_selfMock4='' -CMD_OPTS_NAME_SC_selfRelease='VALET_GITHUB_RELEASE_TOKEN' -CMD_OPTS_NAME_SC_selfSetup='' -CMD_OPTS_NAME_SC_selfTest='VALET_USER_DIRECTORY' -CMD_OPTS_NAME_SC_selfUpdate='' -CMD_OPTS_NAME_SC_showCommandHelp='VALET_NO_COLORS' -CMD_OPTS_NAME_SC_this='VALET_PROFILING' -CMD_OPTS_NAME__menu='help' -CMD_OPTS_NAME_selfBuild='userDirectory' -CMD_OPTS_NAME_selfConfig='noEdit' -CMD_OPTS_NAME_selfExport='exportAll' -CMD_OPTS_NAME_selfMock1='help' -CMD_OPTS_NAME_selfMock2='option1' -CMD_OPTS_NAME_selfMock3='help' -CMD_OPTS_NAME_selfMock4='help' -CMD_OPTS_NAME_selfRelease='githubReleaseToken' -CMD_OPTS_NAME_selfSetup='help' -CMD_OPTS_NAME_selfTest='userDirectory' -CMD_OPTS_NAME_selfUpdate='help' -CMD_OPTS_NAME_showCommandHelp='noColors' -CMD_OPTS_NAME_this='profiling' -CMD_OPTS__menu='-h --help' -CMD_OPTS_selfBuild='-d --user-directory' -CMD_OPTS_selfConfig='--no-edit' -CMD_OPTS_selfExport='-a --export-all' -CMD_OPTS_selfMock1='-h --help' -CMD_OPTS_selfMock2='-o --option1' -CMD_OPTS_selfMock3='-h --help' -CMD_OPTS_selfMock4='-h --help' -CMD_OPTS_selfRelease='-t --github-release-token' -CMD_OPTS_selfSetup='-h --help' -CMD_OPTS_selfTest='-d --user-directory' -CMD_OPTS_selfUpdate='-h --help' -CMD_OPTS_showCommandHelp='-n --no-colors' -CMD_OPTS_this='-x --profiling' +CMD_OPTIONS_NAME_selfBuild=0 "-d, --user-directory " 1 "-o, --output " 2 "-h, --help" +CMD_OPTIONS_NAME_selfConfig=0 "--no-edit" 1 "--override" 2 "--export-current-values" 3 "-h, --help" +CMD_OPTIONS_NAME_selfExport=0 "-a, --export-all" 1 "-h, --help" +CMD_OPTIONS_NAME_selfMock1=0 "-h, --help" +CMD_OPTIONS_NAME_selfMock2=0 "-o, --option1" 1 "-2, --this-is-option2 " 2 "-h, --help" +CMD_OPTIONS_NAME_selfMock3=0 "-h, --help" +CMD_OPTIONS_NAME_selfMock4=0 "-h, --help" +CMD_OPTIONS_NAME_selfRelease=0 "-t, --github-release-token " 1 "-b, --bump-level " 2 "--dry-run" 3 "--upload-artifacts-only" 4 "-h, --help" +CMD_OPTIONS_NAME_selfSetup=0 "-h, --help" +CMD_OPTIONS_NAME_selfTest=0 "-d, --user-directory " 1 "-a, --auto-approve" 2 "-c, --with-core" 3 "-C, --only-core" 4 "-i, --include " 5 "-e, --exclude " 6 "-h, --help" +CMD_OPTIONS_NAME_selfUpdate=0 "-h, --help" +CMD_OPTIONS_NAME_showCommandHelp=0 "-n, --no-colors" 1 "-c, --columns " 2 "-h, --help" +CMD_OPTIONS_NAME_this=0 "-x, --profiling" 1 "-l, --log-level, --log " 2 "-v, --verbose" 3 "-w, --very-verbose" 4 "-i, --force-interactive-mode" 5 "--version" 6 "-h, --help" +CMD_OPTS_DEFAULT_selfBuild=0 "" 1 "" 2 "" +CMD_OPTS_DEFAULT_selfConfig=0 "" 1 "" 2 "" 3 "" +CMD_OPTS_DEFAULT_selfExport=0 "" 1 "" +CMD_OPTS_DEFAULT_selfMock1=0 "" +CMD_OPTS_DEFAULT_selfMock2=0 "" 1 "" 2 "" +CMD_OPTS_DEFAULT_selfMock3=0 "" +CMD_OPTS_DEFAULT_selfMock4=0 "" +CMD_OPTS_DEFAULT_selfRelease=0 "" 1 "" 2 "" 3 "" 4 "" +CMD_OPTS_DEFAULT_selfSetup=0 "" +CMD_OPTS_DEFAULT_selfTest=0 "" 1 "" 2 "" 3 "" 4 "" 5 "" 6 "" +CMD_OPTS_DEFAULT_selfUpdate=0 "" +CMD_OPTS_DEFAULT_showCommandHelp=0 "" 1 "" 2 "" +CMD_OPTS_DEFAULT_this=0 "" 1 "" 2 "" 3 "" 4 "" 5 "" 6 "" +CMD_OPTS_HAS_VALUE_selfBuild=0 "true" 1 "true" 2 "false" +CMD_OPTS_HAS_VALUE_selfConfig=0 "false" 1 "false" 2 "false" 3 "false" +CMD_OPTS_HAS_VALUE_selfExport=0 "false" 1 "false" +CMD_OPTS_HAS_VALUE_selfMock1=0 "false" +CMD_OPTS_HAS_VALUE_selfMock2=0 "false" 1 "true" 2 "false" +CMD_OPTS_HAS_VALUE_selfMock3=0 "false" +CMD_OPTS_HAS_VALUE_selfMock4=0 "false" +CMD_OPTS_HAS_VALUE_selfRelease=0 "true" 1 "true" 2 "false" 3 "false" 4 "false" +CMD_OPTS_HAS_VALUE_selfSetup=0 "false" +CMD_OPTS_HAS_VALUE_selfTest=0 "true" 1 "false" 2 "false" 3 "false" 4 "true" 5 "true" 6 "false" +CMD_OPTS_HAS_VALUE_selfUpdate=0 "false" +CMD_OPTS_HAS_VALUE_showCommandHelp=0 "false" 1 "true" 2 "false" +CMD_OPTS_HAS_VALUE_this=0 "false" 1 "true" 2 "false" 3 "false" 4 "false" 5 "false" 6 "false" +CMD_OPTS_NAME_SC_selfBuild=0 "VALET_USER_DIRECTORY" 1 "VALET_OUTPUT" 2 "" +CMD_OPTS_NAME_SC_selfConfig=0 "VALET_NO_EDIT" 1 "VALET_OVERRIDE" 2 "VALET_EXPORT_CURRENT_VALUES" 3 "" +CMD_OPTS_NAME_SC_selfExport=0 "VALET_EXPORT_ALL" 1 "" +CMD_OPTS_NAME_SC_selfMock1=0 "" +CMD_OPTS_NAME_SC_selfMock2=0 "" 1 "VALET_THIS_IS_OPTION2" 2 "" +CMD_OPTS_NAME_SC_selfMock3=0 "" +CMD_OPTS_NAME_SC_selfMock4=0 "" +CMD_OPTS_NAME_SC_selfRelease=0 "VALET_GITHUB_RELEASE_TOKEN" 1 "VALET_BUMP_LEVEL" 2 "VALET_DRY_RUN" 3 "VALET_UPLOAD_ARTIFACTS_ONLY" 4 "" +CMD_OPTS_NAME_SC_selfSetup=0 "" +CMD_OPTS_NAME_SC_selfTest=0 "VALET_USER_DIRECTORY" 1 "VALET_AUTO_APPROVE" 2 "VALET_WITH_CORE" 3 "VALET_ONLY_CORE" 4 "VALET_INCLUDE" 5 "VALET_EXCLUDE" 6 "" +CMD_OPTS_NAME_SC_selfUpdate=0 "" +CMD_OPTS_NAME_SC_showCommandHelp=0 "VALET_NO_COLORS" 1 "VALET_COLUMNS" 2 "" +CMD_OPTS_NAME_SC_this=0 "VALET_PROFILING" 1 "VALET_LOG_LEVEL" 2 "VALET_VERBOSE" 3 "VALET_VERY_VERBOSE" 4 "VALET_FORCE_INTERACTIVE_MODE" 5 "" 6 "" +CMD_OPTS_NAME__menu=0 "help" +CMD_OPTS_NAME_selfBuild=0 "userDirectory" 1 "output" 2 "help" +CMD_OPTS_NAME_selfConfig=0 "noEdit" 1 "override" 2 "exportCurrentValues" 3 "help" +CMD_OPTS_NAME_selfExport=0 "exportAll" 1 "help" +CMD_OPTS_NAME_selfMock1=0 "help" +CMD_OPTS_NAME_selfMock2=0 "option1" 1 "thisIsOption2" 2 "help" +CMD_OPTS_NAME_selfMock3=0 "help" +CMD_OPTS_NAME_selfMock4=0 "help" +CMD_OPTS_NAME_selfRelease=0 "githubReleaseToken" 1 "bumpLevel" 2 "dryRun" 3 "uploadArtifactsOnly" 4 "help" +CMD_OPTS_NAME_selfSetup=0 "help" +CMD_OPTS_NAME_selfTest=0 "userDirectory" 1 "autoApprove" 2 "withCore" 3 "onlyCore" 4 "include" 5 "exclude" 6 "help" +CMD_OPTS_NAME_selfUpdate=0 "help" +CMD_OPTS_NAME_showCommandHelp=0 "noColors" 1 "columns" 2 "help" +CMD_OPTS_NAME_this=0 "profiling" 1 "logLevel" 2 "verbose" 3 "veryVerbose" 4 "forceInteractiveMode" 5 "version" 6 "help" +CMD_OPTS__menu=0 "-h --help" +CMD_OPTS_selfBuild=0 "-d --user-directory" 1 "-o --output" 2 "-h --help" +CMD_OPTS_selfConfig=0 "--no-edit" 1 "--override" 2 "--export-current-values" 3 "-h --help" +CMD_OPTS_selfExport=0 "-a --export-all" 1 "-h --help" +CMD_OPTS_selfMock1=0 "-h --help" +CMD_OPTS_selfMock2=0 "-o --option1" 1 "-2 --this-is-option2" 2 "-h --help" +CMD_OPTS_selfMock3=0 "-h --help" +CMD_OPTS_selfMock4=0 "-h --help" +CMD_OPTS_selfRelease=0 "-t --github-release-token" 1 "-b --bump-level" 2 "--dry-run" 3 "--upload-artifacts-only" 4 "-h --help" +CMD_OPTS_selfSetup=0 "-h --help" +CMD_OPTS_selfTest=0 "-d --user-directory" 1 "-a --auto-approve" 2 "-c --with-core" 3 "-C --only-core" 4 "-i --include" 5 "-e --exclude" 6 "-h --help" +CMD_OPTS_selfUpdate=0 "-h --help" +CMD_OPTS_showCommandHelp=0 "-n --no-colors" 1 "-c --columns" 2 "-h --help" +CMD_OPTS_this=0 "-x --profiling" 1 "-l --log-level --log" 2 "-v --verbose" 3 "-w --very-verbose" 4 "-i --force-interactive-mode" 5 "--version" 6 "-h --help" CMD_SHORT_DESCRIPTION_selfBuild='Re-build the menu of valet from your commands.' CMD_SHORT_DESCRIPTION_selfConfig='Open the configuration file of Valet with your default editor.' CMD_SHORT_DESCRIPTION_selfExport='Returns a string that can be evaluated to have Valet functions in bash.' @@ -240,7 +253,7 @@ INFO Extracting commands from ⌜$GLOBAL_VALET_HOME/valet.d/commands.d/self- INFO β”œβ”€β”€ ⌜self test⌝. INFO == Summary of the commands == -- Number of variables declared: ⌜199⌝. +- Number of variables declared: ⌜212⌝. - Number of functions: ⌜13⌝. - Number of commands: ⌜12⌝. - Maximum sub command level: ⌜1⌝. diff --git a/tests.d/1103-self-release/results.approved.md b/tests.d/1103-self-release/results.approved.md index 805943b..a715eec 100644 --- a/tests.d/1103-self-release/results.approved.md +++ b/tests.d/1103-self-release/results.approved.md @@ -53,6 +53,7 @@ DEBUG Parsed arguments: local parsingErrors githubReleaseToken bumpLevel dryRun uploadArtifactsOnly help dryRun="${VALET_DRY_RUN:-}" uploadArtifactsOnly="${VALET_UPLOAD_ARTIFACTS_ONLY:-}" +help="" parsingErrors="" githubReleaseToken="token" bumpLevel="minor" @@ -184,6 +185,7 @@ INFO Found 98 functions with documentation. β–Ά called io::invoke rm -f $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/io.md β–Ά called io::invoke rm -f $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/kurl.md β–Ά called io::invoke rm -f $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/log.md +β–Ά called io::invoke rm -f $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/profiler.md β–Ά called io::invoke rm -f $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/string.md β–Ά called io::invoke rm -f $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/system.md β–Ά called io::invoke rm -f $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/test.md @@ -257,7 +259,6 @@ INFO Found 98 functions with documentation. β–Ά called io::writeToFile $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/string.md β–Ά called io::writeToFileFromRef $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/core.md β–Ά called io::writeToFile $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/core.md -β–Ά called io::writeToFile $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/profiler.md β–Ά called io::writeToFileFromRef $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/profiler.md β–Ά called io::writeToFile $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/profiler.md β–Ά called io::writeToFileFromRef $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/log.md @@ -342,7 +343,6 @@ INFO Found 98 functions with documentation. β–Ά called io::writeToFile $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/string.md β–Ά called io::writeToFileFromRef $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/system.md β–Ά called io::writeToFile $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/system.md -β–Ά called io::writeToFile $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/profiler.md β–Ά called io::writeToFileFromRef $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/profiler.md β–Ά called io::writeToFile $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/profiler.md β–Ά called io::writeToFileFromRef $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/kurl.md @@ -393,6 +393,7 @@ INFO Found 98 functions with documentation. β–Ά called io::writeToFile $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/io.md β–Ά called io::writeToFile $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/kurl.md β–Ά called io::writeToFile $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/log.md +β–Ά called io::writeToFile $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/profiler.md β–Ά called io::writeToFile $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/string.md β–Ά called io::writeToFile $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/system.md β–Ά called io::writeToFile $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/test.md @@ -400,7 +401,7 @@ INFO Found 98 functions with documentation. β–Ά called io::writeToFile $GLOBAL_VALET_HOME/extras/valet.code-snippets β–Ά called io::writeToFile $GLOBAL_VALET_HOME/docs/static/config.md β–Ά called io::invoke git add $GLOBAL_VALET_HOME/docs/static/config.md -β–Ά called io::invoke git add $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/array.md $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/codes.md $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/core.md $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/fsfs.md $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/interactive.md $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/io.md $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/kurl.md $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/log.md $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/string.md $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/system.md $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/test.md +β–Ά called io::invoke git add $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/array.md $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/codes.md $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/core.md $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/fsfs.md $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/interactive.md $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/io.md $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/kurl.md $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/log.md $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/profiler.md $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/string.md $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/system.md $GLOBAL_VALET_HOME/docs/content/docs/300.libraries/test.md β–Ά called io::invoke git add $GLOBAL_VALET_HOME/extras/all-valet-functions.sh $GLOBAL_VALET_HOME/extras/valet.code-snippets β–Ά called io::invoke git commit -m :memo: updating the documentation SUCCESS The documentation update has been committed. diff --git a/tests.d/1300-valet-cli/results.approved.md b/tests.d/1300-valet-cli/results.approved.md index 2e546e1..086807c 100644 --- a/tests.d/1300-valet-cli/results.approved.md +++ b/tests.d/1300-valet-cli/results.approved.md @@ -552,6 +552,7 @@ DEBUG Loaded file ⌜$GLOBAL_VALET_HOME/valet.d/commands.d/self-mock.sh⌝. DEBUG Running the command ⌜self mock1⌝ with the function ⌜selfMock1⌝ and the arguments ⌜logging-level⌝. DEBUG Parsed arguments: local parsingErrors help action +help="" parsingErrors="" action="logging-level" @@ -585,6 +586,7 @@ DEBUG Loaded file ⌜$GLOBAL_VALET_HOME/valet.d/commands.d/self-mock.sh⌝. DEBUG Running the command ⌜self mock1⌝ with the function ⌜selfMock1⌝ and the arguments ⌜logging-level⌝. DEBUG Parsed arguments: local parsingErrors help action +help="" parsingErrors="" action="logging-level" diff --git a/tests.d/1301-profiler/results.approved.md b/tests.d/1301-profiler/results.approved.md index 31a2687..e2f0993 100644 --- a/tests.d/1301-profiler/results.approved.md +++ b/tests.d/1301-profiler/results.approved.md @@ -24,7 +24,9 @@ D I S timer delta source:line function 00 00 00 0.0XXX 0.0XXX self-mock.sh:170 selfMock2() β†’ core::parseArguments arg1 arg2 00 00 00 0.0XXX 0.0XXX self-mock.sh:170 selfMock2() β†’ eval 'local parsingErrors option1 thisIsOption2 help firstArg local -a more + option1="" thisIsOption2="${VALET_THIS_IS_OPTION2:-}" + help="" parsingErrors="" firstArg="arg1" more=( @@ -32,10 +34,12 @@ D I S timer delta source:line function )' 00 00 00 0.0XXX 0.0XXX self-mock.sh:170 selfMock2() β†’ local parsingErrors option1 thisIsOption2 help firstArg 00 00 00 0.0XXX 0.0XXX self-mock.sh:171 selfMock2() β†’ local -a more -00 00 00 0.0XXX 0.0XXX self-mock.sh:172 selfMock2() β†’ thisIsOption2= -00 00 00 0.0XXX 0.0XXX self-mock.sh:173 selfMock2() β†’ parsingErrors= -00 00 00 0.0XXX 0.0XXX self-mock.sh:174 selfMock2() β†’ firstArg=arg1 -00 00 00 0.0XXX 0.0XXX self-mock.sh:177 selfMock2() β†’ more=("arg2") +00 00 00 0.0XXX 0.0XXX self-mock.sh:172 selfMock2() β†’ option1= +00 00 00 0.0XXX 0.0XXX self-mock.sh:173 selfMock2() β†’ thisIsOption2= +00 00 00 0.0XXX 0.0XXX self-mock.sh:174 selfMock2() β†’ help= +00 00 00 0.0XXX 0.0XXX self-mock.sh:175 selfMock2() β†’ parsingErrors= +00 00 00 0.0XXX 0.0XXX self-mock.sh:176 selfMock2() β†’ firstArg=arg1 +00 00 00 0.0XXX 0.0XXX self-mock.sh:179 selfMock2() β†’ more=("arg2") 00 00 00 0.0XXX 0.0XXX self-mock.sh:171 selfMock2() β†’ core::checkParseResults '' '' 00 00 00 0.0XXX 0.0XXX self-mock.sh:173 selfMock2() β†’ log::info 'First argument: arg1.' 00 00 00 0.0XXX 0.0XXX self-mock.sh:174 selfMock2() β†’ log::info 'Option 1: .' @@ -76,7 +80,9 @@ D I S timer delta source:line function 00 00 00 0.0XXX 0.0XXX self-mock.sh:170 selfMock2() β†’ core::parseArguments arg1 arg2 00 00 00 0.0XXX 0.0XXX self-mock.sh:170 selfMock2() β†’ eval 'local parsingErrors option1 thisIsOption2 help firstArg local -a more + option1="" thisIsOption2="${VALET_THIS_IS_OPTION2:-}" + help="" parsingErrors="" firstArg="arg1" more=( @@ -84,10 +90,12 @@ D I S timer delta source:line function )' 00 00 00 0.0XXX 0.0XXX self-mock.sh:170 selfMock2() β†’ local parsingErrors option1 thisIsOption2 help firstArg 00 00 00 0.0XXX 0.0XXX self-mock.sh:171 selfMock2() β†’ local -a more -00 00 00 0.0XXX 0.0XXX self-mock.sh:172 selfMock2() β†’ thisIsOption2= -00 00 00 0.0XXX 0.0XXX self-mock.sh:173 selfMock2() β†’ parsingErrors= -00 00 00 0.0XXX 0.0XXX self-mock.sh:174 selfMock2() β†’ firstArg=arg1 -00 00 00 0.0XXX 0.0XXX self-mock.sh:177 selfMock2() β†’ more=("arg2") +00 00 00 0.0XXX 0.0XXX self-mock.sh:172 selfMock2() β†’ option1= +00 00 00 0.0XXX 0.0XXX self-mock.sh:173 selfMock2() β†’ thisIsOption2= +00 00 00 0.0XXX 0.0XXX self-mock.sh:174 selfMock2() β†’ help= +00 00 00 0.0XXX 0.0XXX self-mock.sh:175 selfMock2() β†’ parsingErrors= +00 00 00 0.0XXX 0.0XXX self-mock.sh:176 selfMock2() β†’ firstArg=arg1 +00 00 00 0.0XXX 0.0XXX self-mock.sh:179 selfMock2() β†’ more=("arg2") 00 00 00 0.0XXX 0.0XXX self-mock.sh:171 selfMock2() β†’ core::checkParseResults '' '' 00 00 00 0.0XXX 0.0XXX self-mock.sh:173 selfMock2() β†’ log::info 'First argument: arg1.' 00 00 00 0.0XXX 0.0XXX self-mock.sh:174 selfMock2() β†’ log::info 'Option 1: .' diff --git a/valet.d/commands.d/self-build-utils b/valet.d/commands.d/self-build-utils index 710e2d8..6ffcb47 100644 --- a/valet.d/commands.d/self-build-utils +++ b/valet.d/commands.d/self-build-utils @@ -276,15 +276,14 @@ _CMD_INCLUDED=1 # CMD_OPTS_HAS_VALUE_xxx = array which indicates for each option if it has a value or not # CMD_OPTS_NAME_xxx = array with each option names in camel case # CMD_OPTS_NAME_SC_xxx = array with each option names in snake case +# CMD_OPTS_DEFAULT_xxx = contains the default value for this option # CMD_ARGS_NAME_xxx = array with each argument names in camel case # CMD_ARGS_LAST_IS_ARRAY_xxx = true/false to indicate if the last argument of the function is an array (contains ...) # CMD_ARGS_NB_OPTIONAL_xxx = integer to indicate the number of optional arguments (contains ?) " io::invoke declare -p ${!CMD_*} - local IFS=$'\n' local line - local IFS=':' while read -r -d $'\n' line; do printf '%s\n' "${line#declare -? }" done <<< "${RETURNED_VALUE}" diff --git a/valet.d/commands.d/self-build.sh b/valet.d/commands.d/self-build.sh index fbcd713..6995e13 100644 --- a/valet.d/commands.d/self-build.sh +++ b/valet.d/commands.d/self-build.sh @@ -251,7 +251,7 @@ function extractCommandDefinitionsToVariables() { TEMP_CMD_BUILD_fileToSource="${TEMP_CMD_BUILD_fileToSource#"${GLOBAL_VALET_HOME}"/}" # make sure that all these arrays exists and have the same size - array::makeArraysSameSize TEMP_CMD_BUILD_options_name TEMP_CMD_BUILD_options_description TEMP_CMD_BUILD_options_noEnvironmentVariable + array::makeArraysSameSize TEMP_CMD_BUILD_options_name TEMP_CMD_BUILD_options_description TEMP_CMD_BUILD_options_noEnvironmentVariable TEMP_CMD_BUILD_options_default array::makeArraysSameSize TEMP_CMD_BUILD_arguments_name TEMP_CMD_BUILD_arguments_description array::makeArraysSameSize TEMP_CMD_BUILD_examples_name TEMP_CMD_BUILD_examples_description @@ -406,10 +406,13 @@ function declareFinalCommandDefinitionHelpVariables() { } # Declare the following variables: +# # CMD_OPTS_xxx = array with each option separated by a space # CMD_OPTS_HAS_VALUE_xxx = array which indicates for each option if it has a value or not # CMD_OPTS_NAME_xxx = array with each option names in camel case # CMD_OPTS_NAME_SC_xxx = array with each option names in snake case +# CMD_OPTS_DEFAULT_xxx = contains the default value for this option +# # CMD_ARGS_NAME_xxx = array with each argument names in camel case # CMD_ARGS_LAST_IS_ARRAY_xxx = true/false to indicate if the last argument of the function is an array (contains with ...) # CMD_ARGS_NB_OPTIONAL_xxx = integer to indicate the number of optional arguments (contains ?) @@ -442,6 +445,7 @@ function declareFinalCommandDefinitionParserVariables() { eval "CMD_OPTS_HAS_VALUE_${function}+=(\"${optionHasValue}\")" eval "CMD_OPTS_NAME_${function}+=(\"${optionNameCc}\")" eval "CMD_OPTS_NAME_SC_${function}+=(\"${optionNameSc}\")" + eval "CMD_OPTS_DEFAULT_${function}+=(\"${TEMP_CMD_BUILD_options_default[index]:-}\")" done # for each arguments diff --git a/valet.d/main b/valet.d/main index ebfa040..5bb48b3 100644 --- a/valet.d/main +++ b/valet.d/main @@ -903,6 +903,7 @@ function main::parseFunctionArguments() { local -n optionsHasValue="CMD_OPTS_HAS_VALUE_${functionName}" local -n optionsName="CMD_OPTS_NAME_${functionName}" local -n optionsNameSc="CMD_OPTS_NAME_SC_${functionName}" + local -n optionsDefault="CMD_OPTS_DEFAULT_${functionName}" # shortcut if the function expect no arguments and no options if [[ totalNbArguments -eq 0 && totalNbOptions -eq 0 ]]; then @@ -1017,7 +1018,7 @@ function main::parseFunctionArguments() { fi # assign all unmatched options to the corresponding global variable - local optionIndex optionName optionMatched matchedIndex optionNameSc + local optionIndex optionName optionMatched matchedIndex optionNameSc optionDefault for optionIndex in "${!options[@]}"; do optionMatched="false" for matchedIndex in "${matchedOptionsIndex[@]}"; do @@ -1029,8 +1030,14 @@ function main::parseFunctionArguments() { if [[ ${optionMatched} == "false" ]]; then optionName="${optionsName[${optionIndex}]}" optionNameSc="${optionsNameSc[${optionIndex}]:-}" + optionDefault="${optionsDefault[${optionIndex}]:-}" if [[ -n "${optionNameSc}" ]]; then - outputString+="${optionsName[${optionIndex}]}=\"\${${optionNameSc}:-}\""$'\n' + if [[ -n "${optionDefault}" ]]; then + optionDefault="\"${optionDefault}\"" + fi + outputString+="${optionsName[${optionIndex}]}=\"\${${optionNameSc}:-${optionDefault}}\""$'\n' + else + outputString+="${optionsName[${optionIndex}]}=\"${optionDefault}\""$'\n' fi fi done diff --git a/valet.d/version b/valet.d/version index fbe4413..7d27d1b 100644 --- a/valet.d/version +++ b/valet.d/version @@ -1 +1 @@ -0.18.146 \ No newline at end of file +0.18.226 \ No newline at end of file