@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
package/src/types.ts
ADDED
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List of Caporal type aliases.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
* @module caporal/types
|
|
6
|
+
*/
|
|
7
|
+
//
|
|
8
|
+
import { Logger as WinstonLogger } from "winston"
|
|
9
|
+
import { Program } from "./program"
|
|
10
|
+
import { Command } from "./command"
|
|
11
|
+
import { CommonError } from "./error"
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The Caporal logger interface. It extends the [Winston](https://github.com/winstonjs/winston) Logger interface
|
|
15
|
+
* and adds the following properties & methods.
|
|
16
|
+
* @noInheritDoc
|
|
17
|
+
*/
|
|
18
|
+
export interface Logger extends WinstonLogger {
|
|
19
|
+
/**
|
|
20
|
+
* Allow to force disabling colors.
|
|
21
|
+
*/
|
|
22
|
+
disableColors(): void
|
|
23
|
+
/**
|
|
24
|
+
* Tells Caporal if colors are enabled or not.
|
|
25
|
+
*/
|
|
26
|
+
colorsEnabled: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type GlobalOptions = Map<Option, Action | undefined>
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Caporal-provided validator flags.
|
|
33
|
+
*/
|
|
34
|
+
export enum CaporalValidator {
|
|
35
|
+
/**
|
|
36
|
+
* Number validator. Check that the value looks like a numeric one
|
|
37
|
+
* and cast the provided value to a javascript `Number`.
|
|
38
|
+
*/
|
|
39
|
+
NUMBER = 1,
|
|
40
|
+
/**
|
|
41
|
+
* Boolean validator. Check that the value looks like a boolean.
|
|
42
|
+
* It accepts values like `true`, `false`, `yes`, `no`, `0`, and `1`
|
|
43
|
+
* and will auto-cast those values to `true` or `false`.
|
|
44
|
+
*/
|
|
45
|
+
BOOLEAN = 2,
|
|
46
|
+
/**
|
|
47
|
+
* String validator. Mainly used to make sure the value is a string,
|
|
48
|
+
* and prevent Caporal auto-casting of numerics values and boolean
|
|
49
|
+
* strings like `true` or `false`.
|
|
50
|
+
*/
|
|
51
|
+
STRING = 4,
|
|
52
|
+
/**
|
|
53
|
+
* Array validator. Convert any provided value to an array. If a string is provided,
|
|
54
|
+
* this validator will try to split it by commas.
|
|
55
|
+
*/
|
|
56
|
+
ARRAY = 8,
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
type FunctionValidatorArgument = ParsedArgument | ParsedOption
|
|
60
|
+
|
|
61
|
+
// export type FunctionValidator<T = FunctionValidatorArgument> = (
|
|
62
|
+
// value: T,
|
|
63
|
+
// ) => FunctionValidatorArgument | Promise<FunctionValidatorArgument>
|
|
64
|
+
|
|
65
|
+
export interface FunctionValidator<T = FunctionValidatorArgument> {
|
|
66
|
+
(value: T): Promisable<T>
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// export type FunctionValidator<T = FunctionValidatorArgument> = (value: T) => Promisable<T>
|
|
70
|
+
|
|
71
|
+
export type Validator = RegExp | FunctionValidator | CaporalValidator | ParserTypes[]
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
export interface ValidatorWrapper {
|
|
77
|
+
validate(
|
|
78
|
+
value: ParsedArgument | ParsedOption,
|
|
79
|
+
): ParserTypes | ParserTypes[] | Promise<ParserTypes>
|
|
80
|
+
getChoices(): ParserTypes[]
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface OptionSynopsis {
|
|
84
|
+
name: string
|
|
85
|
+
notation: string
|
|
86
|
+
shortName?: string
|
|
87
|
+
shortNotation?: string
|
|
88
|
+
longName?: string
|
|
89
|
+
longNotation?: string
|
|
90
|
+
allNames: string[]
|
|
91
|
+
allNotations: string[]
|
|
92
|
+
synopsis: string
|
|
93
|
+
valueRequired: boolean
|
|
94
|
+
valueType?: OptionValueType
|
|
95
|
+
variadic: boolean
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Option possible value.
|
|
100
|
+
*
|
|
101
|
+
*/
|
|
102
|
+
export enum OptionValueType {
|
|
103
|
+
/**
|
|
104
|
+
* Value is optional.
|
|
105
|
+
*/
|
|
106
|
+
Optional,
|
|
107
|
+
/**
|
|
108
|
+
* Value is required.
|
|
109
|
+
*/
|
|
110
|
+
Required,
|
|
111
|
+
/**
|
|
112
|
+
* Option does not have any possible value
|
|
113
|
+
*/
|
|
114
|
+
None,
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Option properties
|
|
119
|
+
*/
|
|
120
|
+
export interface CreateOptionCommandOpts {
|
|
121
|
+
/**
|
|
122
|
+
* Optional validator
|
|
123
|
+
*/
|
|
124
|
+
validator?: Validator
|
|
125
|
+
/**
|
|
126
|
+
* Default value for the Option
|
|
127
|
+
*/
|
|
128
|
+
default?: ParsedOption
|
|
129
|
+
/**
|
|
130
|
+
* Set the Option as itself required
|
|
131
|
+
*/
|
|
132
|
+
required?: boolean
|
|
133
|
+
/**
|
|
134
|
+
* Hide the option from help
|
|
135
|
+
*/
|
|
136
|
+
hidden?: boolean
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Option properties
|
|
141
|
+
*/
|
|
142
|
+
export interface CreateOptionProgramOpts extends CreateOptionCommandOpts {
|
|
143
|
+
/**
|
|
144
|
+
* Set to `true` for a global option.
|
|
145
|
+
*/
|
|
146
|
+
global?: boolean
|
|
147
|
+
/**
|
|
148
|
+
* Action to call when a global-option is passed.
|
|
149
|
+
* Only available for global options, e.g. when `global` is set to `true`.
|
|
150
|
+
*/
|
|
151
|
+
action?: Action
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface CreateArgumentOpts {
|
|
155
|
+
/**
|
|
156
|
+
* Argument validator.
|
|
157
|
+
*/
|
|
158
|
+
validator?: Validator
|
|
159
|
+
/**
|
|
160
|
+
* Argument default value.
|
|
161
|
+
*/
|
|
162
|
+
default?: ParsedArgument
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export interface ArgumentSynopsis {
|
|
166
|
+
/**
|
|
167
|
+
* Argument name.
|
|
168
|
+
*/
|
|
169
|
+
readonly name: string
|
|
170
|
+
/**
|
|
171
|
+
* Boolean indicating if the argument is required.
|
|
172
|
+
*/
|
|
173
|
+
readonly required: boolean
|
|
174
|
+
/**
|
|
175
|
+
* Synopsis string.
|
|
176
|
+
*/
|
|
177
|
+
readonly synopsis: string
|
|
178
|
+
/**
|
|
179
|
+
* Boolean indicating if the argument is valiadic,
|
|
180
|
+
* e.g. can be repeated to contain an array of values.
|
|
181
|
+
*/
|
|
182
|
+
readonly variadic: boolean
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export interface Argument extends ArgumentSynopsis {
|
|
186
|
+
readonly default?: ParsedArgument
|
|
187
|
+
readonly description: string
|
|
188
|
+
readonly choices: ParsedArgument[]
|
|
189
|
+
readonly validator?: Validator
|
|
190
|
+
typeHint?: string
|
|
191
|
+
kind: "argument"
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export interface Option extends OptionSynopsis {
|
|
195
|
+
readonly boolean: boolean
|
|
196
|
+
readonly default?: ParsedOption
|
|
197
|
+
readonly description: string
|
|
198
|
+
readonly choices: ParsedOption[]
|
|
199
|
+
readonly validator?: Validator
|
|
200
|
+
readonly required: boolean
|
|
201
|
+
readonly visible: boolean
|
|
202
|
+
typeHint?: string
|
|
203
|
+
kind: "option"
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* A type that could be wrapped in a Promise, or not
|
|
208
|
+
*/
|
|
209
|
+
export type Promisable<T> = T | Promise<T>
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Parameters object passed to an {@link Action} function
|
|
213
|
+
*/
|
|
214
|
+
export interface ActionParameters {
|
|
215
|
+
/**
|
|
216
|
+
* Parsed command line arguments
|
|
217
|
+
*/
|
|
218
|
+
args: ParsedArgumentsObject
|
|
219
|
+
/**
|
|
220
|
+
* If the `dash` (double dash) config property is enabled,
|
|
221
|
+
* this *array* will contain all arguments present
|
|
222
|
+
* after '--'.
|
|
223
|
+
*/
|
|
224
|
+
ddash: ParsedArguments
|
|
225
|
+
/**
|
|
226
|
+
* Parsed command line options
|
|
227
|
+
*/
|
|
228
|
+
options: ParsedOptions
|
|
229
|
+
/**
|
|
230
|
+
* Program instance
|
|
231
|
+
*/
|
|
232
|
+
program: Program
|
|
233
|
+
/**
|
|
234
|
+
* Contextual command, if any
|
|
235
|
+
*/
|
|
236
|
+
command?: Command
|
|
237
|
+
/**
|
|
238
|
+
* Logger instance
|
|
239
|
+
*/
|
|
240
|
+
logger: Logger
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* An action is a function that will be executed upon a command call.
|
|
245
|
+
*/
|
|
246
|
+
export interface Action {
|
|
247
|
+
(params: ActionParameters): unknown
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export interface ErrorMetadata {
|
|
251
|
+
[meta: string]: unknown
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export type ParserTypes = string | number | boolean
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Available options for the Caporal internal parser.
|
|
258
|
+
* Arguments must be referenced by their position (0-based) and options by their name (short or long)
|
|
259
|
+
* in {@link ParserOptions.boolean boolean}, {@link ParserOptions.string string}
|
|
260
|
+
* and {@link ParserOptions.variadic variadic} parser options.
|
|
261
|
+
*
|
|
262
|
+
*/
|
|
263
|
+
export interface ParserOptions {
|
|
264
|
+
/**
|
|
265
|
+
* List of {@link Argument Arguments} and {@link Options Options} to be casted as *booleans*.
|
|
266
|
+
* Arguments must be referenced by their position (0-based) and options by their name (short or long).
|
|
267
|
+
*
|
|
268
|
+
* **Example**
|
|
269
|
+
*
|
|
270
|
+
* ```ts
|
|
271
|
+
* import { parseArgv } from "caporal/parser"
|
|
272
|
+
*
|
|
273
|
+
* parseArgv({
|
|
274
|
+
* boolean: [2, 'sendEmail']
|
|
275
|
+
* })
|
|
276
|
+
*
|
|
277
|
+
* // ./my-cli-app first-arg second-arg 3rd-arg --sendEmail=1
|
|
278
|
+
* // -> "3rd-arg" will be casted to boolean as well as "--sendEmail"
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
boolean: (string | number)[]
|
|
282
|
+
/**
|
|
283
|
+
* List of {@link Argument Arguments} and {@link Options Options} to be casted as *strings*.
|
|
284
|
+
* Arguments must be referenced by their position (0-based) and options by their name (short or long).
|
|
285
|
+
*
|
|
286
|
+
* **Example**
|
|
287
|
+
*
|
|
288
|
+
* ```ts
|
|
289
|
+
* import { parseArgv } from "caporal/parser"
|
|
290
|
+
*
|
|
291
|
+
* parseArgv({
|
|
292
|
+
* string: [1]
|
|
293
|
+
* })
|
|
294
|
+
*
|
|
295
|
+
* // ./my-cli-app first-arg 2
|
|
296
|
+
* // -> second arg "2" will be casted to string instead of number
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
string: (string | number)[]
|
|
300
|
+
/**
|
|
301
|
+
* List of variadic {@link Argument Arguments} and {@link Options Options}, meaning
|
|
302
|
+
* that there value is an `Array`.
|
|
303
|
+
*
|
|
304
|
+
* Arguments must be referenced by their position (0-based) and options by their name (short or long).
|
|
305
|
+
*
|
|
306
|
+
* **Example**
|
|
307
|
+
*
|
|
308
|
+
* ```ts
|
|
309
|
+
* import { parseArgv } from "caporal/parser"
|
|
310
|
+
*
|
|
311
|
+
* parseArgv({
|
|
312
|
+
* variadic: [1]
|
|
313
|
+
* })
|
|
314
|
+
*
|
|
315
|
+
* // ./pizza order margherita regina --add sausages --add basil
|
|
316
|
+
* {
|
|
317
|
+
* args: ['order', ['margherita', 'regina']]
|
|
318
|
+
* options: {
|
|
319
|
+
* add: ['sausages', 'basil']
|
|
320
|
+
* }
|
|
321
|
+
* }
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
variadic: (string | number)[]
|
|
325
|
+
/**
|
|
326
|
+
* Double-dash (--) handling mode. If `true`, the parser will populate the
|
|
327
|
+
* {@link ParserResult.ddash} property, otherwise, arguments will be added
|
|
328
|
+
* to {@link ParserResult.args}.
|
|
329
|
+
*/
|
|
330
|
+
ddash: boolean
|
|
331
|
+
/**
|
|
332
|
+
* Option aliases map.
|
|
333
|
+
*/
|
|
334
|
+
alias: Record<string, string>
|
|
335
|
+
/**
|
|
336
|
+
* Enable or disable autocasting of arguments and options. Default to `true`.
|
|
337
|
+
*/
|
|
338
|
+
autoCast: boolean
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export type ParsedArgument = ParserTypes | ParserTypes[]
|
|
342
|
+
export type ParsedArguments = ParsedArgument[]
|
|
343
|
+
export interface ParsedArgumentsObject {
|
|
344
|
+
[arg: string]: ParsedArgument
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export type ParsedOption = ParserTypes | ParserTypes[]
|
|
348
|
+
export interface ParsedOptions {
|
|
349
|
+
[opt: string]: ParsedOption
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* @internal
|
|
353
|
+
*/
|
|
354
|
+
export interface ArgumentsRange {
|
|
355
|
+
min: number
|
|
356
|
+
max: number
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export interface ParserResult {
|
|
360
|
+
args: ParsedArguments
|
|
361
|
+
options: ParsedOptions
|
|
362
|
+
rawOptions: ParsedOptions
|
|
363
|
+
line: string
|
|
364
|
+
rawArgv: string[]
|
|
365
|
+
ddash: ParsedArguments
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export interface ParserProcessedResult extends Omit<ParserResult, "args"> {
|
|
369
|
+
args: ParsedArgumentsObject
|
|
370
|
+
errors: CommonError[]
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export interface CreateCommandParameters {
|
|
374
|
+
program: Program
|
|
375
|
+
createCommand(description?: string): Command
|
|
376
|
+
}
|
|
377
|
+
export interface CommandCreator {
|
|
378
|
+
(options: CreateCommandParameters): Command
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Available configuration properties for the program.
|
|
383
|
+
*/
|
|
384
|
+
export type ProgramConfig = {
|
|
385
|
+
/**
|
|
386
|
+
* Strict checking of arguments count. If enabled, any additional argument willl trigger an error.
|
|
387
|
+
* Default to `true`.
|
|
388
|
+
*/
|
|
389
|
+
strictArgsCount: boolean
|
|
390
|
+
/**
|
|
391
|
+
* Strict checking of options provided. If enabled, any unknown option will trigger an error.
|
|
392
|
+
* Default to `true`.
|
|
393
|
+
*/
|
|
394
|
+
strictOptions: boolean
|
|
395
|
+
/**
|
|
396
|
+
* Auto-casting of arguments and options.
|
|
397
|
+
* Default to `true`.
|
|
398
|
+
*/
|
|
399
|
+
autoCast: boolean
|
|
400
|
+
/**
|
|
401
|
+
* Environment variable to check for log level override.
|
|
402
|
+
* Default to "CAPORAL_LOG_LEVEL".
|
|
403
|
+
*/
|
|
404
|
+
logLevelEnvVar: string
|
|
405
|
+
}
|
|
406
|
+
export type CommandConfig = {
|
|
407
|
+
/**
|
|
408
|
+
* Strict checking of arguments count. If enabled, any additional argument willl trigger an error.
|
|
409
|
+
*/
|
|
410
|
+
strictArgsCount?: boolean
|
|
411
|
+
/**
|
|
412
|
+
* Strict checking of options provided. If enabled, any unknown option will trigger an error.
|
|
413
|
+
*/
|
|
414
|
+
strictOptions?: boolean
|
|
415
|
+
/**
|
|
416
|
+
* Auto-casting of arguments and options.
|
|
417
|
+
*/
|
|
418
|
+
autoCast?: boolean
|
|
419
|
+
/**
|
|
420
|
+
* Visibility of the command in help.
|
|
421
|
+
*/
|
|
422
|
+
visible: boolean
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
export type BaseConfig = Record<string, boolean | string>
|
|
426
|
+
|
|
427
|
+
export interface Configurator<T extends BaseConfig> {
|
|
428
|
+
get<K extends keyof T>(key: K): T[K]
|
|
429
|
+
getAll(): T
|
|
430
|
+
set(props: Partial<T>): T
|
|
431
|
+
reset(): T
|
|
432
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { readdir } from "../fs"
|
|
2
|
+
import { expect, it, describe } from "vitest"
|
|
3
|
+
|
|
4
|
+
describe("readdir()", () => {
|
|
5
|
+
it("should resolve to a file list on success", async () => {
|
|
6
|
+
const files = await readdir(__dirname)
|
|
7
|
+
return expect(files.sort()).toEqual(
|
|
8
|
+
["fs.spec.ts", "levenshtein.spec.ts", "suggest.spec.ts"].sort(),
|
|
9
|
+
)
|
|
10
|
+
})
|
|
11
|
+
it("should reject if directory does note exist", () => {
|
|
12
|
+
return expect(readdir("/does/not/exist")).rejects.toBeInstanceOf(Error)
|
|
13
|
+
})
|
|
14
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { levenshtein } from "../levenshtein"
|
|
2
|
+
import { expect, it, describe } from "vitest"
|
|
3
|
+
|
|
4
|
+
describe("levenshtein", () => {
|
|
5
|
+
it.each([
|
|
6
|
+
["hello", "bye", 5],
|
|
7
|
+
["some", "sometimes", 5],
|
|
8
|
+
["john", "jane", 3],
|
|
9
|
+
["exemple", "example", 1],
|
|
10
|
+
["", "", 0],
|
|
11
|
+
["not-empty", "", 9],
|
|
12
|
+
["", "not-empty", 9],
|
|
13
|
+
])(".levenshtein('%s', '%s')", (a, b, expected) => {
|
|
14
|
+
expect(levenshtein(a, b)).toBe(expected)
|
|
15
|
+
})
|
|
16
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getSuggestions, boldDiffString } from "../suggest"
|
|
2
|
+
import c from "chalk"
|
|
3
|
+
import { expect, it, describe } from "vitest"
|
|
4
|
+
|
|
5
|
+
describe("Suggest", () => {
|
|
6
|
+
describe("getSuggestions()", () => {
|
|
7
|
+
it("should return proper suggestions", () => {
|
|
8
|
+
const suggestions = getSuggestions("foo", ["foa", "foab", "foabc", "afoo", "bfoap"])
|
|
9
|
+
expect(suggestions).toStrictEqual(["foa", "afoo", "foab"])
|
|
10
|
+
})
|
|
11
|
+
})
|
|
12
|
+
describe("boldDiffString()", () => {
|
|
13
|
+
it("should make the diff bold at the end of the word", () => {
|
|
14
|
+
expect(boldDiffString("foo", "foob")).toEqual("foo" + c.bold.greenBright("b"))
|
|
15
|
+
})
|
|
16
|
+
it("should make the diff bold at the beginning of the word", () => {
|
|
17
|
+
expect(boldDiffString("foo", "doo")).toBe(c.bold.greenBright("d") + "oo")
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it("should make the diff bold at the middle of the word", () => {
|
|
21
|
+
expect(boldDiffString("foo", "fao")).toBe("f" + c.bold.greenBright("a") + "o")
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it("should make the diff bold anywhere in the word", () => {
|
|
25
|
+
expect(boldDiffString("minimum", "maximum")).toBe(
|
|
26
|
+
"m" + c.bold.greenBright("a") + c.bold.greenBright("x") + "imum",
|
|
27
|
+
)
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
import c from "chalk"
|
|
6
|
+
|
|
7
|
+
export function colorize(text: string): string {
|
|
8
|
+
return text
|
|
9
|
+
.replace(/<([^>]+)>/gi, (match) => {
|
|
10
|
+
return c.hex("#569cd6")(match)
|
|
11
|
+
})
|
|
12
|
+
.replace(/<command>/gi, (match) => {
|
|
13
|
+
return c.hex("#ff9900")(match)
|
|
14
|
+
})
|
|
15
|
+
.replace(/\[([^[\]]+)\]/gi, (match) => {
|
|
16
|
+
return c.hex("#aaa")(match)
|
|
17
|
+
})
|
|
18
|
+
.replace(/ --?([^\s,]+)/gi, (match) => {
|
|
19
|
+
return c.green(match)
|
|
20
|
+
})
|
|
21
|
+
}
|
package/src/utils/fs.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
import { glob } from "glob"
|
|
6
|
+
import fs from "fs"
|
|
7
|
+
|
|
8
|
+
export function readdir(dirPath: string, extensions = "js,ts"): Promise<string[]> {
|
|
9
|
+
if (!fs.existsSync(dirPath)) {
|
|
10
|
+
return Promise.reject(new Error(`'${dirPath}' does not exist!`))
|
|
11
|
+
}
|
|
12
|
+
return glob(`**/*.{${extensions}}`, { cwd: dirPath })
|
|
13
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export function levenshtein(a: string, b: string): number {
|
|
6
|
+
if (a === b) {
|
|
7
|
+
return 0
|
|
8
|
+
}
|
|
9
|
+
if (!a.length || !b.length) {
|
|
10
|
+
return a.length || b.length
|
|
11
|
+
}
|
|
12
|
+
let cell = 0
|
|
13
|
+
let lcell = 0
|
|
14
|
+
let dcell = 0
|
|
15
|
+
const row = [...Array(b.length + 1).keys()]
|
|
16
|
+
for (let i = 0; i < a.length; i++) {
|
|
17
|
+
dcell = i
|
|
18
|
+
lcell = i + 1
|
|
19
|
+
for (let j = 0; j < b.length; j++) {
|
|
20
|
+
cell = a[i] === b[j] ? dcell : Math.min(...[dcell, row[j + 1], lcell]) + 1
|
|
21
|
+
dcell = row[j + 1]
|
|
22
|
+
row[j] = lcell
|
|
23
|
+
lcell = cell
|
|
24
|
+
}
|
|
25
|
+
row[row.length - 1] = cell
|
|
26
|
+
}
|
|
27
|
+
return cell
|
|
28
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
import chalk from "chalk"
|
|
6
|
+
import { levenshtein } from "./levenshtein"
|
|
7
|
+
|
|
8
|
+
interface Suggestion {
|
|
9
|
+
distance: number
|
|
10
|
+
suggestion: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const MAX_DISTANCE = 2
|
|
14
|
+
|
|
15
|
+
const sortByDistance = (a: Suggestion, b: Suggestion): number => a.distance - b.distance
|
|
16
|
+
|
|
17
|
+
const keepMeaningfulSuggestions = (s: Suggestion): boolean => s.distance <= MAX_DISTANCE
|
|
18
|
+
|
|
19
|
+
const possibilitesMapper = (input: string, p: string): Suggestion => {
|
|
20
|
+
return { suggestion: p, distance: levenshtein(input, p) }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Get autocomplete suggestions
|
|
25
|
+
*
|
|
26
|
+
* @param {String} input - User input
|
|
27
|
+
* @param {String[]} possibilities - Possibilities to retrieve suggestions from
|
|
28
|
+
*/
|
|
29
|
+
export function getSuggestions(input: string, possibilities: string[]): string[] {
|
|
30
|
+
return possibilities
|
|
31
|
+
.map((p) => possibilitesMapper(input, p))
|
|
32
|
+
.filter(keepMeaningfulSuggestions)
|
|
33
|
+
.sort(sortByDistance)
|
|
34
|
+
.map((p) => p.suggestion)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Make diff bolder in a string
|
|
39
|
+
*
|
|
40
|
+
* @param from original string
|
|
41
|
+
* @param to target string
|
|
42
|
+
*/
|
|
43
|
+
export function boldDiffString(from: string, to: string): string {
|
|
44
|
+
return [...to]
|
|
45
|
+
.map((char, index) => {
|
|
46
|
+
if (char != from.charAt(index)) {
|
|
47
|
+
return chalk.bold.greenBright(char)
|
|
48
|
+
}
|
|
49
|
+
return char
|
|
50
|
+
})
|
|
51
|
+
.join("")
|
|
52
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
import path from "path"
|
|
6
|
+
|
|
7
|
+
export function detectVersion(): string | undefined {
|
|
8
|
+
try {
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
10
|
+
return require(path.join(__filename, "..", "..", "..", "package.json")).version
|
|
11
|
+
// eslint-disable-next-line no-empty
|
|
12
|
+
} catch (e) {}
|
|
13
|
+
return undefined
|
|
14
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Autocomplete mock for caporal-web
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
import type { Program } from "../../program"
|
|
8
|
+
import type { Argument, Option } from "../../types"
|
|
9
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
10
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
11
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
12
|
+
export function registerCompletion(
|
|
13
|
+
argOrOpt: Argument | Option,
|
|
14
|
+
completer: () => unknown,
|
|
15
|
+
) {}
|
|
16
|
+
|
|
17
|
+
export async function installCompletion(program: Program): Promise<void> {}
|
|
18
|
+
|
|
19
|
+
export async function uninstallCompletion(program: Program): Promise<void> {}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A process mock for the web
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
8
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
9
|
+
/* eslint-disable no-console */
|
|
10
|
+
export const version = process.version
|
|
11
|
+
export const argv = ["node", "play.ts"]
|
|
12
|
+
export const execArgv = [] as any[]
|
|
13
|
+
export const exitCode = 0
|
|
14
|
+
export const fake = true
|
|
15
|
+
export const on = () => {}
|
|
16
|
+
export const once = () => {}
|
|
17
|
+
export const exit = function (code = 0) {
|
|
18
|
+
if (code > 0) {
|
|
19
|
+
return console.debug(
|
|
20
|
+
`[playground process exiting with code ${code} - usually a fatal error]`,
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
console.debug(`[process exiting with code ${code}]`)
|
|
24
|
+
}
|