@bemoje/cli 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +5 -0
- package/.swcrc +32 -0
- package/dist/cjs/arg/ArgumentBuilder.js +45 -0
- package/dist/cjs/arg/ArgumentBuilder.js.map +1 -0
- package/dist/cjs/arg/ArgumentParserSelector.js +15 -0
- package/dist/cjs/arg/ArgumentParserSelector.js.map +1 -0
- package/dist/cjs/arg/ArgumentReader.js +38 -0
- package/dist/cjs/arg/ArgumentReader.js.map +1 -0
- package/dist/cjs/arg/ArgumentValidatorSelector.js +16 -0
- package/dist/cjs/arg/ArgumentValidatorSelector.js.map +1 -0
- package/dist/cjs/cmd/CLI.js +16 -0
- package/dist/cjs/cmd/CLI.js.map +1 -0
- package/dist/cjs/cmd/CommandBuilder.js +1098 -0
- package/dist/cjs/cmd/CommandBuilder.js.map +1 -0
- package/dist/cjs/cmd/CommandBuilderMetaData.js +43 -0
- package/dist/cjs/cmd/CommandBuilderMetaData.js.map +1 -0
- package/dist/cjs/cmd/CommandFeatureSelector.js +112 -0
- package/dist/cjs/cmd/CommandFeatureSelector.js.map +1 -0
- package/dist/cjs/cmd/DefaultHelpConfig.js +141 -0
- package/dist/cjs/cmd/DefaultHelpConfig.js.map +1 -0
- package/dist/cjs/cmd/asdas.js +27 -0
- package/dist/cjs/cmd/asdas.js.map +1 -0
- package/dist/cjs/core/OutputManager.js +99 -0
- package/dist/cjs/core/OutputManager.js.map +1 -0
- package/dist/cjs/core/ParserSelector.js +36 -0
- package/dist/cjs/core/ParserSelector.js.map +1 -0
- package/dist/cjs/core/ValidatorSelector.js +36 -0
- package/dist/cjs/core/ValidatorSelector.js.map +1 -0
- package/dist/cjs/core/splitCombinedArgvShorts.js +15 -0
- package/dist/cjs/core/splitCombinedArgvShorts.js.map +1 -0
- package/dist/cjs/db/AbstractJsonFileSection.js +190 -0
- package/dist/cjs/db/AbstractJsonFileSection.js.map +1 -0
- package/dist/cjs/db/AppDataSection.js +48 -0
- package/dist/cjs/db/AppDataSection.js.map +1 -0
- package/dist/cjs/db/ConfigSection.js +71 -0
- package/dist/cjs/db/ConfigSection.js.map +1 -0
- package/dist/cjs/db/JsonFile.js +55 -0
- package/dist/cjs/db/JsonFile.js.map +1 -0
- package/dist/cjs/db/PresetsSection.js +92 -0
- package/dist/cjs/db/PresetsSection.js.map +1 -0
- package/dist/cjs/index.js +120 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/opt/OptionArgumentParserSelector.js +16 -0
- package/dist/cjs/opt/OptionArgumentParserSelector.js.map +1 -0
- package/dist/cjs/opt/OptionArgumentValidatorSelector.js +19 -0
- package/dist/cjs/opt/OptionArgumentValidatorSelector.js.map +1 -0
- package/dist/cjs/opt/OptionBuilder.js +88 -0
- package/dist/cjs/opt/OptionBuilder.js.map +1 -0
- package/dist/cjs/opt/OptionHelpers.js +57 -0
- package/dist/cjs/opt/OptionHelpers.js.map +1 -0
- package/dist/cjs/opt/OptionReader.js +66 -0
- package/dist/cjs/opt/OptionReader.js.map +1 -0
- package/dist/cjs/proto/overrideCommanderPrototype.js +37 -0
- package/dist/cjs/proto/overrideCommanderPrototype.js.map +1 -0
- package/dist/cjs/types/IConfig.js +3 -0
- package/dist/cjs/types/IConfig.js.map +1 -0
- package/dist/cjs/types/IPreset.js +3 -0
- package/dist/cjs/types/IPreset.js.map +1 -0
- package/dist/cjs/util/array/arrLast.js +21 -0
- package/dist/cjs/util/array/arrLast.js.map +1 -0
- package/dist/cjs/util/array/arrSome.js +26 -0
- package/dist/cjs/util/array/arrSome.js.map +1 -0
- package/dist/cjs/util/array/types/ArrayPredicate.js +3 -0
- package/dist/cjs/util/array/types/ArrayPredicate.js.map +1 -0
- package/dist/cjs/util/db/JsonDB.js +145 -0
- package/dist/cjs/util/db/JsonDB.js.map +1 -0
- package/dist/cjs/util/errors/ErrorParser.js +164 -0
- package/dist/cjs/util/errors/ErrorParser.js.map +1 -0
- package/dist/cjs/util/fs/promptUserEditInTextEditor/IGetUserInputFromEditorOptions.js +3 -0
- package/dist/cjs/util/fs/promptUserEditInTextEditor/IGetUserInputFromEditorOptions.js.map +1 -0
- package/dist/cjs/util/fs/promptUserEditInTextEditor/promptUserEditInTextEditorSync.js +32 -0
- package/dist/cjs/util/fs/promptUserEditInTextEditor/promptUserEditInTextEditorSync.js.map +1 -0
- package/dist/cjs/util/fs/promptUserEditInTextEditor/promptUserEditJsonInTextEditorSync.js +25 -0
- package/dist/cjs/util/fs/promptUserEditInTextEditor/promptUserEditJsonInTextEditorSync.js.map +1 -0
- package/dist/cjs/util/fs/readFile/readFileSafeSync.js +28 -0
- package/dist/cjs/util/fs/readFile/readFileSafeSync.js.map +1 -0
- package/dist/cjs/util/fs/readFile/readFileSync.js +20 -0
- package/dist/cjs/util/fs/readFile/readFileSync.js.map +1 -0
- package/dist/cjs/util/fs/readJsonFile/readJsonFileSafeSync.js +24 -0
- package/dist/cjs/util/fs/readJsonFile/readJsonFileSafeSync.js.map +1 -0
- package/dist/cjs/util/fs/removeFile/removeFile.js +6 -0
- package/dist/cjs/util/fs/removeFile/removeFile.js.map +1 -0
- package/dist/cjs/util/fs/tempFile/tempFileSync.js +28 -0
- package/dist/cjs/util/fs/tempFile/tempFileSync.js.map +1 -0
- package/dist/cjs/util/fs/types/IReadJsonFileOptions.js +3 -0
- package/dist/cjs/util/fs/types/IReadJsonFileOptions.js.map +1 -0
- package/dist/cjs/util/fs/writeFile/writeFileSafeSync.js +6 -0
- package/dist/cjs/util/fs/writeFile/writeFileSafeSync.js.map +1 -0
- package/dist/cjs/util/fs/writeFile/writeFileSync.js +6 -0
- package/dist/cjs/util/fs/writeFile/writeFileSync.js.map +1 -0
- package/dist/cjs/util/fs/writeJsonFile/writeJsonFileSafe.js +6 -0
- package/dist/cjs/util/fs/writeJsonFile/writeJsonFileSafe.js.map +1 -0
- package/dist/cjs/util/function/MethodDisabler.js +94 -0
- package/dist/cjs/util/function/MethodDisabler.js.map +1 -0
- package/dist/cjs/util/function/funSetName.js +21 -0
- package/dist/cjs/util/function/funSetName.js.map +1 -0
- package/dist/cjs/util/node/execInherit.js +19 -0
- package/dist/cjs/util/node/execInherit.js.map +1 -0
- package/dist/cjs/util/node/formatTableForTerminal.js +21 -0
- package/dist/cjs/util/node/formatTableForTerminal.js.map +1 -0
- package/dist/cjs/util/object/arrAssign.js +6 -0
- package/dist/cjs/util/object/arrAssign.js.map +1 -0
- package/dist/cjs/util/object/createArrayMerger.js +20 -0
- package/dist/cjs/util/object/createArrayMerger.js.map +1 -0
- package/dist/cjs/util/object/createObjectMerger.js +20 -0
- package/dist/cjs/util/object/createObjectMerger.js.map +1 -0
- package/dist/cjs/util/object/objAssign.js +6 -0
- package/dist/cjs/util/object/objAssign.js.map +1 -0
- package/dist/cjs/util/object/objUpdatePropertyDescriptors.js +28 -0
- package/dist/cjs/util/object/objUpdatePropertyDescriptors.js.map +1 -0
- package/dist/cjs/util/object/realizeLazyProperty.js +14 -0
- package/dist/cjs/util/object/realizeLazyProperty.js.map +1 -0
- package/dist/cjs/util/object/setNonEnumerable.js +25 -0
- package/dist/cjs/util/object/setNonEnumerable.js.map +1 -0
- package/dist/cjs/util/os/defaultOpenInEditorCommand.js +18 -0
- package/dist/cjs/util/os/defaultOpenInEditorCommand.js.map +1 -0
- package/dist/cjs/util/os/isOSX.js +13 -0
- package/dist/cjs/util/os/isOSX.js.map +1 -0
- package/dist/cjs/util/os/isVsCodeInstalled.js +19 -0
- package/dist/cjs/util/os/isVsCodeInstalled.js.map +1 -0
- package/dist/cjs/util/os/isWindows.js +16 -0
- package/dist/cjs/util/os/isWindows.js.map +1 -0
- package/dist/cjs/util/path/getTempDataPath.js +20 -0
- package/dist/cjs/util/path/getTempDataPath.js.map +1 -0
- package/dist/cjs/util/regex/regexEscapeString.js +18 -0
- package/dist/cjs/util/regex/regexEscapeString.js.map +1 -0
- package/dist/cjs/util/string/strEnsureStartsWith.js +19 -0
- package/dist/cjs/util/string/strEnsureStartsWith.js.map +1 -0
- package/dist/cjs/util/string/strFirstCharToUpperCase.js +16 -0
- package/dist/cjs/util/string/strFirstCharToUpperCase.js.map +1 -0
- package/dist/cjs/util/string/strIsLowerCase.js +18 -0
- package/dist/cjs/util/string/strIsLowerCase.js.map +1 -0
- package/dist/cjs/util/string/strIsUpperCase.js +18 -0
- package/dist/cjs/util/string/strIsUpperCase.js.map +1 -0
- package/dist/cjs/util/string/strSplitCamelCase.js +55 -0
- package/dist/cjs/util/string/strSplitCamelCase.js.map +1 -0
- package/dist/cjs/util/string-parsers/createBooleanParser.js +21 -0
- package/dist/cjs/util/string-parsers/createBooleanParser.js.map +1 -0
- package/dist/cjs/util/string-parsers/createTypedListParser.js +22 -0
- package/dist/cjs/util/string-parsers/createTypedListParser.js.map +1 -0
- package/dist/cjs/util/string-parsers/parseBoolean.js +15 -0
- package/dist/cjs/util/string-parsers/parseBoolean.js.map +1 -0
- package/dist/cjs/util/string-parsers/parseInteger.js +17 -0
- package/dist/cjs/util/string-parsers/parseInteger.js.map +1 -0
- package/dist/cjs/util/string-parsers/parseNumber.js +13 -0
- package/dist/cjs/util/string-parsers/parseNumber.js.map +1 -0
- package/dist/cjs/util/string-parsers/parseString.js +8 -0
- package/dist/cjs/util/string-parsers/parseString.js.map +1 -0
- package/dist/cjs/util/types/Any.js +3 -0
- package/dist/cjs/util/types/Any.js.map +1 -0
- package/dist/cjs/util/types/DeepArray.js +3 -0
- package/dist/cjs/util/types/DeepArray.js.map +1 -0
- package/dist/cjs/util/types/DeepObject.js +3 -0
- package/dist/cjs/util/types/DeepObject.js.map +1 -0
- package/dist/cjs/util/types/JsonArray.js +3 -0
- package/dist/cjs/util/types/JsonArray.js.map +1 -0
- package/dist/cjs/util/types/JsonDefinedPrimitive.js +6 -0
- package/dist/cjs/util/types/JsonDefinedPrimitive.js.map +1 -0
- package/dist/cjs/util/types/JsonObject.js +3 -0
- package/dist/cjs/util/types/JsonObject.js.map +1 -0
- package/dist/cjs/util/types/JsonRawPrimitive.js +3 -0
- package/dist/cjs/util/types/JsonRawPrimitive.js.map +1 -0
- package/dist/cjs/util/types/JsonValue.js +3 -0
- package/dist/cjs/util/types/JsonValue.js.map +1 -0
- package/dist/cjs/util/types/ObjectKey.js +3 -0
- package/dist/cjs/util/types/ObjectKey.js.map +1 -0
- package/dist/cjs/util/types/TConstructor.js +3 -0
- package/dist/cjs/util/types/TConstructor.js.map +1 -0
- package/dist/cjs/util/types/TFunction.js +3 -0
- package/dist/cjs/util/types/TFunction.js.map +1 -0
- package/dist/cjs/util/types/TFunctionNoNew.js +3 -0
- package/dist/cjs/util/types/TFunctionNoNew.js.map +1 -0
- package/dist/cjs/util/types/TPlainObject.js +3 -0
- package/dist/cjs/util/types/TPlainObject.js.map +1 -0
- package/dist/cjs/util/types/TPrimitive.js +3 -0
- package/dist/cjs/util/types/TPrimitive.js.map +1 -0
- package/dist/cjs/util/types/TStringParser.js +3 -0
- package/dist/cjs/util/types/TStringParser.js.map +1 -0
- package/dist/cjs/util/types/TValidator.js +3 -0
- package/dist/cjs/util/types/TValidator.js.map +1 -0
- package/dist/cjs/util/validation/createTypedArrayValidator.js +26 -0
- package/dist/cjs/util/validation/createTypedArrayValidator.js.map +1 -0
- package/dist/cjs/util/validation/ensureThat.js +12 -0
- package/dist/cjs/util/validation/ensureThat.js.map +1 -0
- package/dist/cjs/util/validation/isArray.js +5 -0
- package/dist/cjs/util/validation/isArray.js.map +1 -0
- package/dist/cjs/util/validation/isBoolean.js +8 -0
- package/dist/cjs/util/validation/isBoolean.js.map +1 -0
- package/dist/cjs/util/validation/isFunction.js +17 -0
- package/dist/cjs/util/validation/isFunction.js.map +1 -0
- package/dist/cjs/util/validation/isNamedFunction.js +11 -0
- package/dist/cjs/util/validation/isNamedFunction.js.map +1 -0
- package/dist/cjs/util/validation/isNamedFunctionArray.js +9 -0
- package/dist/cjs/util/validation/isNamedFunctionArray.js.map +1 -0
- package/dist/cjs/util/validation/isObject.js +22 -0
- package/dist/cjs/util/validation/isObject.js.map +1 -0
- package/dist/cjs/util/validation/isPlainObject.js +19 -0
- package/dist/cjs/util/validation/isPlainObject.js.map +1 -0
- package/dist/cjs/util/validation/isPrimitive.js +18 -0
- package/dist/cjs/util/validation/isPrimitive.js.map +1 -0
- package/dist/cjs/util/validation/isString.js +8 -0
- package/dist/cjs/util/validation/isString.js.map +1 -0
- package/dist/cjs/util/validation/isStringArray.js +12 -0
- package/dist/cjs/util/validation/isStringArray.js.map +1 -0
- package/dist/cjs/util/validation/isStringWithNoSpacesOrDashes.js +9 -0
- package/dist/cjs/util/validation/isStringWithNoSpacesOrDashes.js.map +1 -0
- package/dist/cjs/util/validation/numbers/isInteger.js +17 -0
- package/dist/cjs/util/validation/numbers/isInteger.js.map +1 -0
- package/dist/cjs/util/validation/numbers/isValidNumber.js +22 -0
- package/dist/cjs/util/validation/numbers/isValidNumber.js.map +1 -0
- package/dist/esm/arg/ArgumentBuilder.js +41 -0
- package/dist/esm/arg/ArgumentBuilder.js.map +1 -0
- package/dist/esm/arg/ArgumentParserSelector.js +11 -0
- package/dist/esm/arg/ArgumentParserSelector.js.map +1 -0
- package/dist/esm/arg/ArgumentReader.js +34 -0
- package/dist/esm/arg/ArgumentReader.js.map +1 -0
- package/dist/esm/arg/ArgumentValidatorSelector.js +12 -0
- package/dist/esm/arg/ArgumentValidatorSelector.js.map +1 -0
- package/dist/esm/cmd/CLI.js +12 -0
- package/dist/esm/cmd/CLI.js.map +1 -0
- package/dist/esm/cmd/CommandBuilder.js +1091 -0
- package/dist/esm/cmd/CommandBuilder.js.map +1 -0
- package/dist/esm/cmd/CommandBuilderMetaData.js +39 -0
- package/dist/esm/cmd/CommandBuilderMetaData.js.map +1 -0
- package/dist/esm/cmd/CommandFeatureSelector.js +108 -0
- package/dist/esm/cmd/CommandFeatureSelector.js.map +1 -0
- package/dist/esm/cmd/DefaultHelpConfig.js +135 -0
- package/dist/esm/cmd/DefaultHelpConfig.js.map +1 -0
- package/dist/esm/cmd/asdas.js +25 -0
- package/dist/esm/cmd/asdas.js.map +1 -0
- package/dist/esm/core/OutputManager.js +92 -0
- package/dist/esm/core/OutputManager.js.map +1 -0
- package/dist/esm/core/ParserSelector.js +32 -0
- package/dist/esm/core/ParserSelector.js.map +1 -0
- package/dist/esm/core/ValidatorSelector.js +32 -0
- package/dist/esm/core/ValidatorSelector.js.map +1 -0
- package/dist/esm/core/splitCombinedArgvShorts.js +11 -0
- package/dist/esm/core/splitCombinedArgvShorts.js.map +1 -0
- package/dist/esm/db/AbstractJsonFileSection.js +186 -0
- package/dist/esm/db/AbstractJsonFileSection.js.map +1 -0
- package/dist/esm/db/AppDataSection.js +44 -0
- package/dist/esm/db/AppDataSection.js.map +1 -0
- package/dist/esm/db/ConfigSection.js +67 -0
- package/dist/esm/db/ConfigSection.js.map +1 -0
- package/dist/esm/db/JsonFile.js +51 -0
- package/dist/esm/db/JsonFile.js.map +1 -0
- package/dist/esm/db/PresetsSection.js +88 -0
- package/dist/esm/db/PresetsSection.js.map +1 -0
- package/dist/esm/index.js +104 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/opt/OptionArgumentParserSelector.js +12 -0
- package/dist/esm/opt/OptionArgumentParserSelector.js.map +1 -0
- package/dist/esm/opt/OptionArgumentValidatorSelector.js +15 -0
- package/dist/esm/opt/OptionArgumentValidatorSelector.js.map +1 -0
- package/dist/esm/opt/OptionBuilder.js +84 -0
- package/dist/esm/opt/OptionBuilder.js.map +1 -0
- package/dist/esm/opt/OptionHelpers.js +54 -0
- package/dist/esm/opt/OptionHelpers.js.map +1 -0
- package/dist/esm/opt/OptionReader.js +62 -0
- package/dist/esm/opt/OptionReader.js.map +1 -0
- package/dist/esm/proto/overrideCommanderPrototype.js +34 -0
- package/dist/esm/proto/overrideCommanderPrototype.js.map +1 -0
- package/dist/esm/types/IConfig.js +2 -0
- package/dist/esm/types/IConfig.js.map +1 -0
- package/dist/esm/types/IPreset.js +2 -0
- package/dist/esm/types/IPreset.js.map +1 -0
- package/dist/esm/util/array/arrLast.js +17 -0
- package/dist/esm/util/array/arrLast.js.map +1 -0
- package/dist/esm/util/array/arrSome.js +22 -0
- package/dist/esm/util/array/arrSome.js.map +1 -0
- package/dist/esm/util/array/types/ArrayPredicate.js +2 -0
- package/dist/esm/util/array/types/ArrayPredicate.js.map +1 -0
- package/dist/esm/util/db/JsonDB.js +141 -0
- package/dist/esm/util/db/JsonDB.js.map +1 -0
- package/dist/esm/util/errors/ErrorParser.js +154 -0
- package/dist/esm/util/errors/ErrorParser.js.map +1 -0
- package/dist/esm/util/fs/promptUserEditInTextEditor/IGetUserInputFromEditorOptions.js +2 -0
- package/dist/esm/util/fs/promptUserEditInTextEditor/IGetUserInputFromEditorOptions.js.map +1 -0
- package/dist/esm/util/fs/promptUserEditInTextEditor/promptUserEditInTextEditorSync.js +28 -0
- package/dist/esm/util/fs/promptUserEditInTextEditor/promptUserEditInTextEditorSync.js.map +1 -0
- package/dist/esm/util/fs/promptUserEditInTextEditor/promptUserEditJsonInTextEditorSync.js +21 -0
- package/dist/esm/util/fs/promptUserEditInTextEditor/promptUserEditJsonInTextEditorSync.js.map +1 -0
- package/dist/esm/util/fs/readFile/readFileSafeSync.js +21 -0
- package/dist/esm/util/fs/readFile/readFileSafeSync.js.map +1 -0
- package/dist/esm/util/fs/readFile/readFileSync.js +13 -0
- package/dist/esm/util/fs/readFile/readFileSync.js.map +1 -0
- package/dist/esm/util/fs/readJsonFile/readJsonFileSafeSync.js +17 -0
- package/dist/esm/util/fs/readJsonFile/readJsonFileSafeSync.js.map +1 -0
- package/dist/esm/util/fs/removeFile/removeFile.js +2 -0
- package/dist/esm/util/fs/removeFile/removeFile.js.map +1 -0
- package/dist/esm/util/fs/tempFile/tempFileSync.js +21 -0
- package/dist/esm/util/fs/tempFile/tempFileSync.js.map +1 -0
- package/dist/esm/util/fs/types/IReadJsonFileOptions.js +2 -0
- package/dist/esm/util/fs/types/IReadJsonFileOptions.js.map +1 -0
- package/dist/esm/util/fs/writeFile/writeFileSafeSync.js +2 -0
- package/dist/esm/util/fs/writeFile/writeFileSafeSync.js.map +1 -0
- package/dist/esm/util/fs/writeFile/writeFileSync.js +2 -0
- package/dist/esm/util/fs/writeFile/writeFileSync.js.map +1 -0
- package/dist/esm/util/fs/writeJsonFile/writeJsonFileSafe.js +2 -0
- package/dist/esm/util/fs/writeJsonFile/writeJsonFileSafe.js.map +1 -0
- package/dist/esm/util/function/MethodDisabler.js +90 -0
- package/dist/esm/util/function/MethodDisabler.js.map +1 -0
- package/dist/esm/util/function/funSetName.js +17 -0
- package/dist/esm/util/function/funSetName.js.map +1 -0
- package/dist/esm/util/node/execInherit.js +15 -0
- package/dist/esm/util/node/execInherit.js.map +1 -0
- package/dist/esm/util/node/formatTableForTerminal.js +14 -0
- package/dist/esm/util/node/formatTableForTerminal.js.map +1 -0
- package/dist/esm/util/object/arrAssign.js +3 -0
- package/dist/esm/util/object/arrAssign.js.map +1 -0
- package/dist/esm/util/object/createArrayMerger.js +16 -0
- package/dist/esm/util/object/createArrayMerger.js.map +1 -0
- package/dist/esm/util/object/createObjectMerger.js +16 -0
- package/dist/esm/util/object/createObjectMerger.js.map +1 -0
- package/dist/esm/util/object/objAssign.js +3 -0
- package/dist/esm/util/object/objAssign.js.map +1 -0
- package/dist/esm/util/object/objUpdatePropertyDescriptors.js +24 -0
- package/dist/esm/util/object/objUpdatePropertyDescriptors.js.map +1 -0
- package/dist/esm/util/object/realizeLazyProperty.js +10 -0
- package/dist/esm/util/object/realizeLazyProperty.js.map +1 -0
- package/dist/esm/util/object/setNonEnumerable.js +21 -0
- package/dist/esm/util/object/setNonEnumerable.js.map +1 -0
- package/dist/esm/util/os/defaultOpenInEditorCommand.js +14 -0
- package/dist/esm/util/os/defaultOpenInEditorCommand.js.map +1 -0
- package/dist/esm/util/os/isOSX.js +9 -0
- package/dist/esm/util/os/isOSX.js.map +1 -0
- package/dist/esm/util/os/isVsCodeInstalled.js +15 -0
- package/dist/esm/util/os/isVsCodeInstalled.js.map +1 -0
- package/dist/esm/util/os/isWindows.js +12 -0
- package/dist/esm/util/os/isWindows.js.map +1 -0
- package/dist/esm/util/path/getTempDataPath.js +13 -0
- package/dist/esm/util/path/getTempDataPath.js.map +1 -0
- package/dist/esm/util/regex/regexEscapeString.js +14 -0
- package/dist/esm/util/regex/regexEscapeString.js.map +1 -0
- package/dist/esm/util/string/strEnsureStartsWith.js +15 -0
- package/dist/esm/util/string/strEnsureStartsWith.js.map +1 -0
- package/dist/esm/util/string/strFirstCharToUpperCase.js +12 -0
- package/dist/esm/util/string/strFirstCharToUpperCase.js.map +1 -0
- package/dist/esm/util/string/strIsLowerCase.js +14 -0
- package/dist/esm/util/string/strIsLowerCase.js.map +1 -0
- package/dist/esm/util/string/strIsUpperCase.js +14 -0
- package/dist/esm/util/string/strIsUpperCase.js.map +1 -0
- package/dist/esm/util/string/strSplitCamelCase.js +51 -0
- package/dist/esm/util/string/strSplitCamelCase.js.map +1 -0
- package/dist/esm/util/string-parsers/createBooleanParser.js +17 -0
- package/dist/esm/util/string-parsers/createBooleanParser.js.map +1 -0
- package/dist/esm/util/string-parsers/createTypedListParser.js +18 -0
- package/dist/esm/util/string-parsers/createTypedListParser.js.map +1 -0
- package/dist/esm/util/string-parsers/parseBoolean.js +12 -0
- package/dist/esm/util/string-parsers/parseBoolean.js.map +1 -0
- package/dist/esm/util/string-parsers/parseInteger.js +13 -0
- package/dist/esm/util/string-parsers/parseInteger.js.map +1 -0
- package/dist/esm/util/string-parsers/parseNumber.js +9 -0
- package/dist/esm/util/string-parsers/parseNumber.js.map +1 -0
- package/dist/esm/util/string-parsers/parseString.js +4 -0
- package/dist/esm/util/string-parsers/parseString.js.map +1 -0
- package/dist/esm/util/types/Any.js +2 -0
- package/dist/esm/util/types/Any.js.map +1 -0
- package/dist/esm/util/types/DeepArray.js +2 -0
- package/dist/esm/util/types/DeepArray.js.map +1 -0
- package/dist/esm/util/types/DeepObject.js +2 -0
- package/dist/esm/util/types/DeepObject.js.map +1 -0
- package/dist/esm/util/types/JsonArray.js +2 -0
- package/dist/esm/util/types/JsonArray.js.map +1 -0
- package/dist/esm/util/types/JsonDefinedPrimitive.js +5 -0
- package/dist/esm/util/types/JsonDefinedPrimitive.js.map +1 -0
- package/dist/esm/util/types/JsonObject.js +2 -0
- package/dist/esm/util/types/JsonObject.js.map +1 -0
- package/dist/esm/util/types/JsonRawPrimitive.js +2 -0
- package/dist/esm/util/types/JsonRawPrimitive.js.map +1 -0
- package/dist/esm/util/types/JsonValue.js +2 -0
- package/dist/esm/util/types/JsonValue.js.map +1 -0
- package/dist/esm/util/types/ObjectKey.js +2 -0
- package/dist/esm/util/types/ObjectKey.js.map +1 -0
- package/dist/esm/util/types/TConstructor.js +2 -0
- package/dist/esm/util/types/TConstructor.js.map +1 -0
- package/dist/esm/util/types/TFunction.js +2 -0
- package/dist/esm/util/types/TFunction.js.map +1 -0
- package/dist/esm/util/types/TFunctionNoNew.js +2 -0
- package/dist/esm/util/types/TFunctionNoNew.js.map +1 -0
- package/dist/esm/util/types/TPlainObject.js +2 -0
- package/dist/esm/util/types/TPlainObject.js.map +1 -0
- package/dist/esm/util/types/TPrimitive.js +2 -0
- package/dist/esm/util/types/TPrimitive.js.map +1 -0
- package/dist/esm/util/types/TStringParser.js +2 -0
- package/dist/esm/util/types/TStringParser.js.map +1 -0
- package/dist/esm/util/types/TValidator.js +2 -0
- package/dist/esm/util/types/TValidator.js.map +1 -0
- package/dist/esm/util/validation/createTypedArrayValidator.js +22 -0
- package/dist/esm/util/validation/createTypedArrayValidator.js.map +1 -0
- package/dist/esm/util/validation/ensureThat.js +8 -0
- package/dist/esm/util/validation/ensureThat.js.map +1 -0
- package/dist/esm/util/validation/isArray.js +2 -0
- package/dist/esm/util/validation/isArray.js.map +1 -0
- package/dist/esm/util/validation/isBoolean.js +4 -0
- package/dist/esm/util/validation/isBoolean.js.map +1 -0
- package/dist/esm/util/validation/isFunction.js +13 -0
- package/dist/esm/util/validation/isFunction.js.map +1 -0
- package/dist/esm/util/validation/isNamedFunction.js +7 -0
- package/dist/esm/util/validation/isNamedFunction.js.map +1 -0
- package/dist/esm/util/validation/isNamedFunctionArray.js +5 -0
- package/dist/esm/util/validation/isNamedFunctionArray.js.map +1 -0
- package/dist/esm/util/validation/isObject.js +18 -0
- package/dist/esm/util/validation/isObject.js.map +1 -0
- package/dist/esm/util/validation/isPlainObject.js +15 -0
- package/dist/esm/util/validation/isPlainObject.js.map +1 -0
- package/dist/esm/util/validation/isPrimitive.js +14 -0
- package/dist/esm/util/validation/isPrimitive.js.map +1 -0
- package/dist/esm/util/validation/isString.js +4 -0
- package/dist/esm/util/validation/isString.js.map +1 -0
- package/dist/esm/util/validation/isStringArray.js +8 -0
- package/dist/esm/util/validation/isStringArray.js.map +1 -0
- package/dist/esm/util/validation/isStringWithNoSpacesOrDashes.js +5 -0
- package/dist/esm/util/validation/isStringWithNoSpacesOrDashes.js.map +1 -0
- package/dist/esm/util/validation/numbers/isInteger.js +14 -0
- package/dist/esm/util/validation/numbers/isInteger.js.map +1 -0
- package/dist/esm/util/validation/numbers/isValidNumber.js +18 -0
- package/dist/esm/util/validation/numbers/isValidNumber.js.map +1 -0
- package/{src → dist/types}/arg/ArgumentBuilder.d.ts +1 -1
- package/{src → dist/types}/arg/ArgumentParserSelector.d.ts +2 -2
- package/{src → dist/types}/arg/ArgumentReader.d.ts +3 -3
- package/{src → dist/types}/arg/ArgumentValidatorSelector.d.ts +2 -2
- package/dist/types/cmd/CLI.d.ts +2 -0
- package/{src → dist/types}/cmd/CommandBuilder.d.ts +26 -28
- package/{src → dist/types}/cmd/CommandBuilderMetaData.d.ts +7 -7
- package/{src → dist/types}/cmd/CommandFeatureSelector.d.ts +1 -1
- package/dist/types/cmd/DefaultHelpConfig.d.ts +28 -0
- package/dist/types/cmd/asdas.d.ts +6 -0
- package/{src → dist/types}/core/OutputManager.d.ts +1 -1
- package/{src → dist/types}/core/ParserSelector.d.ts +3 -3
- package/{src → dist/types}/core/ValidatorSelector.d.ts +2 -2
- package/{src → dist/types}/db/AbstractJsonFileSection.d.ts +3 -3
- package/{src → dist/types}/db/AppDataSection.d.ts +1 -1
- package/{src → dist/types}/db/ConfigSection.d.ts +4 -4
- package/{src → dist/types}/db/PresetsSection.d.ts +2 -2
- package/{src → dist/types}/index.d.ts +1 -0
- package/{src → dist/types}/opt/OptionArgumentParserSelector.d.ts +1 -1
- package/{src → dist/types}/opt/OptionArgumentValidatorSelector.d.ts +2 -2
- package/{src → dist/types}/opt/OptionBuilder.d.ts +2 -1
- package/{src → dist/types}/opt/OptionHelpers.d.ts +2 -2
- package/{src → dist/types}/opt/OptionReader.d.ts +7 -7
- package/dist/types/proto/overrideCommanderPrototype.d.ts +8 -0
- package/{src → dist/types}/types/IConfig.d.ts +3 -3
- package/{src → dist/types}/types/IPreset.d.ts +4 -3
- package/{src → dist/types}/util/db/JsonDB.d.ts +2 -2
- package/{src → dist/types}/util/fs/promptUserEditInTextEditor/promptUserEditInTextEditorSync.d.ts +1 -1
- package/{src → dist/types}/util/fs/promptUserEditInTextEditor/promptUserEditJsonInTextEditorSync.d.ts +1 -1
- package/{src → dist/types}/util/fs/readJsonFile/readJsonFileSafeSync.d.ts +1 -1
- package/{src → dist/types}/util/fs/tempFile/tempFileSync.d.ts +1 -1
- package/{src → dist/types}/util/function/MethodDisabler.d.ts +3 -3
- package/{src → dist/types}/util/object/createObjectMerger.d.ts +1 -1
- package/{src → dist/types}/util/object/objUpdatePropertyDescriptors.d.ts +1 -1
- package/{src → dist/types}/util/object/setNonEnumerable.d.ts +1 -1
- package/{src → dist/types}/util/string-parsers/createTypedListParser.d.ts +1 -1
- package/{src → dist/types}/util/types/DeepArray.d.ts +2 -2
- package/{src → dist/types}/util/types/DeepObject.d.ts +2 -2
- package/{src → dist/types}/util/types/JsonArray.d.ts +2 -2
- package/{src → dist/types}/util/types/JsonObject.d.ts +2 -2
- package/{src → dist/types}/util/types/JsonRawPrimitive.d.ts +1 -1
- package/{src → dist/types}/util/types/JsonValue.d.ts +3 -3
- package/{src → dist/types}/util/types/TConstructor.d.ts +1 -1
- package/dist/types/util/types/TFunction.d.ts +4 -0
- package/{src → dist/types}/util/types/TFunctionNoNew.d.ts +1 -1
- package/{src → dist/types}/util/types/TPlainObject.d.ts +1 -1
- package/dist/types/util/types/TValidator.d.ts +2 -0
- package/{src → dist/types}/util/validation/ensureThat.d.ts +2 -2
- package/{src → dist/types}/util/validation/isFunction.d.ts +1 -1
- package/{src → dist/types}/util/validation/isNamedFunction.d.ts +1 -1
- package/{src → dist/types}/util/validation/isPlainObject.d.ts +2 -2
- package/{src → dist/types}/util/validation/isPrimitive.d.ts +1 -1
- package/jest.config.ts +11 -0
- package/notes/tsc.md +1 -0
- package/package.json +13 -6
- package/project.json +43 -0
- package/scripts/_example/CommandBuilder.example.ts +96 -0
- package/scripts/_example/CommandBuilder.example2.ts +31 -0
- package/scripts/_example/CommandBuilder.example3.ts +20 -0
- package/scripts/_example/bFindIn.ts +207 -0
- package/scripts/currentBemojeUtils.txt +41 -0
- package/scripts/rollupUtils.ts +184 -0
- package/src/arg/ArgumentBuilder.test.ts +102 -0
- package/src/arg/ArgumentBuilder.ts +47 -0
- package/src/arg/ArgumentParserSelector.test.ts +53 -0
- package/src/arg/ArgumentParserSelector.ts +14 -0
- package/src/arg/ArgumentReader.test.ts +60 -0
- package/src/arg/ArgumentReader.ts +33 -0
- package/src/arg/ArgumentValidatorSelector.test.ts +80 -0
- package/src/arg/ArgumentValidatorSelector.ts +14 -0
- package/src/cmd/CLI.test.ts +14 -0
- package/src/cmd/CLI.ts +13 -0
- package/src/cmd/CommandBuilder.test.ts +611 -0
- package/src/cmd/CommandBuilder.ts +1175 -0
- package/src/cmd/CommandBuilderMetaData.test.ts +54 -0
- package/src/cmd/CommandBuilderMetaData.ts +44 -0
- package/src/cmd/CommandFeatureSelector.test.ts +185 -0
- package/src/cmd/CommandFeatureSelector.ts +113 -0
- package/src/cmd/DefaultHelpConfig.test.ts +22 -0
- package/src/cmd/DefaultHelpConfig.ts +141 -0
- package/src/cmd/asdas.ts +40 -0
- package/src/core/OutputManager.test.ts +129 -0
- package/src/core/OutputManager.ts +103 -0
- package/src/core/ParserSelector.test.ts +7 -0
- package/src/core/ParserSelector.ts +38 -0
- package/src/core/ValidatorSelector.test.ts +7 -0
- package/src/core/ValidatorSelector.ts +38 -0
- package/src/core/splitCombinedArgvShorts.test.ts +9 -0
- package/src/core/splitCombinedArgvShorts.ts +10 -0
- package/src/db/AbstractJsonFileSection.test.ts +274 -0
- package/src/db/AbstractJsonFileSection.ts +218 -0
- package/src/db/AppDataSection.test.ts +69 -0
- package/src/db/AppDataSection.ts +46 -0
- package/src/db/ConfigSection.test.ts +95 -0
- package/src/db/ConfigSection.ts +74 -0
- package/src/db/JsonFile.test.ts +56 -0
- package/src/db/JsonFile.ts +52 -0
- package/src/db/PresetsSection.test.ts +130 -0
- package/src/db/PresetsSection.ts +92 -0
- package/src/index.ts +103 -0
- package/src/opt/OptionArgumentParserSelector.test.ts +54 -0
- package/src/opt/OptionArgumentParserSelector.ts +14 -0
- package/src/opt/OptionArgumentValidatorSelector.test.ts +90 -0
- package/src/opt/OptionArgumentValidatorSelector.ts +16 -0
- package/src/opt/OptionBuilder.test.ts +229 -0
- package/src/opt/OptionBuilder.ts +85 -0
- package/src/opt/OptionHelpers.test.ts +229 -0
- package/src/opt/OptionHelpers.ts +57 -0
- package/src/opt/OptionReader.test.ts +106 -0
- package/src/opt/OptionReader.ts +61 -0
- package/src/proto/overrideCommanderPrototype.ts +42 -0
- package/src/types/IConfig.ts +25 -0
- package/src/types/IPreset.ts +16 -0
- package/src/util/array/arrLast.test.ts +25 -0
- package/src/util/array/arrLast.ts +15 -0
- package/src/util/array/arrSome.test.ts +78 -0
- package/src/util/array/arrSome.ts +23 -0
- package/src/util/array/types/ArrayPredicate.ts +10 -0
- package/src/util/db/JsonDB.test.ts +214 -0
- package/src/util/db/JsonDB.ts +138 -0
- package/src/util/errors/ErrorParser.ts +165 -0
- package/src/util/fs/promptUserEditInTextEditor/IGetUserInputFromEditorOptions.ts +15 -0
- package/src/util/fs/promptUserEditInTextEditor/promptUserEditInTextEditorSync.ts +30 -0
- package/src/util/fs/promptUserEditInTextEditor/promptUserEditJsonInTextEditorSync.ts +25 -0
- package/src/util/fs/readFile/readFileSafeSync.ts +20 -0
- package/src/util/fs/readFile/readFileSync.ts +13 -0
- package/src/util/fs/readJsonFile/readJsonFileSafeSync.ts +17 -0
- package/src/util/fs/removeFile/removeFile.ts +1 -0
- package/src/util/fs/tempFile/tempFileSync.ts +21 -0
- package/src/util/fs/types/IReadJsonFileOptions.ts +1 -0
- package/src/util/fs/writeFile/writeFileSafeSync.ts +1 -0
- package/src/util/fs/writeFile/writeFileSync.ts +1 -0
- package/src/util/fs/writeJsonFile/writeJsonFileSafe.ts +1 -0
- package/src/util/function/MethodDisabler.test.ts +112 -0
- package/src/util/function/MethodDisabler.ts +94 -0
- package/src/util/function/funSetName.test.ts +12 -0
- package/src/util/function/funSetName.ts +16 -0
- package/src/util/node/execInherit.ts +14 -0
- package/src/util/node/formatTableForTerminal.ts +12 -0
- package/src/util/object/arrAssign.ts +3 -0
- package/src/util/object/createArrayMerger.test.ts +11 -0
- package/src/util/object/createArrayMerger.ts +15 -0
- package/src/util/object/createObjectMerger.test.ts +11 -0
- package/src/util/object/createObjectMerger.ts +17 -0
- package/src/util/object/objAssign.ts +3 -0
- package/src/util/object/objUpdatePropertyDescriptors.test.ts +40 -0
- package/src/util/object/objUpdatePropertyDescriptors.ts +29 -0
- package/src/util/object/realizeLazyProperty.ts +9 -0
- package/src/util/object/setNonEnumerable.test.ts +63 -0
- package/src/util/object/setNonEnumerable.ts +22 -0
- package/src/util/os/defaultOpenInEditorCommand.ts +14 -0
- package/src/util/os/isOSX.ts +9 -0
- package/src/util/os/isVsCodeInstalled.test.ts +7 -0
- package/src/util/os/isVsCodeInstalled.ts +14 -0
- package/src/util/os/isWindows.ts +12 -0
- package/src/util/path/getTempDataPath.test.ts +9 -0
- package/src/util/path/getTempDataPath.ts +14 -0
- package/src/util/regex/regexEscapeString.test.ts +35 -0
- package/src/util/regex/regexEscapeString.ts +13 -0
- package/src/util/string/strEnsureStartsWith.test.ts +13 -0
- package/src/util/string/strEnsureStartsWith.ts +14 -0
- package/src/util/string/strFirstCharToUpperCase.test.ts +33 -0
- package/src/util/string/strFirstCharToUpperCase.ts +11 -0
- package/src/util/string/strIsLowerCase.test.ts +42 -0
- package/src/util/string/strIsLowerCase.ts +13 -0
- package/src/util/string/strIsUpperCase.test.ts +48 -0
- package/src/util/string/strIsUpperCase.ts +13 -0
- package/src/util/string/strSplitCamelCase.test.ts +54 -0
- package/src/util/string/strSplitCamelCase.ts +51 -0
- package/src/util/string-parsers/createBooleanParser.test.ts +58 -0
- package/src/util/string-parsers/createBooleanParser.ts +21 -0
- package/src/util/string-parsers/createTypedListParser.test.ts +19 -0
- package/src/util/string-parsers/createTypedListParser.ts +19 -0
- package/src/util/string-parsers/parseBoolean.test.ts +30 -0
- package/src/util/string-parsers/parseBoolean.ts +12 -0
- package/src/util/string-parsers/parseInteger.test.ts +52 -0
- package/src/util/string-parsers/parseInteger.ts +9 -0
- package/src/util/string-parsers/parseNumber.test.ts +53 -0
- package/src/util/string-parsers/parseNumber.ts +6 -0
- package/src/util/string-parsers/parseString.test.ts +7 -0
- package/src/util/string-parsers/parseString.ts +3 -0
- package/src/util/types/Any.ts +2 -0
- package/src/util/types/DeepArray.ts +12 -0
- package/src/util/types/DeepObject.ts +16 -0
- package/src/util/types/JsonArray.ts +8 -0
- package/src/util/types/JsonDefinedPrimitive.ts +5 -0
- package/src/util/types/JsonObject.ts +8 -0
- package/src/util/types/JsonRawPrimitive.ts +7 -0
- package/src/util/types/JsonValue.ts +14 -0
- package/src/util/types/ObjectKey.ts +1 -0
- package/src/util/types/TConstructor.ts +6 -0
- package/src/util/types/TFunction.ts +5 -0
- package/src/util/types/TFunctionNoNew.ts +3 -0
- package/src/util/types/TPlainObject.ts +4 -0
- package/src/util/types/TPrimitive.ts +1 -0
- package/src/util/types/TStringParser.ts +1 -0
- package/src/util/types/TValidator.ts +3 -0
- package/src/util/validation/createTypedArrayValidator.test.ts +34 -0
- package/src/util/validation/createTypedArrayValidator.ts +25 -0
- package/src/util/validation/ensureThat.test.ts +37 -0
- package/src/util/validation/ensureThat.ts +14 -0
- package/src/util/validation/isArray.test.ts +7 -0
- package/src/util/validation/isArray.ts +1 -0
- package/src/util/validation/isBoolean.test.ts +31 -0
- package/src/util/validation/isBoolean.ts +3 -0
- package/src/util/validation/isFunction.test.ts +54 -0
- package/src/util/validation/isFunction.ts +14 -0
- package/src/util/validation/isNamedFunction.test.ts +28 -0
- package/src/util/validation/isNamedFunction.ts +8 -0
- package/src/util/validation/isNamedFunctionArray.test.ts +14 -0
- package/src/util/validation/isNamedFunctionArray.ts +5 -0
- package/src/util/validation/isObject.test.ts +57 -0
- package/src/util/validation/isObject.ts +17 -0
- package/src/util/validation/isPlainObject.test.ts +21 -0
- package/src/util/validation/isPlainObject.ts +14 -0
- package/src/util/validation/isPrimitive.ts +15 -0
- package/src/util/validation/isString.test.ts +23 -0
- package/src/util/validation/isString.ts +3 -0
- package/src/util/validation/isStringArray.test.ts +24 -0
- package/src/util/validation/isStringArray.ts +8 -0
- package/src/util/validation/isStringWithNoSpacesOrDashes.test.ts +28 -0
- package/src/util/validation/isStringWithNoSpacesOrDashes.ts +5 -0
- package/src/util/validation/numbers/isInteger.test.ts +25 -0
- package/src/util/validation/numbers/isInteger.ts +13 -0
- package/src/util/validation/numbers/isValidNumber.test.ts +20 -0
- package/src/util/validation/numbers/isValidNumber.ts +17 -0
- package/tsconfig.json +32 -0
- package/tsconfig.lib.json +18 -0
- package/tsconfig.spec.json +10 -0
- package/index.cjs.d.ts +0 -1
- package/index.cjs.js +0 -3231
- package/index.esm.js +0 -3119
- package/src/cmd/CLI.d.ts +0 -2
- package/src/cmd/DefaultHelpConfig.d.ts +0 -2
- package/src/proto/overrideCommanderPrototype.d.ts +0 -8
- package/src/util/types/TFunction.d.ts +0 -4
- package/src/util/types/TValidator.d.ts +0 -1
- /package/{src → dist/types}/core/splitCombinedArgvShorts.d.ts +0 -0
- /package/{src → dist/types}/db/JsonFile.d.ts +0 -0
- /package/{src → dist/types}/util/array/arrLast.d.ts +0 -0
- /package/{src → dist/types}/util/array/arrSome.d.ts +0 -0
- /package/{src → dist/types}/util/array/types/ArrayPredicate.d.ts +0 -0
- /package/{src → dist/types}/util/errors/ErrorParser.d.ts +0 -0
- /package/{src → dist/types}/util/fs/promptUserEditInTextEditor/IGetUserInputFromEditorOptions.d.ts +0 -0
- /package/{src → dist/types}/util/fs/readFile/readFileSafeSync.d.ts +0 -0
- /package/{src → dist/types}/util/fs/readFile/readFileSync.d.ts +0 -0
- /package/{src → dist/types}/util/fs/removeFile/removeFile.d.ts +0 -0
- /package/{src → dist/types}/util/fs/types/IReadJsonFileOptions.d.ts +0 -0
- /package/{src → dist/types}/util/fs/writeFile/writeFileSafeSync.d.ts +0 -0
- /package/{src → dist/types}/util/fs/writeFile/writeFileSync.d.ts +0 -0
- /package/{src → dist/types}/util/fs/writeJsonFile/writeJsonFileSafe.d.ts +0 -0
- /package/{src → dist/types}/util/function/funSetName.d.ts +0 -0
- /package/{src → dist/types}/util/node/execInherit.d.ts +0 -0
- /package/{src → dist/types}/util/node/formatTableForTerminal.d.ts +0 -0
- /package/{src → dist/types}/util/object/arrAssign.d.ts +0 -0
- /package/{src → dist/types}/util/object/createArrayMerger.d.ts +0 -0
- /package/{src → dist/types}/util/object/objAssign.d.ts +0 -0
- /package/{src → dist/types}/util/object/realizeLazyProperty.d.ts +0 -0
- /package/{src → dist/types}/util/os/defaultOpenInEditorCommand.d.ts +0 -0
- /package/{src → dist/types}/util/os/isOSX.d.ts +0 -0
- /package/{src → dist/types}/util/os/isVsCodeInstalled.d.ts +0 -0
- /package/{src → dist/types}/util/os/isWindows.d.ts +0 -0
- /package/{src → dist/types}/util/path/getTempDataPath.d.ts +0 -0
- /package/{src → dist/types}/util/regex/regexEscapeString.d.ts +0 -0
- /package/{src → dist/types}/util/string/strEnsureStartsWith.d.ts +0 -0
- /package/{src → dist/types}/util/string/strFirstCharToUpperCase.d.ts +0 -0
- /package/{src → dist/types}/util/string/strIsLowerCase.d.ts +0 -0
- /package/{src → dist/types}/util/string/strIsUpperCase.d.ts +0 -0
- /package/{src → dist/types}/util/string/strSplitCamelCase.d.ts +0 -0
- /package/{src → dist/types}/util/string-parsers/createBooleanParser.d.ts +0 -0
- /package/{src → dist/types}/util/string-parsers/parseBoolean.d.ts +0 -0
- /package/{src → dist/types}/util/string-parsers/parseInteger.d.ts +0 -0
- /package/{src → dist/types}/util/string-parsers/parseNumber.d.ts +0 -0
- /package/{src → dist/types}/util/string-parsers/parseString.d.ts +0 -0
- /package/{src → dist/types}/util/types/Any.d.ts +0 -0
- /package/{src → dist/types}/util/types/JsonDefinedPrimitive.d.ts +0 -0
- /package/{src → dist/types}/util/types/ObjectKey.d.ts +0 -0
- /package/{src → dist/types}/util/types/TPrimitive.d.ts +0 -0
- /package/{src → dist/types}/util/types/TStringParser.d.ts +0 -0
- /package/{src → dist/types}/util/validation/createTypedArrayValidator.d.ts +0 -0
- /package/{src → dist/types}/util/validation/isArray.d.ts +0 -0
- /package/{src → dist/types}/util/validation/isBoolean.d.ts +0 -0
- /package/{src → dist/types}/util/validation/isNamedFunctionArray.d.ts +0 -0
- /package/{src → dist/types}/util/validation/isObject.d.ts +0 -0
- /package/{src → dist/types}/util/validation/isString.d.ts +0 -0
- /package/{src → dist/types}/util/validation/isStringArray.d.ts +0 -0
- /package/{src → dist/types}/util/validation/isStringWithNoSpacesOrDashes.d.ts +0 -0
- /package/{src → dist/types}/util/validation/numbers/isInteger.d.ts +0 -0
- /package/{src → dist/types}/util/validation/numbers/isValidNumber.d.ts +0 -0
|
@@ -0,0 +1,1175 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
|
+
import colors from 'ansi-colors'
|
|
3
|
+
import fs from 'fs-extra'
|
|
4
|
+
import isAsyncFunction from 'is-async-function'
|
|
5
|
+
import os from 'os'
|
|
6
|
+
import path from 'path'
|
|
7
|
+
import type { Any } from '../util/types/Any'
|
|
8
|
+
import { ArgumentBuilder } from '../arg/ArgumentBuilder'
|
|
9
|
+
import { arrAssign } from '../util/object/arrAssign'
|
|
10
|
+
import { arrLast } from '../util/array/arrLast'
|
|
11
|
+
import { arrSome } from '../util/array/arrSome'
|
|
12
|
+
import { CommandBuilderMetaData } from './CommandBuilderMetaData'
|
|
13
|
+
import { commanderBackRefs } from '../proto/overrideCommanderPrototype'
|
|
14
|
+
import { CommandFeatureSelector } from './CommandFeatureSelector'
|
|
15
|
+
import { DefaultHelpConfig } from './DefaultHelpConfig'
|
|
16
|
+
import { ensureThat } from '../util/validation/ensureThat'
|
|
17
|
+
import { formatTableForTerminal } from '../util/node/formatTableForTerminal'
|
|
18
|
+
import type { IConfig } from '../types/IConfig'
|
|
19
|
+
import type { IPreset, IPresetPartial } from '../types/IPreset'
|
|
20
|
+
import { isArray } from '../util/validation/isArray'
|
|
21
|
+
import { isObject } from '../util/validation/isObject'
|
|
22
|
+
import { isString } from '../util/validation/isString'
|
|
23
|
+
import { isStringArray } from '../util/validation/isStringArray'
|
|
24
|
+
import { isStringWithNoSpacesOrDashes } from '../util/validation/isStringWithNoSpacesOrDashes'
|
|
25
|
+
import { JsonFile } from '../db/JsonFile'
|
|
26
|
+
import { objAssign } from '../util/object/objAssign'
|
|
27
|
+
import { OptionBuilder } from '../opt/OptionBuilder'
|
|
28
|
+
import { OptionHelpers } from '../opt/OptionHelpers'
|
|
29
|
+
import { OutputManager } from '../core/OutputManager'
|
|
30
|
+
import { PresetsSection } from '../db/PresetsSection'
|
|
31
|
+
import { realizeLazyProperty } from '../util/object/realizeLazyProperty'
|
|
32
|
+
import { removeFile } from '../util/fs/removeFile/removeFile'
|
|
33
|
+
import type { ReturnTypesOfFunctionArray, ReturnTypesOfFunctionMap } from './asdas'
|
|
34
|
+
import { setNonEnumerable } from '../util/object/setNonEnumerable'
|
|
35
|
+
import { splitCombinedArgvShorts } from '../core/splitCombinedArgvShorts'
|
|
36
|
+
import type { TStringParser } from '../util/types/TStringParser'
|
|
37
|
+
import {
|
|
38
|
+
type AddHelpTextPosition,
|
|
39
|
+
Argument,
|
|
40
|
+
Command,
|
|
41
|
+
CommanderError,
|
|
42
|
+
type CommandUnknownOpts,
|
|
43
|
+
type ErrorOptions,
|
|
44
|
+
type HelpConfiguration,
|
|
45
|
+
type HookEvent,
|
|
46
|
+
InvalidArgumentError,
|
|
47
|
+
Option,
|
|
48
|
+
type OptionValues,
|
|
49
|
+
type OptionValueSource,
|
|
50
|
+
} from '@commander-js/extra-typings'
|
|
51
|
+
import { type JsonValue } from '../util/types/JsonValue'
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Wrapper around the @see Command class, for more intuitive construction.
|
|
55
|
+
*/
|
|
56
|
+
export class CommandBuilder<Args extends Any[] = unknown[], Opts extends OptionValues = OptionValues> {
|
|
57
|
+
static dataDirectory = path.join(os.homedir(), 'config', 'cli')
|
|
58
|
+
|
|
59
|
+
protected readonly features = new CommandFeatureSelector(this)
|
|
60
|
+
readonly parent: CommandBuilder | null = null
|
|
61
|
+
readonly $: Command<Args, Opts>
|
|
62
|
+
readonly meta = new CommandBuilderMetaData<Args>()
|
|
63
|
+
get db() {
|
|
64
|
+
return realizeLazyProperty(this, 'db', new JsonFile(this))
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
constructor(
|
|
68
|
+
name: string,
|
|
69
|
+
callback?: (this: CommandBuilder<Args, Opts>, cmd: CommandBuilder<Args, Opts>) => void,
|
|
70
|
+
parent?: CommandBuilder,
|
|
71
|
+
isNative = false
|
|
72
|
+
) {
|
|
73
|
+
this.meta.isNative = isNative
|
|
74
|
+
this.$ = new Command<Args, Opts>(name)
|
|
75
|
+
commanderBackRefs.set(this.$, this)
|
|
76
|
+
|
|
77
|
+
if (parent) {
|
|
78
|
+
this.parent = parent
|
|
79
|
+
this.parent.meta.subcommands.push(this)
|
|
80
|
+
this.parent.$.addCommand(this.$)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
this.initializeHelp()
|
|
84
|
+
|
|
85
|
+
if (callback) callback.call(this, this)
|
|
86
|
+
|
|
87
|
+
if (this.parent) {
|
|
88
|
+
this.$.copyInheritedSettings(this.parent.$)
|
|
89
|
+
this.features.inheritFrom(this.parent.features)
|
|
90
|
+
this.inheritParentHiddenGlobals()
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!this.meta.isNative) {
|
|
94
|
+
this.assertCommandNameNotReserved(this.name)
|
|
95
|
+
this.addUtilCommands()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (this.isRoot) {
|
|
99
|
+
for (const child of this.getChildrenIterator({ includeSelf: true })) {
|
|
100
|
+
if (child.features.isAutoAssignSubCommandAliasesEnabled) {
|
|
101
|
+
child.assignSubCommandAliases()
|
|
102
|
+
if (!child.meta.isNative) {
|
|
103
|
+
child.assertNoDuplicateCommandNames()
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (child.features.isAutoAssignMissingOptionFlagsEnabled) {
|
|
108
|
+
child.assignMissingOptionFlags()
|
|
109
|
+
if (!child.meta.isNative) {
|
|
110
|
+
child.assertNoDuplicateOptionNames()
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
setRecommended() {
|
|
118
|
+
this.enableBuiltinOptions({ debug: true, disableStderr: true, disableStdout: true })
|
|
119
|
+
this.autoAssignMissingOptionFlags()
|
|
120
|
+
this.autoAssignSubCommandAliases()
|
|
121
|
+
this.presetsEnabled()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
deleteDataFile() {
|
|
125
|
+
const filepath = this.dataFilepath
|
|
126
|
+
if (fs.existsSync(filepath)) removeFile(filepath)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
version(string: string) {
|
|
130
|
+
this.$.version(string)
|
|
131
|
+
const opt = this.options.find((o) => o.attributeName() === 'version')
|
|
132
|
+
if (opt) this.meta.globalOptions.push(opt)
|
|
133
|
+
return this
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
description(...lines: string[]) {
|
|
137
|
+
const description = lines.join('\n')
|
|
138
|
+
const summary = description.split(/(\. ?|\n|$)/)[0]
|
|
139
|
+
this.$.summary(summary + '.')
|
|
140
|
+
this.$.description(description)
|
|
141
|
+
return this
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
alias(alias: string) {
|
|
145
|
+
this.assertCommandNameNotReserved(alias)
|
|
146
|
+
this.$.alias(alias)
|
|
147
|
+
return this
|
|
148
|
+
}
|
|
149
|
+
aliases(...aliases: string[]) {
|
|
150
|
+
aliases.forEach((alias) => this.assertCommandNameNotReserved(alias))
|
|
151
|
+
this.$.aliases(aliases)
|
|
152
|
+
return this
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
enableBuiltinOptions(options?: {
|
|
156
|
+
debug?: boolean
|
|
157
|
+
disableColor?: boolean
|
|
158
|
+
disableStderr?: boolean
|
|
159
|
+
disableStdout?: boolean
|
|
160
|
+
}) {
|
|
161
|
+
if (!options || options.debug) this.globalOption('-D, --debug', 'Output debugging information.')
|
|
162
|
+
if (!options || options.disableColor) this.globalOption('-C, --disable-color', 'Disable color in terminal output.')
|
|
163
|
+
if (!options || options.disableStderr) this.globalOption('-E, --disable-stderr', 'Mute all output to stderr.')
|
|
164
|
+
if (!options || options.disableStdout) this.globalOption('-O, --disable-stdout', 'Mute all output to stdout.')
|
|
165
|
+
return this
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
argument(name: string, description?: string): this
|
|
169
|
+
argument(name: string, cb: (opt: ArgumentBuilder, cmd: this) => void): this
|
|
170
|
+
argument(name: string, cb?: string | ((arg: ArgumentBuilder, cmd: this) => void)): this {
|
|
171
|
+
const ins = new ArgumentBuilder(this, name)
|
|
172
|
+
this.$.addArgument(ins.$)
|
|
173
|
+
if (typeof cb === 'function') {
|
|
174
|
+
cb(ins, this)
|
|
175
|
+
} else if (typeof cb === 'string') {
|
|
176
|
+
ins.description(cb)
|
|
177
|
+
}
|
|
178
|
+
return this
|
|
179
|
+
}
|
|
180
|
+
option(flags: string, description?: string): this
|
|
181
|
+
option(flags: string, cb?: (opt: OptionBuilder, cmd: this) => void): this
|
|
182
|
+
option(flags: string, cb?: string | ((opt: OptionBuilder, cmd: this) => void)): this {
|
|
183
|
+
const ins = new OptionBuilder(this, flags)
|
|
184
|
+
if (this.hasIdenticalParentOption(ins.$)) return this
|
|
185
|
+
this.$.addOption(ins.$)
|
|
186
|
+
if (typeof cb === 'function') {
|
|
187
|
+
cb(ins, this)
|
|
188
|
+
} else if (typeof cb === 'string') {
|
|
189
|
+
ins.description(cb)
|
|
190
|
+
}
|
|
191
|
+
return this
|
|
192
|
+
}
|
|
193
|
+
globalOption(flags: string, description?: string): this
|
|
194
|
+
globalOption(flags: string, cb?: (opt: OptionBuilder, cmd: this) => void): this
|
|
195
|
+
globalOption(flags: string, cb?: string | ((opt: OptionBuilder, cmd: this) => void)): this {
|
|
196
|
+
return this.option(flags, (ins) => {
|
|
197
|
+
const opt = ins.$
|
|
198
|
+
this.meta.globalOptions.push(opt)
|
|
199
|
+
if (typeof cb === 'function') {
|
|
200
|
+
cb(ins, this)
|
|
201
|
+
} else if (typeof cb === 'string') {
|
|
202
|
+
ins.description(cb)
|
|
203
|
+
}
|
|
204
|
+
if (opt.hidden) this.meta.hiddenGlobalOptions.add(opt)
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
command<A extends Any[] = unknown[], O extends OptionValues = OptionValues>(
|
|
208
|
+
name: string,
|
|
209
|
+
cb: (this: CommandBuilder<A, O>, cmd: CommandBuilder<A, O>) => void
|
|
210
|
+
): this {
|
|
211
|
+
new CommandBuilder<A, O>(name, cb, this)
|
|
212
|
+
return this
|
|
213
|
+
}
|
|
214
|
+
nativeCommand<A extends Any[] = unknown[], O extends OptionValues = OptionValues>(
|
|
215
|
+
name: string,
|
|
216
|
+
cb: (this: CommandBuilder<A, O>, cmd: CommandBuilder<A, O>) => void
|
|
217
|
+
): this {
|
|
218
|
+
new CommandBuilder<A, O>(name, cb, this, true)
|
|
219
|
+
return this
|
|
220
|
+
}
|
|
221
|
+
action(fn: (...args: any[]) => void | Promise<void>): this {
|
|
222
|
+
const isAsync = isAsyncFunction(fn) || /^\(.+\) ?=> ?tslib_1\.__awaiter\(/.test(fn.toString().trim())
|
|
223
|
+
Object.defineProperty(this.meta, 'actionHandler', { value: fn, configurable: false, writable: false })
|
|
224
|
+
this.initializeActionWrapper(isAsync)
|
|
225
|
+
return this
|
|
226
|
+
}
|
|
227
|
+
errorHandler(fn: (this: Command, error: unknown, cmd: CommandBuilder<Args, Opts>) => void) {
|
|
228
|
+
Object.defineProperty(this.meta, 'errorHandler', { value: fn, configurable: true })
|
|
229
|
+
return this
|
|
230
|
+
}
|
|
231
|
+
appData(key: string, value: JsonValue) {
|
|
232
|
+
this.features.appData(true)
|
|
233
|
+
this.db.appData.defineProperty(key, value)
|
|
234
|
+
return this
|
|
235
|
+
}
|
|
236
|
+
config(key: string, entry: IConfig<JsonValue>) {
|
|
237
|
+
this.features.config(true)
|
|
238
|
+
this.db.config.defineProperty(key, entry)
|
|
239
|
+
return this
|
|
240
|
+
}
|
|
241
|
+
preset(name: string, preset: IPresetPartial) {
|
|
242
|
+
this.features.presets()
|
|
243
|
+
this.meta.presetOptionKeys.push(name)
|
|
244
|
+
this.db.presets.defineProperty(name, {
|
|
245
|
+
description: preset.description,
|
|
246
|
+
presets: preset.presets ?? [],
|
|
247
|
+
args: preset.args ?? [],
|
|
248
|
+
options: preset.options ?? {},
|
|
249
|
+
})
|
|
250
|
+
return this
|
|
251
|
+
}
|
|
252
|
+
presetsEnabled(boolean = true) {
|
|
253
|
+
this.features.presets(boolean)
|
|
254
|
+
return this
|
|
255
|
+
}
|
|
256
|
+
autoAssignMissingOptionFlags(boolean = true) {
|
|
257
|
+
this.features.autoAssignMissingOptionFlags(boolean)
|
|
258
|
+
return this
|
|
259
|
+
}
|
|
260
|
+
autoAssignSubCommandAliases(boolean = true) {
|
|
261
|
+
this.features.autoAssignSubCommandAliases(boolean)
|
|
262
|
+
return this
|
|
263
|
+
}
|
|
264
|
+
allowExcessArguments(bool = true) {
|
|
265
|
+
this.$.allowExcessArguments(bool)
|
|
266
|
+
return this
|
|
267
|
+
}
|
|
268
|
+
allowUnknownOption(bool = true) {
|
|
269
|
+
this.$.allowUnknownOption(bool)
|
|
270
|
+
return this
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Register callback to use as replacement for calling process.exit.
|
|
274
|
+
*/
|
|
275
|
+
exitOverride(callback?: (err: CommanderError) => never | void): this {
|
|
276
|
+
this.$.exitOverride(callback)
|
|
277
|
+
return this
|
|
278
|
+
}
|
|
279
|
+
throwInsteadOfProcessExit() {
|
|
280
|
+
const onErr = (err: unknown) => {
|
|
281
|
+
throw err
|
|
282
|
+
}
|
|
283
|
+
this.exitOverride(onErr)
|
|
284
|
+
this.errorHandler(onErr)
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Add hook for life cycle event.
|
|
288
|
+
*/
|
|
289
|
+
hook(
|
|
290
|
+
event: HookEvent,
|
|
291
|
+
listener: (thisCommand: CommandUnknownOpts, actionCommand: CommandUnknownOpts) => void | Promise<void>
|
|
292
|
+
): this {
|
|
293
|
+
this.$.hook(event, listener)
|
|
294
|
+
return this
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* You can customise the help by overriding Help properties using configureHelp(),
|
|
299
|
+
* or with a subclass of Help by overriding createHelp().
|
|
300
|
+
*/
|
|
301
|
+
configureHelp(configuration: HelpConfiguration): this {
|
|
302
|
+
this.$.configureHelp(configuration)
|
|
303
|
+
return this
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Display the help or a custom message after an error occurs.
|
|
308
|
+
*/
|
|
309
|
+
showHelpAfterError(displayHelp?: boolean | string): this {
|
|
310
|
+
this.$.showHelpAfterError(displayHelp)
|
|
311
|
+
return this
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Display suggestion of similar commands for unknown commands, or options for unknown options.
|
|
316
|
+
*/
|
|
317
|
+
showSuggestionAfterError(displaySuggestion?: boolean): this {
|
|
318
|
+
this.$.showSuggestionAfterError(displaySuggestion)
|
|
319
|
+
return this
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Add additional text to be displayed with the built-in help.
|
|
324
|
+
*
|
|
325
|
+
* Position is 'before' or 'after' to affect just this command,
|
|
326
|
+
* and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
|
|
327
|
+
*/
|
|
328
|
+
addHelpText(position: AddHelpTextPosition, text: string) {
|
|
329
|
+
this.$.addHelpText(position, text)
|
|
330
|
+
return this
|
|
331
|
+
}
|
|
332
|
+
throwCommanderError(message: string, exitCode = 1, type = 'error'): never {
|
|
333
|
+
throw new CommanderError(exitCode, type, message)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
hideGlobalOptions(...names: string[]) {
|
|
337
|
+
const globals = this.getGlobalOptions()
|
|
338
|
+
names = names.length ? names : globals.map((opt) => opt.attributeName())
|
|
339
|
+
for (const name of names) {
|
|
340
|
+
if (!name) continue
|
|
341
|
+
let found = false
|
|
342
|
+
for (const opt of globals) {
|
|
343
|
+
if (opt.attributeName() === name) {
|
|
344
|
+
this.meta.hiddenGlobalOptions.add(opt)
|
|
345
|
+
found = true
|
|
346
|
+
break
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (!found) this.throwCommanderError(`Unknown global option name: ${name} for command, ${this.name}`)
|
|
351
|
+
}
|
|
352
|
+
return this
|
|
353
|
+
}
|
|
354
|
+
unhideGlobalOptions(...names: string[]) {
|
|
355
|
+
const globals = this.getGlobalOptions()
|
|
356
|
+
names = names.length ? names : globals.map((opt) => opt.attributeName())
|
|
357
|
+
for (const name of names) {
|
|
358
|
+
if (!name) continue
|
|
359
|
+
let found = false
|
|
360
|
+
for (const opt of globals) {
|
|
361
|
+
if (opt.attributeName() === name) {
|
|
362
|
+
this.meta.hiddenGlobalOptions.delete(opt)
|
|
363
|
+
found = true
|
|
364
|
+
break
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
if (!found) this.throwCommanderError(`Unknown global option name: ${name} for command, ${this.name}`)
|
|
368
|
+
}
|
|
369
|
+
return this
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Set the directory for searching for executable subcommands of this command.
|
|
373
|
+
*/
|
|
374
|
+
executableDir(path: string): this {
|
|
375
|
+
this.$.executableDir(path)
|
|
376
|
+
return this
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Store option value.
|
|
381
|
+
*/
|
|
382
|
+
setOptionValue(key: string, value: unknown): this {
|
|
383
|
+
this.$.setOptionValue(key, value)
|
|
384
|
+
return this
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Store option value and where the value came from.
|
|
389
|
+
*/
|
|
390
|
+
setOptionValueWithSource(key: string, value: unknown, source: OptionValueSource): this {
|
|
391
|
+
this.$.setOptionValueWithSource(key, value, source)
|
|
392
|
+
return this
|
|
393
|
+
}
|
|
394
|
+
setDataFilepath(filepath: string) {
|
|
395
|
+
Object.defineProperty(this, 'dataFilepath', { value: filepath })
|
|
396
|
+
if (Object.hasOwn(this, 'db') && Object.hasOwn(this.db, 'db')) {
|
|
397
|
+
this.db.db.setFilepath(filepath)
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Display error message and exit (or call exitOverride).
|
|
403
|
+
*/
|
|
404
|
+
outputError(message: string, options?: ErrorOptions) {
|
|
405
|
+
this.$.error(message, options)
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Output help information for this command.
|
|
410
|
+
*/
|
|
411
|
+
outputHelp() {
|
|
412
|
+
console.log(this.getRenderedHelp())
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Display error message and exit (or call exitOverride).
|
|
417
|
+
*/
|
|
418
|
+
outputDebugMessage(event: string, getProps: () => Record<string, unknown> = () => ({})) {
|
|
419
|
+
OutputManager.getInstance().outputDebug(() => ({ event, cmd: this.getPrefixString(), ...getProps() }))
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
parseArguments(args: string[]) {
|
|
423
|
+
const last = this.arguments.length - 1
|
|
424
|
+
return args.map((arg, i) => {
|
|
425
|
+
if (!arg) return arg
|
|
426
|
+
const parse = this.meta.argParsers[i > last ? last : i]
|
|
427
|
+
return parse ? (Array.isArray(arg) ? arg.map(parse) : parse(arg)) : arg
|
|
428
|
+
})
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Parses (and validates) options using the parsers defined in the command builder.
|
|
433
|
+
*/
|
|
434
|
+
parseOptions(opts: OptionValues) {
|
|
435
|
+
for (const [key, value] of Object.entries(opts)) {
|
|
436
|
+
const parse = this.meta.optParsers[key]
|
|
437
|
+
opts[key] = parse ? (Array.isArray(value) ? value.map(parse) : parse(value as string)) : value
|
|
438
|
+
}
|
|
439
|
+
return opts
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Validate ALREADY PARSED args using the validators defined in the command builder.
|
|
444
|
+
*/
|
|
445
|
+
assertValidArguments(parsedArgs: Any[]) {
|
|
446
|
+
const last = this.arguments.length - 1
|
|
447
|
+
parsedArgs.forEach((arg, i) => {
|
|
448
|
+
if (arg == null) return
|
|
449
|
+
const index = i > last ? last : i
|
|
450
|
+
const validators = this.meta.argValidators[index]
|
|
451
|
+
if (!validators) return
|
|
452
|
+
for (const isValid of validators) {
|
|
453
|
+
ensureThat(arg, isValid, { Err: InvalidArgumentError })
|
|
454
|
+
}
|
|
455
|
+
})
|
|
456
|
+
return parsedArgs
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Validate ALREADY PARSED options using the validators defined in the command builder.
|
|
461
|
+
*/
|
|
462
|
+
assertValidOptions(parsedOptions: OptionValues) {
|
|
463
|
+
for (const [key, value] of Object.entries(parsedOptions)) {
|
|
464
|
+
if (!this.meta.optValidators[key]) continue
|
|
465
|
+
if (value == null) continue
|
|
466
|
+
for (const isValid of this.meta.optValidators[key]) {
|
|
467
|
+
ensureThat(value, isValid)
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return parsedOptions
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
assertValidPreset(key: string, preset: IPreset) {
|
|
474
|
+
const { description, presets, args, options } = preset
|
|
475
|
+
ensureThat(key, isStringWithNoSpacesOrDashes)
|
|
476
|
+
ensureThat(description, isString)
|
|
477
|
+
ensureThat(presets, isStringArray)
|
|
478
|
+
ensureThat(args, isArray)
|
|
479
|
+
this.assertPresetArgsOptional(args)
|
|
480
|
+
this.assertValidArguments(args)
|
|
481
|
+
ensureThat(options, isObject)
|
|
482
|
+
this.assertValidOptions(options)
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
get name() {
|
|
486
|
+
return this.$.name()
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Get the command at the root of the command tree.
|
|
490
|
+
*/
|
|
491
|
+
get root(): CommandBuilder {
|
|
492
|
+
if (this.isRoot) return this
|
|
493
|
+
return this.getAncestors().pop() as CommandBuilder
|
|
494
|
+
}
|
|
495
|
+
get isRoot() {
|
|
496
|
+
return !this.parent
|
|
497
|
+
}
|
|
498
|
+
get arguments() {
|
|
499
|
+
return this.$.registeredArguments
|
|
500
|
+
}
|
|
501
|
+
get options() {
|
|
502
|
+
return this.$.options
|
|
503
|
+
}
|
|
504
|
+
get commander() {
|
|
505
|
+
return this.$
|
|
506
|
+
}
|
|
507
|
+
get hasGrandChildren() {
|
|
508
|
+
return this.meta.subcommands.some((sub) => !!sub.meta.subcommands.length)
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Returns whether a command's last argument is variadic.
|
|
512
|
+
*/
|
|
513
|
+
get isLastArgVariadic() {
|
|
514
|
+
if (!this.arguments.length) return false
|
|
515
|
+
return arrLast(this.arguments as Argument[]).variadic
|
|
516
|
+
}
|
|
517
|
+
get dataFilepath() {
|
|
518
|
+
return path.join(CommandBuilder.dataDirectory, this.root.name + '.json')
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Get the executable search directory.
|
|
523
|
+
*/
|
|
524
|
+
getExecutableDir(): string | null {
|
|
525
|
+
return this.$.executableDir()
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Retrieve option value.
|
|
529
|
+
*/
|
|
530
|
+
getOptionValue(key: string): Any {
|
|
531
|
+
return this.$.getOptionValue(key)
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Get source of option value.
|
|
536
|
+
*/
|
|
537
|
+
getOptionValueSource(key: string): OptionValueSource | undefined {
|
|
538
|
+
return this.$.getOptionValueSource(key)
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Get source of option value. See also .optsWithGlobals().
|
|
543
|
+
*/
|
|
544
|
+
getOptionValueSourceWithGlobals(key: string): OptionValueSource | undefined {
|
|
545
|
+
return this.$.getOptionValueSourceWithGlobals(key)
|
|
546
|
+
}
|
|
547
|
+
getActionHandler() {
|
|
548
|
+
return this.meta.actionHandler
|
|
549
|
+
}
|
|
550
|
+
getDescription() {
|
|
551
|
+
return this.$.description()
|
|
552
|
+
}
|
|
553
|
+
getSummary() {
|
|
554
|
+
return this.$.summary()
|
|
555
|
+
}
|
|
556
|
+
getVersion() {
|
|
557
|
+
return this.$.version()
|
|
558
|
+
}
|
|
559
|
+
getAlias() {
|
|
560
|
+
return this.$.alias()
|
|
561
|
+
}
|
|
562
|
+
getAliases() {
|
|
563
|
+
return this.$.aliases()
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Get a commands prefix array based on all its parent/ancestor commands.
|
|
568
|
+
*/
|
|
569
|
+
getPrefixArray(): string[] {
|
|
570
|
+
return this.getAncestors({ includeSelf: true })
|
|
571
|
+
.reverse()
|
|
572
|
+
.map((node) => node.name)
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Get a commands prefix string based on all its parent/ancestor commands.
|
|
577
|
+
*/
|
|
578
|
+
getPrefixString() {
|
|
579
|
+
return this.getPrefixArray().join(' ')
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
getGlobalOptions(): Option[] {
|
|
583
|
+
const result: Option[] = []
|
|
584
|
+
for (const anc of this.getAncestors({ includeSelf: true }).reverse()) {
|
|
585
|
+
for (const gopt of anc.meta.globalOptions) {
|
|
586
|
+
if (!this.meta.hiddenGlobalOptions.has(gopt)) {
|
|
587
|
+
result.push(gopt)
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
return result
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
getOwnAndGlobalOptions(): Option[] {
|
|
595
|
+
return this.options.concat(this.getGlobalOptions())
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
*getChildrenIterator(options?: { includeSelf?: boolean }): Generator<CommandBuilder> {
|
|
599
|
+
if (options?.includeSelf) yield this
|
|
600
|
+
for (const sub of this.meta.subcommands) {
|
|
601
|
+
yield sub
|
|
602
|
+
yield* sub.getChildrenIterator()
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
getChildren(options?: { includeSelf?: boolean }) {
|
|
607
|
+
return [...this.getChildrenIterator(options)]
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
*getAncestorsIterator(options?: { includeSelf?: boolean }): Generator<CommandBuilder> {
|
|
611
|
+
if (options?.includeSelf) yield this
|
|
612
|
+
let node = this.parent
|
|
613
|
+
while (node) {
|
|
614
|
+
yield node
|
|
615
|
+
node = node.parent
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* Get a command's ancestors, optionally starting from the command itself.
|
|
621
|
+
*/
|
|
622
|
+
getAncestors(options?: { includeSelf?: boolean }): CommandBuilder[] {
|
|
623
|
+
return [...this.getAncestorsIterator(options)]
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
*getSiblingsIterator() {
|
|
627
|
+
if (!this.parent) return
|
|
628
|
+
for (const sub of this.parent.meta.subcommands) {
|
|
629
|
+
if (sub === this) continue
|
|
630
|
+
yield sub
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* Returns an array of sibling CommandBuilder objects.
|
|
636
|
+
*/
|
|
637
|
+
getSiblings() {
|
|
638
|
+
return [...this.getSiblingsIterator()]
|
|
639
|
+
}
|
|
640
|
+
getClosestNonNativeParent() {
|
|
641
|
+
for (const anc of this.getAncestorsIterator({ includeSelf: true })) {
|
|
642
|
+
if (!anc.meta.isNative) return anc
|
|
643
|
+
}
|
|
644
|
+
this.throwCommanderError('No non-native parent found')
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
getRenderedHelp() {
|
|
648
|
+
return this.$.helpInformation()
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
getOptsWithGlobalsParsed() {
|
|
652
|
+
return this.parseOptions(this.$.optsWithGlobals())
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
getParsedValidArgsOptsWithPresets(): [Any[], OptionValues] {
|
|
656
|
+
const [presetArgs, presetOpts, presetOrder] = this.getPresetArgsAndOpts()
|
|
657
|
+
const args = this.getParsedValidArgsWithPresets(presetArgs)
|
|
658
|
+
const opts = this.getParsedValidOptsWithPresets(presetOpts)
|
|
659
|
+
this.debugLogArgsOpts(args, opts, presetArgs, presetOpts, presetOrder)
|
|
660
|
+
return [args, opts]
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
getParsedValidArgsWithPresets(presetArgs: Any[][]) {
|
|
664
|
+
const result = arrAssign([], ...presetArgs, this.parseArguments(this.$.args))
|
|
665
|
+
this.combineVariadicArgs(result)
|
|
666
|
+
this.assertValidArguments(result)
|
|
667
|
+
return this.padArgsWithUndefinedUntilExpectedLength(result)
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
getParsedValidOptsWithPresets(presetOpts: OptionValues[]) {
|
|
671
|
+
const parsed = this.getOptsWithGlobalsParsed()
|
|
672
|
+
const opts = presetOpts.length ? objAssign({}, ...presetOpts, parsed) : parsed
|
|
673
|
+
this.deleteOptionsWithDefaultOrNoValue(opts)
|
|
674
|
+
this.assertValidOptions(opts)
|
|
675
|
+
return opts
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
getPresetArgsAndOpts(): [presetArgs: string[][], presetOpts: OptionValues[], presetOrder: string[]] {
|
|
679
|
+
if (!this.features.isPresetsEnabled) return [[], [], []]
|
|
680
|
+
const presets = this.db.presets.getAll()
|
|
681
|
+
const opts = this.$.optsWithGlobals()
|
|
682
|
+
const selectedPresets = Object.keys(presets).filter((name) => opts[name] === true)
|
|
683
|
+
const presetOrder = Object.keys(opts).filter((key) => selectedPresets.includes(key))
|
|
684
|
+
const presetArgs: string[][] = presetOrder.map((name) => presets[name].args)
|
|
685
|
+
const presetOpts: OptionValues[] = presetOrder.map((name) => presets[name].options)
|
|
686
|
+
return [presetArgs, presetOpts, presetOrder]
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
protected combineVariadicArgs(result: Any[]) {
|
|
690
|
+
if (this.isLastArgVariadic && result.length && !Array.isArray(arrLast(result))) {
|
|
691
|
+
const rest = result.splice(this.arguments.length - 1)
|
|
692
|
+
result.push(rest.filter((arg) => arg != null))
|
|
693
|
+
}
|
|
694
|
+
return result
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
protected debugLogArgsOpts(
|
|
698
|
+
args: Any[],
|
|
699
|
+
opts: OptionValues,
|
|
700
|
+
presetArgs: string[][],
|
|
701
|
+
presetOpts: OptionValues[],
|
|
702
|
+
presetOrder: string[]
|
|
703
|
+
) {
|
|
704
|
+
if (opts['debug']) {
|
|
705
|
+
if (this.features.isPresetsEnabled) {
|
|
706
|
+
this.outputDebugMessage('parsePresets', () => ({ presetOrder, presetArgs, presetOpts }))
|
|
707
|
+
}
|
|
708
|
+
this.outputDebugMessage('parseArgsOpts', () => {
|
|
709
|
+
return {
|
|
710
|
+
args,
|
|
711
|
+
opts,
|
|
712
|
+
command: [this.root.name, ...this.meta.rawArgs].join(' '),
|
|
713
|
+
}
|
|
714
|
+
})
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
protected deleteOptionsWithDefaultOrNoValue(opts: OptionValues) {
|
|
719
|
+
const names = new Set(this.getOwnAndGlobalOptions().map((o) => o.attributeName()))
|
|
720
|
+
for (const [key, value] of Object.entries(opts)) {
|
|
721
|
+
if (!names.has(key) || value === false || value == null) {
|
|
722
|
+
setNonEnumerable(opts, key)
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
for (const key of this.meta.presetOptionKeys) {
|
|
726
|
+
if (Object.hasOwn(opts, key)) {
|
|
727
|
+
setNonEnumerable(opts, key)
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
return opts
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
protected handleOutputOptions() {
|
|
734
|
+
const opts = this.$.optsWithGlobals()
|
|
735
|
+
const om = OutputManager.getInstance().reset()
|
|
736
|
+
if (opts['disableColor']) om.colors.enabled = false
|
|
737
|
+
if (opts['disableStderr']) om.stderr.disable()
|
|
738
|
+
if (opts['disableStdout']) om.stdout.disable()
|
|
739
|
+
if (opts['debug']) {
|
|
740
|
+
om.debug.enable()
|
|
741
|
+
om.drainDebugMessageQueue()
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
protected padArgsWithUndefinedUntilExpectedLength(args: Any[]) {
|
|
746
|
+
while (args.length < this.arguments.length) args.push(undefined)
|
|
747
|
+
return args
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
protected assertPresetArgsOptional(args: Any[]) {
|
|
751
|
+
args.forEach((arg, i) => {
|
|
752
|
+
if (arg != null && i < this.arguments.length && this.arguments[i].required) {
|
|
753
|
+
this.throwCommanderError(`Cannot preset required arguments.`)
|
|
754
|
+
}
|
|
755
|
+
})
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
protected addUtilCommands() {
|
|
759
|
+
if (
|
|
760
|
+
!this.hasGrandChildren &&
|
|
761
|
+
!this.features.isConfigEnabled &&
|
|
762
|
+
!this.features.isPresetsEnabled &&
|
|
763
|
+
!this.features.isAppDataEnabled
|
|
764
|
+
) {
|
|
765
|
+
return
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
this.nativeCommand('util', (u) => {
|
|
769
|
+
const cmd = u.getClosestNonNativeParent()
|
|
770
|
+
u.alias('u')
|
|
771
|
+
u.description('Utility commands.')
|
|
772
|
+
if (cmd.features.isConfigEnabled) {
|
|
773
|
+
u.nativeCommand('config', createConfigCommand)
|
|
774
|
+
}
|
|
775
|
+
if (cmd.features.isPresetsEnabled && cmd.meta.hasCustomActionHandler) {
|
|
776
|
+
u.nativeCommand('presets', createPresetsCommand)
|
|
777
|
+
}
|
|
778
|
+
if (cmd.hasGrandChildren) {
|
|
779
|
+
u.nativeCommand('list', createUtilListCommand)
|
|
780
|
+
}
|
|
781
|
+
if (cmd.features.isConfigEnabled || cmd.features.isPresetsEnabled || cmd.features.isAppDataEnabled) {
|
|
782
|
+
u.nativeCommand('filepath', createUtilFilepathCommand)
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
function createUtilFilepathCommand(f: CommandBuilder) {
|
|
786
|
+
f.alias('f')
|
|
787
|
+
f.description('Print filepath to JSON file containing user data, eg. config and presets.')
|
|
788
|
+
f.action(async () => console.log(cmd.dataFilepath))
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
function createUtilListCommand(l: CommandBuilder) {
|
|
792
|
+
l.alias('l')
|
|
793
|
+
l.description('List nested subcommands.')
|
|
794
|
+
l.option('--all', 'Include utility commands.')
|
|
795
|
+
l.action(async (opts: { all?: boolean }) => {
|
|
796
|
+
const filter = opts.all
|
|
797
|
+
? undefined
|
|
798
|
+
: (prefix: string) => {
|
|
799
|
+
return !/ (config|presets|util)( .+)?$/gi.test(prefix)
|
|
800
|
+
}
|
|
801
|
+
const table: string[][] = []
|
|
802
|
+
for (const c of cmd.getChildrenIterator({ includeSelf: true })) {
|
|
803
|
+
const prefix = c.getPrefixString()
|
|
804
|
+
if (filter && !filter(prefix)) continue
|
|
805
|
+
table.push([prefix, c.getSummary()])
|
|
806
|
+
}
|
|
807
|
+
const ansi = table.map((row) => {
|
|
808
|
+
const arr = row[0].split(' ')
|
|
809
|
+
const last = arr.pop() as string
|
|
810
|
+
let col = colors.magenta
|
|
811
|
+
if (row[1].startsWith('[Preset]')) {
|
|
812
|
+
col = colors.green
|
|
813
|
+
} else if (/ (util|config|presets) /.test(row[0])) {
|
|
814
|
+
col = colors.gray
|
|
815
|
+
} else if (/ (util|config|presets)/.test(row[0])) {
|
|
816
|
+
col = colors.dim
|
|
817
|
+
}
|
|
818
|
+
row[0] = arr.map(colors.dim).concat(col(last)).join(' ')
|
|
819
|
+
return row
|
|
820
|
+
})
|
|
821
|
+
console.log(formatTableForTerminal(ansi, ['Command', 'Summary']))
|
|
822
|
+
})
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
function createPresetsCommand(p: CommandBuilder) {
|
|
826
|
+
const db = cmd.db.presets as PresetsSection
|
|
827
|
+
p.alias('p')
|
|
828
|
+
p.description(
|
|
829
|
+
'Edit presets in your text editor',
|
|
830
|
+
'',
|
|
831
|
+
'A preset consists of pre-set arguments and/or options for a command.',
|
|
832
|
+
'Additionally, a preset can have other presets as dependencies.',
|
|
833
|
+
'When running the command, multiple presets can be stacked.',
|
|
834
|
+
'Required arguments cannot be pre-set.'
|
|
835
|
+
)
|
|
836
|
+
p.nativeCommand('edit', (e) => {
|
|
837
|
+
e.alias('e')
|
|
838
|
+
e.description('Edit as JSON in a text editor.')
|
|
839
|
+
e.option('--editor [cmd]', 'The command to launch your preferred text editor.')
|
|
840
|
+
e.action(async (opts: { editor: string }) => {
|
|
841
|
+
db.edit(opts.editor)
|
|
842
|
+
console.info(db.getAll())
|
|
843
|
+
})
|
|
844
|
+
})
|
|
845
|
+
p.nativeCommand('list', (l) => {
|
|
846
|
+
l.alias('l')
|
|
847
|
+
l.description('List all presets.')
|
|
848
|
+
l.action(async () => console.dir(db.getAll(), { depth: null }))
|
|
849
|
+
})
|
|
850
|
+
for (const [key, preset] of Object.entries(db.getAll())) {
|
|
851
|
+
if (key === 'defaults') continue
|
|
852
|
+
cmd.option(`--${key}`, (o) => {
|
|
853
|
+
o.description('[Preset]: ' + preset.description)
|
|
854
|
+
const implied: Record<string, boolean> = { defaults: true }
|
|
855
|
+
const recurse = (preset: string) => {
|
|
856
|
+
if (implied[preset]) return
|
|
857
|
+
implied[preset] = true
|
|
858
|
+
db.get(preset).presets.forEach((k) => recurse(k))
|
|
859
|
+
}
|
|
860
|
+
recurse(key)
|
|
861
|
+
o.implies(implied)
|
|
862
|
+
})
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
function createConfigCommand(c: CommandBuilder) {
|
|
867
|
+
const db = cmd.db.config
|
|
868
|
+
c.alias('c')
|
|
869
|
+
c.description('Manage configuration file.')
|
|
870
|
+
c.nativeCommand('edit', (e) => {
|
|
871
|
+
e.alias('e')
|
|
872
|
+
e.description('Edit as JSON in a text editor.')
|
|
873
|
+
e.option('--editor [cmd]', 'The command to launch your preferred text editor.')
|
|
874
|
+
e.action(async (opts: { editor: string }) => {
|
|
875
|
+
db.edit(opts.editor)
|
|
876
|
+
console.info(db.getAll())
|
|
877
|
+
})
|
|
878
|
+
})
|
|
879
|
+
c.nativeCommand('list', (l) => {
|
|
880
|
+
l.alias('l')
|
|
881
|
+
l.description('Print entire config with details.')
|
|
882
|
+
l.action(async () => {
|
|
883
|
+
const result = db.keys.map((key: string) => ({
|
|
884
|
+
key,
|
|
885
|
+
description: db.descriptions[key],
|
|
886
|
+
value: db.get(key),
|
|
887
|
+
defaultValue: db.defaultValues,
|
|
888
|
+
}))
|
|
889
|
+
console.dir(result, { depth: null })
|
|
890
|
+
})
|
|
891
|
+
})
|
|
892
|
+
c.nativeCommand('get', (g) => {
|
|
893
|
+
g.alias('g')
|
|
894
|
+
g.description('Print value(s) from the config.')
|
|
895
|
+
g.argument('[key]', 'The key to print the value of. Omit to print all values.')
|
|
896
|
+
g.action(async (key: string) => console.log(key ? db.get(key) : db.getAll()))
|
|
897
|
+
})
|
|
898
|
+
c.nativeCommand('set', (s) => {
|
|
899
|
+
s.alias('s')
|
|
900
|
+
s.description('Set a value in the config.')
|
|
901
|
+
s.argument('<key>', 'The key to set the value of.')
|
|
902
|
+
s.argument('<value>', 'The new value.')
|
|
903
|
+
s.action(async (key: string, val: string) => {
|
|
904
|
+
const parse = db.parsers[key]
|
|
905
|
+
const value = typeof parse === 'function' ? parse(val) : val
|
|
906
|
+
db.set(key, value)
|
|
907
|
+
console.info({ [key]: value })
|
|
908
|
+
})
|
|
909
|
+
})
|
|
910
|
+
c.nativeCommand('reset', (r) => {
|
|
911
|
+
r.alias('r')
|
|
912
|
+
r.description('Reset to defaults.')
|
|
913
|
+
r.argument('[key]', 'The key for which to reset the value. Omit to reset entire config.')
|
|
914
|
+
r.action(async (key: string) => {
|
|
915
|
+
if (key) db.reset(key)
|
|
916
|
+
else db.resetAll()
|
|
917
|
+
console.info(db.getAll())
|
|
918
|
+
})
|
|
919
|
+
})
|
|
920
|
+
/*
|
|
921
|
+
config.option('--editor [cmd]', (o) => {
|
|
922
|
+
o.description('The command to launch your preferred text editor.')
|
|
923
|
+
})
|
|
924
|
+
config.argument('[action]', (a) => {
|
|
925
|
+
a.description('The action to perform.')
|
|
926
|
+
a.choices(['edit', 'list', 'get', 'set', 'reset'])
|
|
927
|
+
a.default('edit')
|
|
928
|
+
})
|
|
929
|
+
config.argument('[key]', (a) => {
|
|
930
|
+
a.description('Property key (if applicable)')
|
|
931
|
+
})
|
|
932
|
+
config.argument('[value]', (a) => {
|
|
933
|
+
a.description('Value to set (if applicable)')
|
|
934
|
+
})
|
|
935
|
+
config.action(
|
|
936
|
+
async (action: string, key: string, value: string, opts: { editor: string }, config: CommandBuilder) => {
|
|
937
|
+
const cmd = config.getClosestNonNativeParent()
|
|
938
|
+
const cfg = cmd.db.config
|
|
939
|
+
if (!action || action === 'edit') {
|
|
940
|
+
cfg.edit(opts.editor)
|
|
941
|
+
return console.info(cfg.getAll())
|
|
942
|
+
} else if (action === 'list') {
|
|
943
|
+
return console.dir(
|
|
944
|
+
cfg.keys.map((key: string) => {
|
|
945
|
+
return {
|
|
946
|
+
key,
|
|
947
|
+
description: cfg.descriptions[key],
|
|
948
|
+
value: cfg.get(key),
|
|
949
|
+
defaultValue: cfg.defaultValues,
|
|
950
|
+
}
|
|
951
|
+
})
|
|
952
|
+
)
|
|
953
|
+
} else if (action === 'get') {
|
|
954
|
+
if (key) return console.log(cfg.get(key))
|
|
955
|
+
else return console.log(cfg.getAll())
|
|
956
|
+
} else if (action === 'set') {
|
|
957
|
+
const from = cfg.get(key)
|
|
958
|
+
const parse = cfg.parsers[key]
|
|
959
|
+
const to = typeof parse === 'function' ? cfg.parsers[key](value) : value
|
|
960
|
+
cfg.set(key, to)
|
|
961
|
+
return console.info({ changed: key, from, to })
|
|
962
|
+
} else if (action === 'reset') {
|
|
963
|
+
if (key) cfg.reset(key)
|
|
964
|
+
else cfg.resetAll()
|
|
965
|
+
return console.info(cfg.getAll())
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
)*/
|
|
969
|
+
}
|
|
970
|
+
})
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
/**
|
|
974
|
+
* Makes aliases for the command.
|
|
975
|
+
* The idea is to be able to navigate the command tree by only typing the first letter(s) of the command names.
|
|
976
|
+
*
|
|
977
|
+
* Example: A command 'cola' would get these aliases: ['c', 'co', 'col'].
|
|
978
|
+
* However, if there are namespace clashes with sibling subcommands that start with the same letter,
|
|
979
|
+
* eg. like 'cola' and 'coal' where the first two letters clash, cola's aliases are reduced to only ['col'] and similarly for 'coal'.
|
|
980
|
+
*
|
|
981
|
+
* This method creates the aliases, ensuring there are no clashes with sublings, why it is important that the
|
|
982
|
+
* entire command tree is built before invoking this method.
|
|
983
|
+
*/
|
|
984
|
+
protected assignSubCommandAliases() {
|
|
985
|
+
if (this.getAlias() || this.name.length <= 1) return this
|
|
986
|
+
const sibAliases = this.getSiblings()
|
|
987
|
+
.map((sib) => sib.getAliases())
|
|
988
|
+
.flat()
|
|
989
|
+
for (let i = 0; i < this.name.length - 1; i++) {
|
|
990
|
+
let cmdAlias = this.name.substring(0, i + 1)
|
|
991
|
+
let isClash = arrSome(sibAliases, (sibAlias) => {
|
|
992
|
+
return cmdAlias === sibAlias
|
|
993
|
+
})
|
|
994
|
+
if (isClash && i === 0) {
|
|
995
|
+
cmdAlias = cmdAlias.charAt(0).toUpperCase()
|
|
996
|
+
isClash = arrSome(sibAliases, (sibAlias) => {
|
|
997
|
+
return cmdAlias === sibAlias
|
|
998
|
+
})
|
|
999
|
+
}
|
|
1000
|
+
if (isClash) continue
|
|
1001
|
+
this.alias(cmdAlias)
|
|
1002
|
+
return this
|
|
1003
|
+
}
|
|
1004
|
+
return this
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
/**
|
|
1008
|
+
* Automatically set 'short' and 'long' names to options that don't have one assigned yet.
|
|
1009
|
+
*
|
|
1010
|
+
* First, it tries to assign a short name based on the first letter of the option's attribute name
|
|
1011
|
+
* Both lower and upper case are tried. If these is not available, the next letter of the option name is tried.
|
|
1012
|
+
*
|
|
1013
|
+
* If none of the letters of the option name are available, the option is skipped until all other
|
|
1014
|
+
* options have had letters from their names attempted assigned.
|
|
1015
|
+
* Those that remain are assigned the first available letter of the alphabet + 0-9.
|
|
1016
|
+
* If there are 64 options for the command and no more alphanumeric characters are available,
|
|
1017
|
+
* the option is not assigned a short name.
|
|
1018
|
+
*/
|
|
1019
|
+
protected assignMissingOptionFlags() {
|
|
1020
|
+
const taken = new Set<string>()
|
|
1021
|
+
for (const anc of this.getAncestorsIterator({ includeSelf: true })) {
|
|
1022
|
+
anc.options.forEach((opt) => {
|
|
1023
|
+
if (!opt.short) return
|
|
1024
|
+
taken.add(opt.short.replace(/^-/g, ''))
|
|
1025
|
+
})
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
const failed = new Set<Option>()
|
|
1029
|
+
|
|
1030
|
+
// assign letter from option name
|
|
1031
|
+
this.options.forEach((opt) => {
|
|
1032
|
+
if (opt.short) return
|
|
1033
|
+
const name = opt.attributeName()
|
|
1034
|
+
for (let c = 0; c < name.length; c++) {
|
|
1035
|
+
let char = name.charAt(c).toLowerCase()
|
|
1036
|
+
if (taken.has(char)) {
|
|
1037
|
+
char = char.toUpperCase()
|
|
1038
|
+
if (taken.has(char)) continue
|
|
1039
|
+
}
|
|
1040
|
+
OptionHelpers.setShort(opt, char)
|
|
1041
|
+
taken.add(char)
|
|
1042
|
+
return
|
|
1043
|
+
}
|
|
1044
|
+
failed.add(opt)
|
|
1045
|
+
})
|
|
1046
|
+
|
|
1047
|
+
// assign random alphanumeric character.
|
|
1048
|
+
const name = 'abcdefghijklmnopqrstuvwxyz1234567890'
|
|
1049
|
+
failed.forEach((opt) => {
|
|
1050
|
+
for (let c = 0; c < name.length; c++) {
|
|
1051
|
+
let char = name.charAt(c)
|
|
1052
|
+
if (taken.has(char)) {
|
|
1053
|
+
char = char.toUpperCase()
|
|
1054
|
+
if (taken.has(char)) continue
|
|
1055
|
+
}
|
|
1056
|
+
OptionHelpers.setShort(opt, char)
|
|
1057
|
+
taken.add(char)
|
|
1058
|
+
return
|
|
1059
|
+
}
|
|
1060
|
+
})
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
protected assertNoDuplicateCommandNames() {
|
|
1064
|
+
const names = this.$.commands.map((sub) => sub.aliases().concat(sub.name())).flat()
|
|
1065
|
+
if (names.length !== new Set(names).size) {
|
|
1066
|
+
this.throwCommanderError(
|
|
1067
|
+
`Duplicate subcommand names/aliases found for command, ${this.name}: ${names.join(', ')}`
|
|
1068
|
+
)
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
protected hasIdenticalParentOption(option: Option) {
|
|
1072
|
+
const flags = option.flags
|
|
1073
|
+
for (const anc of this.getAncestorsIterator({ includeSelf: true })) {
|
|
1074
|
+
for (const opt of anc.$.options) {
|
|
1075
|
+
if (flags === opt.flags) {
|
|
1076
|
+
return true
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
return false
|
|
1081
|
+
}
|
|
1082
|
+
protected assertNoDuplicateOptionNames() {
|
|
1083
|
+
const throwErr = (cmd: CommandBuilder, opt: string, anc?: CommandBuilder) => {
|
|
1084
|
+
this.throwCommanderError(
|
|
1085
|
+
`Duplicate option names > cmd: ${cmd.name}, ${anc ? `anc: ${anc.name}, ` : ''}opt: ${opt}`
|
|
1086
|
+
)
|
|
1087
|
+
}
|
|
1088
|
+
const set = new Set<string>()
|
|
1089
|
+
for (const opt of this.options) {
|
|
1090
|
+
if (opt.name() === 'help') continue
|
|
1091
|
+
if (opt.short) {
|
|
1092
|
+
if (set.has(opt.short)) throwErr(this, opt.short)
|
|
1093
|
+
set.add(opt.short)
|
|
1094
|
+
}
|
|
1095
|
+
if (opt.long) {
|
|
1096
|
+
if (set.has(opt.long)) throwErr(this, opt.long)
|
|
1097
|
+
set.add(opt.long)
|
|
1098
|
+
}
|
|
1099
|
+
if (opt.attributeName()) {
|
|
1100
|
+
if (set.has(opt.attributeName())) throwErr(this, opt.attributeName())
|
|
1101
|
+
set.add(opt.attributeName())
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
for (const anc of this.getAncestorsIterator()) {
|
|
1105
|
+
for (const opt of anc.$.options) {
|
|
1106
|
+
if (opt.short && set.has(opt.short)) {
|
|
1107
|
+
if (opt.short !== 'V') continue
|
|
1108
|
+
throwErr(this, opt.short, anc)
|
|
1109
|
+
}
|
|
1110
|
+
if (opt.long && set.has(opt.long)) {
|
|
1111
|
+
throwErr(this, opt.long, anc)
|
|
1112
|
+
}
|
|
1113
|
+
if (opt.attributeName() && set.has(opt.attributeName())) {
|
|
1114
|
+
throwErr(this, opt.attributeName(), anc)
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
protected initializeActionWrapper(isAsync = false) {
|
|
1120
|
+
if (isAsync) {
|
|
1121
|
+
this.$.action(async () => {
|
|
1122
|
+
try {
|
|
1123
|
+
this.handleOutputOptions()
|
|
1124
|
+
const [args, opts] = this.getParsedValidArgsOptsWithPresets()
|
|
1125
|
+
if (opts['help']) return this.outputHelp()
|
|
1126
|
+
type TArgs = typeof this.$.args
|
|
1127
|
+
const owg = this.$.optsWithGlobals()
|
|
1128
|
+
type TOpts = typeof owg
|
|
1129
|
+
await this.meta.actionHandler.call(this, ...(args as TArgs), opts as TOpts, this)
|
|
1130
|
+
} catch (error) {
|
|
1131
|
+
this.meta.errorHandler.call(this, error, this)
|
|
1132
|
+
}
|
|
1133
|
+
})
|
|
1134
|
+
} else {
|
|
1135
|
+
this.$.action(() => {
|
|
1136
|
+
try {
|
|
1137
|
+
this.handleOutputOptions()
|
|
1138
|
+
const [args, opts] = this.getParsedValidArgsOptsWithPresets()
|
|
1139
|
+
if (opts['help']) return this.outputHelp()
|
|
1140
|
+
// type TArgs = ReturnTypesOfFunctionArray<typeof this.meta.argParsers>
|
|
1141
|
+
// type TOpts = ReturnTypesOfFunctionMap<typeof this.meta.optParsers>
|
|
1142
|
+
type TArgs = typeof this.$.args
|
|
1143
|
+
const owg = this.$.optsWithGlobals()
|
|
1144
|
+
type TOpts = typeof owg
|
|
1145
|
+
this.meta.actionHandler.call(this, ...(args as TArgs), opts as TOpts, this)
|
|
1146
|
+
} catch (error) {
|
|
1147
|
+
this.meta.errorHandler.call(this, error, this)
|
|
1148
|
+
}
|
|
1149
|
+
})
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
protected initializeHelp() {
|
|
1154
|
+
if (this.isRoot) this.globalOption('-h, --help', 'show help')
|
|
1155
|
+
this.$.addHelpCommand('?', 'show help')
|
|
1156
|
+
this.$.configureHelp(DefaultHelpConfig)
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
protected inheritParentHiddenGlobals() {
|
|
1160
|
+
if (!this.parent) return
|
|
1161
|
+
for (const opt of this.parent.meta.hiddenGlobalOptions) {
|
|
1162
|
+
this.meta.hiddenGlobalOptions.add(opt)
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
protected assertCommandNameNotReserved(name: string) {
|
|
1167
|
+
if (this.isRoot) return
|
|
1168
|
+
if (this.meta.isNative) return
|
|
1169
|
+
if (name === 'u' || name === 'util') {
|
|
1170
|
+
this.throwCommanderError(`Name '${name}' is reserved and is not available as name or alias.`)
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
process.argv = splitCombinedArgvShorts(process.argv.slice())
|