@villedemontreal/caporal 3.1.7
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/LICENSE +21 -0
- package/README.md +29 -0
- package/dist/src/__tests__/issue-163.spec.d.ts +2 -0
- package/dist/src/__tests__/issue-163.spec.d.ts.map +1 -0
- package/dist/src/__tests__/issue-163.spec.js +17 -0
- package/dist/src/__tests__/issue-163.spec.js.map +1 -0
- package/dist/src/argument/__tests__/argument.spec.d.ts +2 -0
- package/dist/src/argument/__tests__/argument.spec.d.ts.map +1 -0
- package/dist/src/argument/__tests__/argument.spec.js +85 -0
- package/dist/src/argument/__tests__/argument.spec.js.map +1 -0
- package/dist/src/argument/find.d.ts +8 -0
- package/dist/src/argument/find.d.ts.map +1 -0
- package/dist/src/argument/find.js +11 -0
- package/dist/src/argument/find.js.map +1 -0
- package/dist/src/argument/index.d.ts +13 -0
- package/dist/src/argument/index.d.ts.map +1 -0
- package/dist/src/argument/index.js +27 -0
- package/dist/src/argument/index.js.map +1 -0
- package/dist/src/argument/synopsis.d.ts +19 -0
- package/dist/src/argument/synopsis.d.ts.map +1 -0
- package/dist/src/argument/synopsis.js +39 -0
- package/dist/src/argument/synopsis.js.map +1 -0
- package/dist/src/argument/validate.d.ts +43 -0
- package/dist/src/argument/validate.d.ts.map +1 -0
- package/dist/src/argument/validate.js +127 -0
- package/dist/src/argument/validate.js.map +1 -0
- package/dist/src/autocomplete/__fixtures__/prog-autocomplete.d.ts +3 -0
- package/dist/src/autocomplete/__fixtures__/prog-autocomplete.d.ts.map +1 -0
- package/dist/src/autocomplete/__fixtures__/prog-autocomplete.js +24 -0
- package/dist/src/autocomplete/__fixtures__/prog-autocomplete.js.map +1 -0
- package/dist/src/autocomplete/__tests__/autocomplete.spec.d.ts +2 -0
- package/dist/src/autocomplete/__tests__/autocomplete.spec.d.ts.map +1 -0
- package/dist/src/autocomplete/__tests__/autocomplete.spec.js +119 -0
- package/dist/src/autocomplete/__tests__/autocomplete.spec.js.map +1 -0
- package/dist/src/autocomplete/index.d.ts +20 -0
- package/dist/src/autocomplete/index.d.ts.map +1 -0
- package/dist/src/autocomplete/index.js +172 -0
- package/dist/src/autocomplete/index.js.map +1 -0
- package/dist/src/autocomplete/types.d.ts +26 -0
- package/dist/src/autocomplete/types.d.ts.map +1 -0
- package/dist/src/autocomplete/types.js +3 -0
- package/dist/src/autocomplete/types.js.map +1 -0
- package/dist/src/command/__fixtures__/example-cmd.d.ts +8 -0
- package/dist/src/command/__fixtures__/example-cmd.d.ts.map +1 -0
- package/dist/src/command/__fixtures__/example-cmd.js +10 -0
- package/dist/src/command/__fixtures__/example-cmd.js.map +1 -0
- package/dist/src/command/__tests__/command.spec.d.ts +2 -0
- package/dist/src/command/__tests__/command.spec.d.ts.map +1 -0
- package/dist/src/command/__tests__/command.spec.js +510 -0
- package/dist/src/command/__tests__/command.spec.js.map +1 -0
- package/dist/src/command/__tests__/find.spec.d.ts +2 -0
- package/dist/src/command/__tests__/find.spec.d.ts.map +1 -0
- package/dist/src/command/__tests__/find.spec.js +31 -0
- package/dist/src/command/__tests__/find.spec.js.map +1 -0
- package/dist/src/command/__tests__/import.spec.d.ts +2 -0
- package/dist/src/command/__tests__/import.spec.d.ts.map +1 -0
- package/dist/src/command/__tests__/import.spec.js +17 -0
- package/dist/src/command/__tests__/import.spec.js.map +1 -0
- package/dist/src/command/__tests__/scan.spec.d.ts +2 -0
- package/dist/src/command/__tests__/scan.spec.d.ts.map +1 -0
- package/dist/src/command/__tests__/scan.spec.js +20 -0
- package/dist/src/command/__tests__/scan.spec.js.map +1 -0
- package/dist/src/command/find.d.ts +8 -0
- package/dist/src/command/find.d.ts.map +1 -0
- package/dist/src/command/find.js +47 -0
- package/dist/src/command/find.js.map +1 -0
- package/dist/src/command/import.d.ts +7 -0
- package/dist/src/command/import.d.ts.map +1 -0
- package/dist/src/command/import.js +47 -0
- package/dist/src/command/import.js.map +1 -0
- package/dist/src/command/index.d.ts +211 -0
- package/dist/src/command/index.d.ts.map +1 -0
- package/dist/src/command/index.js +374 -0
- package/dist/src/command/index.js.map +1 -0
- package/dist/src/command/scan.d.ts +4 -0
- package/dist/src/command/scan.d.ts.map +1 -0
- package/dist/src/command/scan.js +31 -0
- package/dist/src/command/scan.js.map +1 -0
- package/dist/src/command/validate-call.d.ts +8 -0
- package/dist/src/command/validate-call.d.ts.map +1 -0
- package/dist/src/command/validate-call.js +13 -0
- package/dist/src/command/validate-call.js.map +1 -0
- package/dist/src/config/index.d.ts +7 -0
- package/dist/src/config/index.d.ts.map +1 -0
- package/dist/src/config/index.js +24 -0
- package/dist/src/config/index.js.map +1 -0
- package/dist/src/error/__tests__/fatal.spec.d.ts +2 -0
- package/dist/src/error/__tests__/fatal.spec.d.ts.map +1 -0
- package/dist/src/error/__tests__/fatal.spec.js +34 -0
- package/dist/src/error/__tests__/fatal.spec.js.map +1 -0
- package/dist/src/error/action.d.ts +9 -0
- package/dist/src/error/action.d.ts.map +1 -0
- package/dist/src/error/action.js +16 -0
- package/dist/src/error/action.js.map +1 -0
- package/dist/src/error/base.d.ts +11 -0
- package/dist/src/error/base.d.ts.map +1 -0
- package/dist/src/error/base.js +18 -0
- package/dist/src/error/base.js.map +1 -0
- package/dist/src/error/fatal.d.ts +10 -0
- package/dist/src/error/fatal.d.ts.map +1 -0
- package/dist/src/error/fatal.js +27 -0
- package/dist/src/error/fatal.js.map +1 -0
- package/dist/src/error/index.d.ts +18 -0
- package/dist/src/error/index.d.ts.map +1 -0
- package/dist/src/error/index.js +34 -0
- package/dist/src/error/index.js.map +1 -0
- package/dist/src/error/invalid-validator.d.ts +10 -0
- package/dist/src/error/invalid-validator.d.ts.map +1 -0
- package/dist/src/error/invalid-validator.js +15 -0
- package/dist/src/error/invalid-validator.js.map +1 -0
- package/dist/src/error/missing-argument.d.ts +11 -0
- package/dist/src/error/missing-argument.d.ts.map +1 -0
- package/dist/src/error/missing-argument.js +20 -0
- package/dist/src/error/missing-argument.js.map +1 -0
- package/dist/src/error/missing-flag.d.ts +11 -0
- package/dist/src/error/missing-flag.d.ts.map +1 -0
- package/dist/src/error/missing-flag.js +20 -0
- package/dist/src/error/missing-flag.js.map +1 -0
- package/dist/src/error/multi-validation.d.ts +10 -0
- package/dist/src/error/multi-validation.d.ts.map +1 -0
- package/dist/src/error/multi-validation.js +26 -0
- package/dist/src/error/multi-validation.js.map +1 -0
- package/dist/src/error/no-action.d.ts +10 -0
- package/dist/src/error/no-action.d.ts.map +1 -0
- package/dist/src/error/no-action.js +22 -0
- package/dist/src/error/no-action.js.map +1 -0
- package/dist/src/error/option-synopsis-syntax.d.ts +9 -0
- package/dist/src/error/option-synopsis-syntax.d.ts.map +1 -0
- package/dist/src/error/option-synopsis-syntax.js +15 -0
- package/dist/src/error/option-synopsis-syntax.js.map +1 -0
- package/dist/src/error/too-many-arguments.d.ts +11 -0
- package/dist/src/error/too-many-arguments.d.ts.map +1 -0
- package/dist/src/error/too-many-arguments.js +25 -0
- package/dist/src/error/too-many-arguments.js.map +1 -0
- package/dist/src/error/unknown-command.d.ts +13 -0
- package/dist/src/error/unknown-command.d.ts.map +1 -0
- package/dist/src/error/unknown-command.js +44 -0
- package/dist/src/error/unknown-command.js.map +1 -0
- package/dist/src/error/unknown-option.d.ts +13 -0
- package/dist/src/error/unknown-option.d.ts.map +1 -0
- package/dist/src/error/unknown-option.js +40 -0
- package/dist/src/error/unknown-option.js.map +1 -0
- package/dist/src/error/validation.d.ts +17 -0
- package/dist/src/error/validation.d.ts.map +1 -0
- package/dist/src/error/validation.js +49 -0
- package/dist/src/error/validation.js.map +1 -0
- package/dist/src/help/__tests__/help.spec.d.ts +2 -0
- package/dist/src/help/__tests__/help.spec.d.ts.map +1 -0
- package/dist/src/help/__tests__/help.spec.js +130 -0
- package/dist/src/help/__tests__/help.spec.js.map +1 -0
- package/dist/src/help/__tests__/utils.spec.d.ts +2 -0
- package/dist/src/help/__tests__/utils.spec.d.ts.map +1 -0
- package/dist/src/help/__tests__/utils.spec.js +16 -0
- package/dist/src/help/__tests__/utils.spec.js.map +1 -0
- package/dist/src/help/index.d.ts +47 -0
- package/dist/src/help/index.d.ts.map +1 -0
- package/dist/src/help/index.js +131 -0
- package/dist/src/help/index.js.map +1 -0
- package/dist/src/help/templates/command.d.ts +7 -0
- package/dist/src/help/templates/command.d.ts.map +1 -0
- package/dist/src/help/templates/command.js +23 -0
- package/dist/src/help/templates/command.js.map +1 -0
- package/dist/src/help/templates/custom.d.ts +7 -0
- package/dist/src/help/templates/custom.d.ts.map +1 -0
- package/dist/src/help/templates/custom.js +24 -0
- package/dist/src/help/templates/custom.js.map +1 -0
- package/dist/src/help/templates/header.d.ts +7 -0
- package/dist/src/help/templates/header.d.ts.map +1 -0
- package/dist/src/help/templates/header.js +16 -0
- package/dist/src/help/templates/header.js.map +1 -0
- package/dist/src/help/templates/index.d.ts +10 -0
- package/dist/src/help/templates/index.d.ts.map +1 -0
- package/dist/src/help/templates/index.js +26 -0
- package/dist/src/help/templates/index.js.map +1 -0
- package/dist/src/help/templates/program.d.ts +7 -0
- package/dist/src/help/templates/program.d.ts.map +1 -0
- package/dist/src/help/templates/program.js +18 -0
- package/dist/src/help/templates/program.js.map +1 -0
- package/dist/src/help/templates/usage.d.ts +7 -0
- package/dist/src/help/templates/usage.d.ts.map +1 -0
- package/dist/src/help/templates/usage.js +19 -0
- package/dist/src/help/templates/usage.js.map +1 -0
- package/dist/src/help/types.d.ts +53 -0
- package/dist/src/help/types.d.ts.map +1 -0
- package/dist/src/help/types.js +3 -0
- package/dist/src/help/types.js.map +1 -0
- package/dist/src/help/utils.d.ts +9 -0
- package/dist/src/help/utils.d.ts.map +1 -0
- package/dist/src/help/utils.js +92 -0
- package/dist/src/help/utils.js.map +1 -0
- package/dist/src/index.d.ts +90 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +111 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/logger/__tests__/logger.spec.d.ts +2 -0
- package/dist/src/logger/__tests__/logger.spec.d.ts.map +1 -0
- package/dist/src/logger/__tests__/logger.spec.js +56 -0
- package/dist/src/logger/__tests__/logger.spec.js.map +1 -0
- package/dist/src/logger/index.d.ts +6 -0
- package/dist/src/logger/index.d.ts.map +1 -0
- package/dist/src/logger/index.js +128 -0
- package/dist/src/logger/index.js.map +1 -0
- package/dist/src/option/__tests__/global.spec.d.ts +2 -0
- package/dist/src/option/__tests__/global.spec.d.ts.map +1 -0
- package/dist/src/option/__tests__/global.spec.js +121 -0
- package/dist/src/option/__tests__/global.spec.js.map +1 -0
- package/dist/src/option/__tests__/option.spec.d.ts +2 -0
- package/dist/src/option/__tests__/option.spec.d.ts.map +1 -0
- package/dist/src/option/__tests__/option.spec.js +111 -0
- package/dist/src/option/__tests__/option.spec.js.map +1 -0
- package/dist/src/option/find.d.ts +14 -0
- package/dist/src/option/find.d.ts.map +1 -0
- package/dist/src/option/find.js +17 -0
- package/dist/src/option/find.js.map +1 -0
- package/dist/src/option/index.d.ts +65 -0
- package/dist/src/option/index.d.ts.map +1 -0
- package/dist/src/option/index.js +230 -0
- package/dist/src/option/index.js.map +1 -0
- package/dist/src/option/mapping.d.ts +7 -0
- package/dist/src/option/mapping.d.ts.map +1 -0
- package/dist/src/option/mapping.js +21 -0
- package/dist/src/option/mapping.js.map +1 -0
- package/dist/src/option/utils.d.ts +35 -0
- package/dist/src/option/utils.d.ts.map +1 -0
- package/dist/src/option/utils.js +139 -0
- package/dist/src/option/utils.js.map +1 -0
- package/dist/src/option/validate.d.ts +15 -0
- package/dist/src/option/validate.d.ts.map +1 -0
- package/dist/src/option/validate.js +63 -0
- package/dist/src/option/validate.js.map +1 -0
- package/dist/src/parser/__tests__/parser.spec.d.ts +2 -0
- package/dist/src/parser/__tests__/parser.spec.d.ts.map +1 -0
- package/dist/src/parser/__tests__/parser.spec.js +343 -0
- package/dist/src/parser/__tests__/parser.spec.js.map +1 -0
- package/dist/src/parser/index.d.ts +17 -0
- package/dist/src/parser/index.d.ts.map +1 -0
- package/dist/src/parser/index.js +299 -0
- package/dist/src/parser/index.js.map +1 -0
- package/dist/src/program/__tests__/program.spec.d.ts +2 -0
- package/dist/src/program/__tests__/program.spec.d.ts.map +1 -0
- package/dist/src/program/__tests__/program.spec.js +261 -0
- package/dist/src/program/__tests__/program.spec.js.map +1 -0
- package/dist/src/program/index.d.ts +349 -0
- package/dist/src/program/index.d.ts.map +1 -0
- package/dist/src/program/index.js +584 -0
- package/dist/src/program/index.js.map +1 -0
- package/dist/src/types.d.ts +396 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +51 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils/__tests__/fs.spec.d.ts +2 -0
- package/dist/src/utils/__tests__/fs.spec.d.ts.map +1 -0
- package/dist/src/utils/__tests__/fs.spec.js +14 -0
- package/dist/src/utils/__tests__/fs.spec.js.map +1 -0
- package/dist/src/utils/__tests__/levenshtein.spec.d.ts +2 -0
- package/dist/src/utils/__tests__/levenshtein.spec.d.ts.map +1 -0
- package/dist/src/utils/__tests__/levenshtein.spec.js +18 -0
- package/dist/src/utils/__tests__/levenshtein.spec.js.map +1 -0
- package/dist/src/utils/__tests__/suggest.spec.d.ts +2 -0
- package/dist/src/utils/__tests__/suggest.spec.d.ts.map +1 -0
- package/dist/src/utils/__tests__/suggest.spec.js +31 -0
- package/dist/src/utils/__tests__/suggest.spec.js.map +1 -0
- package/dist/src/utils/colorize.d.ts +2 -0
- package/dist/src/utils/colorize.d.ts.map +1 -0
- package/dist/src/utils/colorize.js +27 -0
- package/dist/src/utils/colorize.js.map +1 -0
- package/dist/src/utils/fs.d.ts +2 -0
- package/dist/src/utils/fs.d.ts.map +1 -0
- package/dist/src/utils/fs.js +19 -0
- package/dist/src/utils/fs.js.map +1 -0
- package/dist/src/utils/levenshtein.d.ts +6 -0
- package/dist/src/utils/levenshtein.d.ts.map +1 -0
- package/dist/src/utils/levenshtein.js +32 -0
- package/dist/src/utils/levenshtein.js.map +1 -0
- package/dist/src/utils/suggest.d.ts +15 -0
- package/dist/src/utils/suggest.d.ts.map +1 -0
- package/dist/src/utils/suggest.js +49 -0
- package/dist/src/utils/suggest.js.map +1 -0
- package/dist/src/utils/version.d.ts +2 -0
- package/dist/src/utils/version.d.ts.map +1 -0
- package/dist/src/utils/version.js +21 -0
- package/dist/src/utils/version.js.map +1 -0
- package/dist/src/utils/web/autocomplete.d.ts +12 -0
- package/dist/src/utils/web/autocomplete.d.ts.map +1 -0
- package/dist/src/utils/web/autocomplete.js +12 -0
- package/dist/src/utils/web/autocomplete.js.map +1 -0
- package/dist/src/utils/web/process.d.ts +15 -0
- package/dist/src/utils/web/process.d.ts.map +1 -0
- package/dist/src/utils/web/process.js +29 -0
- package/dist/src/utils/web/process.js.map +1 -0
- package/dist/src/validator/__tests__/array.spec.d.ts +2 -0
- package/dist/src/validator/__tests__/array.spec.d.ts.map +1 -0
- package/dist/src/validator/__tests__/array.spec.js +34 -0
- package/dist/src/validator/__tests__/array.spec.js.map +1 -0
- package/dist/src/validator/__tests__/caporal.spec.d.ts +2 -0
- package/dist/src/validator/__tests__/caporal.spec.d.ts.map +1 -0
- package/dist/src/validator/__tests__/caporal.spec.js +86 -0
- package/dist/src/validator/__tests__/caporal.spec.js.map +1 -0
- package/dist/src/validator/__tests__/function.spec.d.ts +2 -0
- package/dist/src/validator/__tests__/function.spec.d.ts.map +1 -0
- package/dist/src/validator/__tests__/function.spec.js +42 -0
- package/dist/src/validator/__tests__/function.spec.js.map +1 -0
- package/dist/src/validator/__tests__/regexp.spec.d.ts +2 -0
- package/dist/src/validator/__tests__/regexp.spec.d.ts.map +1 -0
- package/dist/src/validator/__tests__/regexp.spec.js +34 -0
- package/dist/src/validator/__tests__/regexp.spec.js.map +1 -0
- package/dist/src/validator/__tests__/utils.spec.d.ts +2 -0
- package/dist/src/validator/__tests__/utils.spec.d.ts.map +1 -0
- package/dist/src/validator/__tests__/utils.spec.js +66 -0
- package/dist/src/validator/__tests__/utils.spec.js.map +1 -0
- package/dist/src/validator/__tests__/validate.spec.d.ts +2 -0
- package/dist/src/validator/__tests__/validate.spec.d.ts.map +1 -0
- package/dist/src/validator/__tests__/validate.spec.js +25 -0
- package/dist/src/validator/__tests__/validate.spec.js.map +1 -0
- package/dist/src/validator/array.d.ts +14 -0
- package/dist/src/validator/array.d.ts.map +1 -0
- package/dist/src/validator/array.js +29 -0
- package/dist/src/validator/array.js.map +1 -0
- package/dist/src/validator/caporal.d.ts +25 -0
- package/dist/src/validator/caporal.d.ts.map +1 -0
- package/dist/src/validator/caporal.js +89 -0
- package/dist/src/validator/caporal.js.map +1 -0
- package/dist/src/validator/function.d.ts +7 -0
- package/dist/src/validator/function.d.ts.map +1 -0
- package/dist/src/validator/function.js +27 -0
- package/dist/src/validator/function.js.map +1 -0
- package/dist/src/validator/regexp.d.ts +14 -0
- package/dist/src/validator/regexp.d.ts.map +1 -0
- package/dist/src/validator/regexp.js +31 -0
- package/dist/src/validator/regexp.js.map +1 -0
- package/dist/src/validator/utils.d.ts +14 -0
- package/dist/src/validator/utils.d.ts.map +1 -0
- package/dist/src/validator/utils.js +81 -0
- package/dist/src/validator/utils.js.map +1 -0
- package/dist/src/validator/validate.d.ts +7 -0
- package/dist/src/validator/validate.d.ts.map +1 -0
- package/dist/src/validator/validate.js +29 -0
- package/dist/src/validator/validate.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +75 -0
- package/src/__tests__/issue-163.spec.ts +18 -0
- package/src/argument/__tests__/argument.spec.ts +84 -0
- package/src/argument/find.ts +11 -0
- package/src/argument/index.ts +35 -0
- package/src/argument/synopsis.ts +41 -0
- package/src/argument/validate.ts +176 -0
- package/src/autocomplete/__fixtures__/prog-autocomplete.ts +24 -0
- package/src/autocomplete/__tests__/autocomplete.spec.ts +129 -0
- package/src/autocomplete/index.ts +225 -0
- package/src/autocomplete/types.ts +29 -0
- package/src/command/__fixtures__/example-cmd.ts +14 -0
- package/src/command/__tests__/command.spec.ts +621 -0
- package/src/command/__tests__/find.spec.ts +32 -0
- package/src/command/__tests__/import.spec.ts +14 -0
- package/src/command/__tests__/scan.spec.ts +16 -0
- package/src/command/find.ts +57 -0
- package/src/command/import.ts +13 -0
- package/src/command/index.ts +458 -0
- package/src/command/scan.ts +30 -0
- package/src/command/validate-call.ts +19 -0
- package/src/config/index.ts +26 -0
- package/src/error/__tests__/fatal.spec.ts +38 -0
- package/src/error/action.ts +13 -0
- package/src/error/base.ts +20 -0
- package/src/error/fatal.ts +25 -0
- package/src/error/index.ts +17 -0
- package/src/error/invalid-validator.ts +12 -0
- package/src/error/missing-argument.ts +16 -0
- package/src/error/missing-flag.ts +16 -0
- package/src/error/multi-validation.ts +22 -0
- package/src/error/no-action.ts +19 -0
- package/src/error/option-synopsis-syntax.ts +12 -0
- package/src/error/too-many-arguments.ts +28 -0
- package/src/error/unknown-command.ts +41 -0
- package/src/error/unknown-option.ts +40 -0
- package/src/error/validation.ts +80 -0
- package/src/help/__tests__/__snapshots__/help.spec.ts.snap +334 -0
- package/src/help/__tests__/help.spec.ts +144 -0
- package/src/help/__tests__/utils.spec.ts +14 -0
- package/src/help/index.ts +107 -0
- package/src/help/templates/command.ts +27 -0
- package/src/help/templates/custom.ts +25 -0
- package/src/help/templates/header.ts +19 -0
- package/src/help/templates/index.ts +9 -0
- package/src/help/templates/program.ts +21 -0
- package/src/help/templates/usage.ts +24 -0
- package/src/help/types.ts +57 -0
- package/src/help/utils.ts +109 -0
- package/src/index.ts +93 -0
- package/src/logger/__tests__/logger.spec.ts +65 -0
- package/src/logger/index.ts +97 -0
- package/src/option/__tests__/global.spec.ts +141 -0
- package/src/option/__tests__/option.spec.ts +115 -0
- package/src/option/find.ts +17 -0
- package/src/option/index.ts +280 -0
- package/src/option/mapping.ts +17 -0
- package/src/option/utils.ts +141 -0
- package/src/option/validate.ts +80 -0
- package/src/parser/__tests__/parser.spec.ts +371 -0
- package/src/parser/index.ts +383 -0
- package/src/program/__tests__/program.spec.ts +316 -0
- package/src/program/index.ts +676 -0
- package/src/types.ts +432 -0
- package/src/utils/__tests__/fs.spec.ts +14 -0
- package/src/utils/__tests__/levenshtein.spec.ts +16 -0
- package/src/utils/__tests__/suggest.spec.ts +30 -0
- package/src/utils/colorize.ts +21 -0
- package/src/utils/fs.ts +13 -0
- package/src/utils/levenshtein.ts +28 -0
- package/src/utils/suggest.ts +52 -0
- package/src/utils/version.ts +14 -0
- package/src/utils/web/autocomplete.ts +19 -0
- package/src/utils/web/process.ts +24 -0
- package/src/validator/__tests__/array.spec.ts +41 -0
- package/src/validator/__tests__/caporal.spec.ts +132 -0
- package/src/validator/__tests__/function.spec.ts +52 -0
- package/src/validator/__tests__/regexp.spec.ts +38 -0
- package/src/validator/__tests__/utils.spec.ts +67 -0
- package/src/validator/__tests__/validate.spec.ts +24 -0
- package/src/validator/array.ts +31 -0
- package/src/validator/caporal.ts +104 -0
- package/src/validator/function.ts +31 -0
- package/src/validator/regexp.ts +34 -0
- package/src/validator/utils.ts +84 -0
- package/src/validator/validate.ts +38 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { program } from "../../index"
|
|
3
|
+
import { Program } from "../../program"
|
|
4
|
+
import { logger } from ".."
|
|
5
|
+
import c from "chalk"
|
|
6
|
+
import stripAnsi from "strip-ansi"
|
|
7
|
+
import { expect, it, describe, beforeEach, vi } from "vitest"
|
|
8
|
+
import { EOL } from "os"
|
|
9
|
+
|
|
10
|
+
describe("logger", () => {
|
|
11
|
+
// @ts-expect-error TS says _stdout does note exist on console but it does
|
|
12
|
+
const logStdoutSpy = vi.spyOn(console._stdout, "write") // winston use this
|
|
13
|
+
let prog = program
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
prog = new Program()
|
|
17
|
+
prog.name("test-prog")
|
|
18
|
+
prog.bin("test-prog")
|
|
19
|
+
prog.version("xyz")
|
|
20
|
+
logStdoutSpy.mockClear()
|
|
21
|
+
logger.level = "info"
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it("logger should handle metadata", () => {
|
|
25
|
+
logger.info("foo", { blabla: "joe" })
|
|
26
|
+
expect(stripAnsi(logStdoutSpy.mock.calls[0][0] as unknown as string)).toBe(
|
|
27
|
+
`info: foo${EOL}info: { blabla: 'joe' }${EOL}`,
|
|
28
|
+
)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it("level string should be colorized by default", () => {
|
|
32
|
+
logger.info("my-info")
|
|
33
|
+
expect(logStdoutSpy).toHaveBeenLastCalledWith(
|
|
34
|
+
`${c.hex("#569cd6")("info")}: my-info${EOL}`,
|
|
35
|
+
)
|
|
36
|
+
logger.warn("my-warn")
|
|
37
|
+
expect(logStdoutSpy).toHaveBeenLastCalledWith(
|
|
38
|
+
`${c.hex("#FF9900")("warn")}: my-warn${EOL}`,
|
|
39
|
+
)
|
|
40
|
+
logger.error("my-error")
|
|
41
|
+
expect(logStdoutSpy).toHaveBeenLastCalledWith(
|
|
42
|
+
`${EOL}${c.bold.redBright("error")}: my-error${EOL}${EOL}`,
|
|
43
|
+
)
|
|
44
|
+
// set level to "debug" for the next test
|
|
45
|
+
logger.level = "debug"
|
|
46
|
+
logger.debug("my-debug")
|
|
47
|
+
expect(logStdoutSpy).toHaveBeenLastCalledWith(`${c.dim("debug")}: my-debug${EOL}`)
|
|
48
|
+
|
|
49
|
+
// set level to "silly" for the next test
|
|
50
|
+
logger.level = "silly"
|
|
51
|
+
logger.silly("my-silly")
|
|
52
|
+
expect(logStdoutSpy).toHaveBeenLastCalledWith(`${c.dim("silly")}: my-silly${EOL}`)
|
|
53
|
+
|
|
54
|
+
logger.http("foo")
|
|
55
|
+
expect(logStdoutSpy).toHaveBeenLastCalledWith(`http: foo${EOL}`)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it("logger.disableColors() should disable colors", () => {
|
|
59
|
+
logger.disableColors()
|
|
60
|
+
logger.info("my-info")
|
|
61
|
+
expect(logStdoutSpy).toHaveBeenLastCalledWith(`info: my-info${EOL}`)
|
|
62
|
+
// revert back
|
|
63
|
+
logger.colorsEnabled = true
|
|
64
|
+
})
|
|
65
|
+
})
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
import { createLogger as winstonCreateLogger, transports, format } from "winston"
|
|
6
|
+
import { inspect } from "util"
|
|
7
|
+
import { default as chalk, supportsColor } from "chalk"
|
|
8
|
+
import type { Logger } from "../types"
|
|
9
|
+
import replace from "lodash/replace"
|
|
10
|
+
import { EOL } from "os"
|
|
11
|
+
|
|
12
|
+
const caporalFormat = format.printf((data) => {
|
|
13
|
+
const { level, ...meta } = data
|
|
14
|
+
let { message } = data
|
|
15
|
+
let prefix = ""
|
|
16
|
+
|
|
17
|
+
const levelStr = getLevelString(level)
|
|
18
|
+
const metaStr = formatMeta(meta)
|
|
19
|
+
|
|
20
|
+
if (metaStr !== "") {
|
|
21
|
+
message += `${EOL}${levelStr}: ${metaStr}`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (level === "error") {
|
|
25
|
+
const spaces = " ".repeat(Number(meta.paddingLeft) || 7)
|
|
26
|
+
prefix = EOL
|
|
27
|
+
message = `${replace(message.toString(), new RegExp(EOL, "g"), EOL + spaces)}${EOL}`
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return `${prefix}${levelStr}: ${message}`
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
function formatMeta(meta: Record<string, unknown>): string {
|
|
34
|
+
delete meta.message
|
|
35
|
+
delete meta[Symbol.for("level") as unknown as string]
|
|
36
|
+
delete meta[Symbol.for("message") as unknown as string]
|
|
37
|
+
delete meta[Symbol.for("splat") as unknown as string]
|
|
38
|
+
if (Object.keys(meta).length) {
|
|
39
|
+
return inspect(meta, {
|
|
40
|
+
showHidden: false,
|
|
41
|
+
colors: logger.colorsEnabled,
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
return ""
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function getLevelString(level: string): string {
|
|
48
|
+
if (!logger.colorsEnabled) {
|
|
49
|
+
return level
|
|
50
|
+
}
|
|
51
|
+
let levelStr = level
|
|
52
|
+
switch (level) {
|
|
53
|
+
case "error":
|
|
54
|
+
levelStr = chalk.bold.redBright(level)
|
|
55
|
+
break
|
|
56
|
+
case "warn":
|
|
57
|
+
levelStr = chalk.hex("#FF9900")(level)
|
|
58
|
+
break
|
|
59
|
+
case "info":
|
|
60
|
+
levelStr = chalk.hex("#569cd6")(level)
|
|
61
|
+
break
|
|
62
|
+
case "debug":
|
|
63
|
+
case "silly":
|
|
64
|
+
levelStr = chalk.dim(level)
|
|
65
|
+
break
|
|
66
|
+
}
|
|
67
|
+
return levelStr
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export let logger: Logger = createDefaultLogger()
|
|
71
|
+
|
|
72
|
+
export function setLogger(loggerObj: Logger): void {
|
|
73
|
+
logger = loggerObj
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function getLogger(): Logger {
|
|
77
|
+
return logger
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function createDefaultLogger(): Logger {
|
|
81
|
+
const logger = winstonCreateLogger({
|
|
82
|
+
transports: [
|
|
83
|
+
new transports.Console({
|
|
84
|
+
format: format.combine(format.splat(), caporalFormat),
|
|
85
|
+
}),
|
|
86
|
+
],
|
|
87
|
+
}) as Logger
|
|
88
|
+
// disableColors() disable on the logger level,
|
|
89
|
+
// while chalk supports the --color/--no-color flag
|
|
90
|
+
// as well as the FORCE_COLOR env var
|
|
91
|
+
logger.disableColors = () => {
|
|
92
|
+
logger.transports[0].format = caporalFormat
|
|
93
|
+
logger.colorsEnabled = false
|
|
94
|
+
}
|
|
95
|
+
logger.colorsEnabled = supportsColor !== false
|
|
96
|
+
return logger
|
|
97
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { program } from "../../index"
|
|
3
|
+
import { Program } from "../../program"
|
|
4
|
+
import { logger } from "../../logger"
|
|
5
|
+
import { Action } from "../../types"
|
|
6
|
+
import { disableGlobalOption, findGlobalOption, resetGlobalOptions } from ".."
|
|
7
|
+
import { expect, it, describe, vi, beforeEach, afterAll } from "vitest"
|
|
8
|
+
|
|
9
|
+
let prog = program
|
|
10
|
+
|
|
11
|
+
describe("option / global", () => {
|
|
12
|
+
const logSpy = vi.spyOn(console, "log")
|
|
13
|
+
// @ts-expect-error TS says _stdout does note exist on console but it does
|
|
14
|
+
const logStdoutSpy = vi.spyOn(console._stdout, "write") // winston use this
|
|
15
|
+
const loggerInfoSpy = vi.spyOn(logger, "info")
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
prog = new Program()
|
|
19
|
+
prog.name("test-prog")
|
|
20
|
+
prog.bin("test-prog")
|
|
21
|
+
prog.version("xyz")
|
|
22
|
+
logSpy.mockClear()
|
|
23
|
+
logStdoutSpy.mockClear()
|
|
24
|
+
logger.level = "info"
|
|
25
|
+
logger.colorsEnabled = true
|
|
26
|
+
resetGlobalOptions()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
afterAll(() => {
|
|
30
|
+
logger.colorsEnabled = true
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it("-V should show program version and exit", async () => {
|
|
34
|
+
await prog.run(["-V"])
|
|
35
|
+
expect(logSpy).toHaveBeenLastCalledWith("xyz")
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it("--version should show program version and exit", async () => {
|
|
39
|
+
await prog.run(["--version"])
|
|
40
|
+
expect(logSpy).toHaveBeenLastCalledWith("xyz")
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it("--no-color should disable colors in output", async () => {
|
|
44
|
+
const action: Action = function ({ logger }) {
|
|
45
|
+
logger.info("Hey!")
|
|
46
|
+
}
|
|
47
|
+
prog.argument("[first-arg]", "First argument").action(action)
|
|
48
|
+
await prog.run(["--no-color", "foo"])
|
|
49
|
+
expect(loggerInfoSpy).toHaveBeenLastCalledWith("Hey!")
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it("--color false should disable colors in output", async () => {
|
|
53
|
+
const action: Action = function ({ logger }) {
|
|
54
|
+
logger.info("Joe!")
|
|
55
|
+
}
|
|
56
|
+
prog.argument("[first-arg]", "First argument").action(action)
|
|
57
|
+
await prog.run(["--color", "false", "foo"])
|
|
58
|
+
expect(loggerInfoSpy).toHaveBeenLastCalledWith("Joe!")
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it("-v should enable verbosity", async () => {
|
|
62
|
+
const action: Action = function ({ logger }) {
|
|
63
|
+
logger.info("my-info")
|
|
64
|
+
logger.debug("my-debug")
|
|
65
|
+
}
|
|
66
|
+
prog.argument("[first-arg]", "First argument").action(action)
|
|
67
|
+
|
|
68
|
+
await prog.run(["foo"])
|
|
69
|
+
expect(logStdoutSpy).toHaveBeenLastCalledWith(expect.stringContaining("my-info"))
|
|
70
|
+
|
|
71
|
+
await prog.run(["foo", "-v"])
|
|
72
|
+
expect(logStdoutSpy).toHaveBeenLastCalledWith(expect.stringContaining("my-debug"))
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it("--verbose should enable verbosity", async () => {
|
|
76
|
+
const action: Action = function ({ logger }) {
|
|
77
|
+
logger.info("my-info")
|
|
78
|
+
logger.debug("my-debug")
|
|
79
|
+
}
|
|
80
|
+
prog.argument("[first-arg]", "First argument").action(action)
|
|
81
|
+
|
|
82
|
+
await prog.run(["foo"])
|
|
83
|
+
expect(logStdoutSpy).toHaveBeenLastCalledWith(expect.stringContaining("my-info"))
|
|
84
|
+
|
|
85
|
+
await prog.run(["foo", "--verbose"])
|
|
86
|
+
expect(logStdoutSpy).toHaveBeenLastCalledWith(expect.stringContaining("my-debug"))
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it("--quiet should make the program only output warnings and errors", async () => {
|
|
90
|
+
const action: Action = function ({ logger }) {
|
|
91
|
+
logger.info("my-info")
|
|
92
|
+
logger.debug("my-debug")
|
|
93
|
+
logger.warn("my-warn")
|
|
94
|
+
logger.error("my-error")
|
|
95
|
+
}
|
|
96
|
+
prog.argument("[first-arg]", "First argument").action(action)
|
|
97
|
+
|
|
98
|
+
await prog.run(["foo", "--quiet"])
|
|
99
|
+
expect(logStdoutSpy).not.toHaveBeenCalledWith(expect.stringContaining("my-info"))
|
|
100
|
+
expect(logStdoutSpy).not.toHaveBeenCalledWith(expect.stringContaining("my-debug"))
|
|
101
|
+
expect(logStdoutSpy).toHaveBeenCalledWith(expect.stringContaining("my-warn"))
|
|
102
|
+
expect(logStdoutSpy).toHaveBeenCalledWith(expect.stringContaining("my-error"))
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
it("--silent should output nothing", async () => {
|
|
106
|
+
const action: Action = function ({ logger }) {
|
|
107
|
+
logger.info("my-info")
|
|
108
|
+
logger.debug("my-debug")
|
|
109
|
+
logger.warn("my-warn")
|
|
110
|
+
logger.error("my-error")
|
|
111
|
+
}
|
|
112
|
+
prog.argument("[first-arg]", "First argument").action(action)
|
|
113
|
+
|
|
114
|
+
await prog.run(["foo", "--silent"])
|
|
115
|
+
expect(logStdoutSpy).not.toHaveBeenCalled()
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it("disableGlobalOption() should disable a global option by name or notation", async () => {
|
|
119
|
+
// by notation
|
|
120
|
+
expect(findGlobalOption("version")).toBeTruthy()
|
|
121
|
+
const result = disableGlobalOption("-V")
|
|
122
|
+
expect(result).toBe(true)
|
|
123
|
+
expect(findGlobalOption("version")).toBeUndefined()
|
|
124
|
+
|
|
125
|
+
// by name
|
|
126
|
+
expect(findGlobalOption("help")).toBeTruthy()
|
|
127
|
+
const result2 = disableGlobalOption("help")
|
|
128
|
+
expect(result2).toBe(true)
|
|
129
|
+
expect(findGlobalOption("help")).toBeUndefined()
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
it("disableGlobalOption() should return false for an unknown global option", async () => {
|
|
133
|
+
// by notation
|
|
134
|
+
const result = disableGlobalOption("--unknown")
|
|
135
|
+
expect(result).toBe(false)
|
|
136
|
+
|
|
137
|
+
// by name
|
|
138
|
+
const result2 = disableGlobalOption("unknown")
|
|
139
|
+
expect(result2).toBe(false)
|
|
140
|
+
})
|
|
141
|
+
})
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { createOption } from ".."
|
|
2
|
+
import { OptionSynopsisSyntaxError } from "../../error"
|
|
3
|
+
import { expect, it, describe } from "vitest"
|
|
4
|
+
|
|
5
|
+
describe("createOption()", () => {
|
|
6
|
+
it("should create a basic short option", () => {
|
|
7
|
+
const opt = createOption("-f <file>", "My simple option")
|
|
8
|
+
expect(opt).toMatchObject({
|
|
9
|
+
allNames: ["f"],
|
|
10
|
+
allNotations: ["-f"],
|
|
11
|
+
shortName: "f",
|
|
12
|
+
shortNotation: "-f",
|
|
13
|
+
description: "My simple option",
|
|
14
|
+
choices: [],
|
|
15
|
+
name: "f",
|
|
16
|
+
valueType: 1,
|
|
17
|
+
boolean: false,
|
|
18
|
+
valueRequired: true,
|
|
19
|
+
required: false,
|
|
20
|
+
synopsis: "-f <file>",
|
|
21
|
+
variadic: false,
|
|
22
|
+
visible: true,
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
it("should create a basic long option", () => {
|
|
26
|
+
const opt = createOption("--file <file>", "My simple option")
|
|
27
|
+
expect(opt).toMatchObject({
|
|
28
|
+
allNames: ["file"],
|
|
29
|
+
allNotations: ["--file"],
|
|
30
|
+
longName: "file",
|
|
31
|
+
longNotation: "--file",
|
|
32
|
+
description: "My simple option",
|
|
33
|
+
choices: [],
|
|
34
|
+
name: "file",
|
|
35
|
+
valueType: 1,
|
|
36
|
+
boolean: false,
|
|
37
|
+
valueRequired: true,
|
|
38
|
+
required: false,
|
|
39
|
+
synopsis: "--file <file>",
|
|
40
|
+
variadic: false,
|
|
41
|
+
visible: true,
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
it("should create a short option without value", () => {
|
|
45
|
+
const opt = createOption("-f", "My simple option")
|
|
46
|
+
expect(opt).toMatchObject({
|
|
47
|
+
allNames: ["f"],
|
|
48
|
+
allNotations: ["-f"],
|
|
49
|
+
shortName: "f",
|
|
50
|
+
shortNotation: "-f",
|
|
51
|
+
description: "My simple option",
|
|
52
|
+
choices: [],
|
|
53
|
+
name: "f",
|
|
54
|
+
boolean: true,
|
|
55
|
+
valueRequired: false,
|
|
56
|
+
valueType: 2,
|
|
57
|
+
default: false,
|
|
58
|
+
required: false,
|
|
59
|
+
synopsis: "-f",
|
|
60
|
+
variadic: false,
|
|
61
|
+
visible: true,
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
it("should create a short option with optional value", () => {
|
|
65
|
+
const opt = createOption("-p [mean]", "My simple option")
|
|
66
|
+
expect(opt).toMatchObject({
|
|
67
|
+
allNames: ["p"],
|
|
68
|
+
allNotations: ["-p"],
|
|
69
|
+
shortName: "p",
|
|
70
|
+
shortNotation: "-p",
|
|
71
|
+
description: "My simple option",
|
|
72
|
+
choices: [],
|
|
73
|
+
name: "p",
|
|
74
|
+
boolean: false,
|
|
75
|
+
valueRequired: false,
|
|
76
|
+
valueType: 0,
|
|
77
|
+
required: false,
|
|
78
|
+
synopsis: "-p [mean]",
|
|
79
|
+
variadic: false,
|
|
80
|
+
visible: true,
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
it("should set choices if validator is an array", () => {
|
|
84
|
+
const opt = createOption("-p [mean]", "My simple option", {
|
|
85
|
+
validator: ["card", "cash"],
|
|
86
|
+
})
|
|
87
|
+
expect(opt).toMatchObject({
|
|
88
|
+
allNames: ["p"],
|
|
89
|
+
allNotations: ["-p"],
|
|
90
|
+
shortName: "p",
|
|
91
|
+
shortNotation: "-p",
|
|
92
|
+
description: "My simple option",
|
|
93
|
+
choices: ["card", "cash"],
|
|
94
|
+
name: "p",
|
|
95
|
+
boolean: false,
|
|
96
|
+
typeHint: 'one of "card","cash"',
|
|
97
|
+
valueRequired: false,
|
|
98
|
+
validator: ["card", "cash"],
|
|
99
|
+
valueType: 0,
|
|
100
|
+
required: false,
|
|
101
|
+
synopsis: "-p [mean]",
|
|
102
|
+
variadic: false,
|
|
103
|
+
visible: true,
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it.each([["bad synopsis"], ["another"], ["---fooo"]])(
|
|
108
|
+
"should throw for a malformed synopsis '%s'",
|
|
109
|
+
(a) => {
|
|
110
|
+
expect(() => createOption(a, "My simple option")).toThrowError(
|
|
111
|
+
OptionSynopsisSyntaxError,
|
|
112
|
+
)
|
|
113
|
+
},
|
|
114
|
+
)
|
|
115
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Command } from "../command"
|
|
7
|
+
import type { Option } from "../types"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Find an option from its name for a given command
|
|
11
|
+
*
|
|
12
|
+
* @param cmd Command object
|
|
13
|
+
* @param name Option name, short or long, camel-cased
|
|
14
|
+
*/
|
|
15
|
+
export function findOption(cmd: Command, name: string): Option | undefined {
|
|
16
|
+
return cmd.options.find((o) => o.allNames.find((opt) => opt === name))
|
|
17
|
+
}
|