@flowscripter/dynamic-cli-framework 1.7.3 → 1.7.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/cli-plugin.ts +1 -1
- package/dist/cli-plugin.d.ts +1 -1
- package/dist/cli-plugin.d.ts.map +1 -1
- package/dist/cli-plugin.js +25 -247
- package/dist/index.js +70 -105754
- package/dist/src/api/BaseCLIFeatureOptions.js +0 -0
- package/dist/src/api/CLI.js +0 -0
- package/dist/src/api/CLIConfig.js +0 -0
- package/dist/src/api/Context.js +0 -0
- package/dist/src/api/RunResult.js +73 -0
- package/dist/src/api/argument/Argument.js +0 -0
- package/dist/src/api/argument/ArgumentValueTypes.js +18 -0
- package/dist/src/api/argument/ComplexOption.js +1 -0
- package/dist/src/api/argument/GlobalCommandArgument.js +0 -0
- package/dist/src/api/argument/Option.js +0 -0
- package/dist/src/api/argument/Positional.js +0 -0
- package/dist/src/api/argument/SubCommandArgument.js +1 -0
- package/dist/src/api/command/Command.js +0 -0
- package/dist/src/api/command/GlobalCommand.js +0 -0
- package/dist/src/api/command/GlobalModifierCommand.js +0 -0
- package/dist/src/api/command/GroupCommand.js +0 -0
- package/dist/src/api/command/SubCommand.js +0 -0
- package/dist/src/api/command/UsageExample.js +0 -0
- package/dist/src/api/plugin/CLIPlugin.js +2 -0
- package/dist/src/api/plugin/CommandFactory.js +7 -0
- package/dist/src/api/plugin/ServiceProviderFactory.js +7 -0
- package/dist/src/api/plugin/createCLIPlugin.js +30 -0
- package/dist/src/api/service/ServiceProvider.js +0 -0
- package/dist/src/api/service/core/ArgumentPrompterService.js +1 -0
- package/dist/src/api/service/core/AsciiBannerGeneratorService.js +1 -0
- package/dist/src/api/service/core/CompletionService.js +8 -0
- package/dist/src/api/service/core/DataDumpGeneratorService.js +7 -0
- package/dist/src/api/service/core/ImagePrinterService.js +1 -0
- package/dist/src/api/service/core/KeyValueService.js +7 -0
- package/dist/src/api/service/core/PluginService.js +6 -0
- package/dist/src/api/service/core/PrettyPrinterService.js +1 -0
- package/dist/src/api/service/core/PrinterService.js +42 -0
- package/dist/src/api/service/core/PrompterService.js +10 -0
- package/dist/src/api/service/core/SecretService.js +0 -0
- package/dist/src/api/service/core/ShutdownService.js +1 -0
- package/dist/src/api/service/core/SyntaxHighlighterService.js +1 -0
- package/dist/src/api/service/core/Table.js +49 -0
- package/dist/src/api/service/core/TableGeneratorService.d.ts +1 -0
- package/dist/src/api/service/core/TableGeneratorService.d.ts.map +1 -1
- package/dist/src/api/service/core/TableGeneratorService.js +7 -0
- package/dist/src/api/service/core/TreePrinterService.js +1 -0
- package/dist/src/cli/BaseCLI.d.ts.map +1 -1
- package/dist/src/cli/BaseCLI.js +232 -0
- package/dist/src/cli/DefaultRuntimeCLI.js +20 -0
- package/dist/src/cli/DynamicPluginRuntimeCLI.js +50 -0
- package/dist/src/command/MultiCommandCliHelpCommand.js +238 -0
- package/dist/src/command/SingleCommandCliHelpCommand.js +104 -0
- package/dist/src/command/UsageCommand.js +16 -0
- package/dist/src/command/VersionCommand.js +13 -0
- package/dist/src/launcher.js +61 -0
- package/dist/src/runtime/DefaultContext.js +25 -0
- package/dist/src/runtime/argument/ArgumentTypeGuards.js +3 -0
- package/dist/src/runtime/command/CommandTypeGuards.js +12 -0
- package/dist/src/runtime/command/CommandValidator.js +371 -0
- package/dist/src/runtime/parser.js +105 -0
- package/dist/src/runtime/registry/CommandRegistry.js +0 -0
- package/dist/src/runtime/registry/DefaultCommandRegistry.js +190 -0
- package/dist/src/runtime/registry/DefaultServiceProviderRegistry.js +20 -0
- package/dist/src/runtime/registry/ServiceProviderRegistry.js +0 -0
- package/dist/src/runtime/runner.js +507 -0
- package/dist/src/runtime/scanner.js +244 -0
- package/dist/src/runtime/values/ValuePopulationResult.js +0 -0
- package/dist/src/runtime/values/argumentValueMerge.js +122 -0
- package/dist/src/runtime/values/argumentValueValidation.js +505 -0
- package/dist/src/runtime/values/globalCommandValuePopulation.js +67 -0
- package/dist/src/runtime/values/subCommandValuePopulation.js +549 -0
- package/dist/src/service/argumentPrompter/ArgumentPrompterServiceProvider.js +19 -0
- package/dist/src/service/argumentPrompter/DefaultArgumentPrompterService.js +197 -0
- package/dist/src/service/asciiBannerGenerator/AsciiBannerGeneratorServiceProvider.js +28 -0
- package/dist/src/service/asciiBannerGenerator/DefaultAsciiBannerGeneratorService.js +233 -0
- package/dist/src/service/asciiBannerGenerator/standard.flf.json +3 -0
- package/dist/src/service/banner/BannerServiceProvider.js +60 -0
- package/dist/src/service/banner/command/NoBannerCommand.js +24 -0
- package/dist/src/service/chiselAsciiBannerGenerator/ChiselFontAsciiBannerGeneratorService.js +51 -0
- package/dist/src/service/chiselAsciiBannerGenerator/chisel.flf.json +3 -0
- package/dist/src/service/completion/CompletionServiceProvider.d.ts +2 -1
- package/dist/src/service/completion/CompletionServiceProvider.d.ts.map +1 -1
- package/dist/src/service/completion/CompletionServiceProvider.js +159 -0
- package/dist/src/service/completion/DefaultCompletionService.js +279 -0
- package/dist/src/service/completion/command/CompletionCompleteSubCommand.d.ts +15 -0
- package/dist/src/service/completion/command/CompletionCompleteSubCommand.d.ts.map +1 -0
- package/dist/src/service/completion/command/CompletionCompleteSubCommand.js +37 -0
- package/dist/src/service/completion/command/CompletionGroupCommand.d.ts +14 -0
- package/dist/src/service/completion/command/CompletionGroupCommand.d.ts.map +1 -0
- package/dist/src/service/completion/command/CompletionGroupCommand.js +10 -0
- package/dist/src/service/completion/command/CompletionIntegrationSubCommand.d.ts +14 -0
- package/dist/src/service/completion/command/CompletionIntegrationSubCommand.d.ts.map +1 -0
- package/dist/src/service/completion/command/CompletionIntegrationSubCommand.js +67 -0
- package/dist/src/service/completion/shell/ShellHandler.js +0 -0
- package/dist/src/service/completion/shell/bash.js +39 -0
- package/dist/src/service/completion/shell/fish.js +35 -0
- package/dist/src/service/completion/shell/powershell.js +51 -0
- package/dist/src/service/completion/shell/zsh.js +42 -0
- package/dist/src/service/configuration/ConfigurationServiceProvider.js +482 -0
- package/dist/src/service/configuration/DefaultKeyValueService.js +80 -0
- package/dist/src/service/configuration/DefaultSecretService.js +60 -0
- package/dist/src/service/configuration/command/ConfigCommand.js +24 -0
- package/dist/src/service/configuration/command/DumpConfigCommand.js +18 -0
- package/dist/src/service/dataDumpGenerator/DataDumpGeneratorServiceProvider.js +24 -0
- package/dist/src/service/dataDumpGenerator/DefaultDataDumpGeneratorService.js +59 -0
- package/dist/src/service/imagePrinter/DefaultImagePrinterService.js +10 -0
- package/dist/src/service/imagePrinter/ImagePrinterServiceProvider.js +20 -0
- package/dist/src/service/plugin/DefaultPluginService.js +21 -0
- package/dist/src/service/plugin/DefaultPluginServiceProvider.d.ts +1 -1
- package/dist/src/service/plugin/DefaultPluginServiceProvider.d.ts.map +1 -1
- package/dist/src/service/plugin/DefaultPluginServiceProvider.js +21 -0
- package/dist/src/service/plugin/command/PluginAddSubCommand.d.ts +17 -0
- package/dist/src/service/plugin/command/PluginAddSubCommand.d.ts.map +1 -0
- package/dist/src/service/plugin/command/PluginAddSubCommand.js +49 -0
- package/dist/src/service/plugin/command/PluginGroupCommand.d.ts +12 -0
- package/dist/src/service/plugin/command/PluginGroupCommand.d.ts.map +1 -0
- package/dist/src/service/plugin/command/PluginGroupCommand.js +21 -0
- package/dist/src/service/plugin/command/PluginListSubCommand.d.ts +12 -0
- package/dist/src/service/plugin/command/PluginListSubCommand.d.ts.map +1 -0
- package/dist/src/service/plugin/command/PluginListSubCommand.js +25 -0
- package/dist/src/service/plugin/command/PluginRemoveSubCommand.d.ts +17 -0
- package/dist/src/service/plugin/command/PluginRemoveSubCommand.d.ts.map +1 -0
- package/dist/src/service/plugin/command/PluginRemoveSubCommand.js +24 -0
- package/dist/src/service/plugin/command/PluginSearchSubCommand.d.ts +18 -0
- package/dist/src/service/plugin/command/PluginSearchSubCommand.d.ts.map +1 -0
- package/dist/src/service/plugin/command/PluginSearchSubCommand.js +34 -0
- package/dist/src/service/plugin/command/PluginUpgradeSubCommand.d.ts +12 -0
- package/dist/src/service/plugin/command/PluginUpgradeSubCommand.d.ts.map +1 -0
- package/dist/src/service/plugin/command/PluginUpgradeSubCommand.js +25 -0
- package/dist/src/service/plugin/command/getPluginId.d.ts +3 -0
- package/dist/src/service/plugin/command/getPluginId.d.ts.map +1 -0
- package/dist/src/service/plugin/command/getPluginId.js +3 -0
- package/dist/src/service/prettyPrinter/DefaultPrettyPrinterService.js +45 -0
- package/dist/src/service/prettyPrinter/PrettyPrinterServiceProvider.js +28 -0
- package/dist/src/service/printer/DefaultPrinterService.js +250 -0
- package/dist/src/service/printer/PrinterServiceProvider.js +43 -0
- package/dist/src/service/printer/command/DarkModeCommand.js +24 -0
- package/dist/src/service/printer/command/LogLevelCommand.js +41 -0
- package/dist/src/service/printer/command/NoColorCommand.js +24 -0
- package/dist/src/service/printer/command/NoHyperlinksCommand.js +21 -0
- package/dist/src/service/printer/terminal/Color.js +15 -0
- package/dist/src/service/printer/terminal/Progress.js +271 -0
- package/dist/src/service/printer/terminal/Spinner.js +83 -0
- package/dist/src/service/printer/terminal/Theme.js +26 -0
- package/dist/src/service/prompter/DefaultPrompterService.js +52 -0
- package/dist/src/service/prompter/PrompterServiceProvider.js +20 -0
- package/dist/src/service/prompter/command/NoPromptCommand.js +21 -0
- package/dist/src/service/prompter/prompt/PromptContext.js +22 -0
- package/dist/src/service/prompter/prompt/promptAcknowledge.js +19 -0
- package/dist/src/service/prompter/prompt/promptMultiSelect.js +74 -0
- package/dist/src/service/prompter/prompt/promptOpenUrl.js +70 -0
- package/dist/src/service/prompter/prompt/promptSingleSelect.js +73 -0
- package/dist/src/service/prompter/prompt/promptText.js +75 -0
- package/dist/src/service/prompter/prompt/promptToggle.js +21 -0
- package/dist/src/service/shutdown/DefaultShutdownService.js +16 -0
- package/dist/src/service/shutdown/ShutdownServiceProvider.js +60 -0
- package/dist/src/service/shutdown/ShutdownState.js +5 -0
- package/dist/src/service/syntaxHighlighter/DefaultSyntaxHighlighterService.js +54 -0
- package/dist/src/service/syntaxHighlighter/SyntaxHighlighterServiceProvider.js +32 -0
- package/dist/src/service/tableGenerator/DefaultTableGeneratorService.d.ts +3 -1
- package/dist/src/service/tableGenerator/DefaultTableGeneratorService.d.ts.map +1 -1
- package/dist/src/service/tableGenerator/DefaultTableGeneratorService.js +344 -0
- package/dist/src/service/tableGenerator/TableGeneratorServiceProvider.js +26 -0
- package/dist/src/service/treePrinter/DefaultTreePrinterService.js +35 -0
- package/dist/src/service/treePrinter/TreePrinterServiceProvider.js +24 -0
- package/dist/src/terminal/Ansi.js +23 -0
- package/dist/src/terminal/ImageRenderer.d.ts.map +1 -1
- package/dist/src/terminal/ImageRenderer.js +166 -0
- package/dist/src/terminal/KeyReader.js +13 -0
- package/dist/src/terminal/PngDecoder.js +115 -0
- package/dist/src/terminal/Styler.js +0 -0
- package/dist/src/terminal/Terminal.js +0 -0
- package/dist/src/terminal/TtyKeyReader.js +87 -0
- package/dist/src/terminal/TtyStyler.js +55 -0
- package/dist/src/terminal/TtyTerminal.js +52 -0
- package/dist/src/terminal/supportsHyperlinks.js +95 -0
- package/dist/src/util/configHelper.js +61 -0
- package/dist/src/util/envVarHelper.js +216 -0
- package/dist/src/util/helpHelper.d.ts.map +1 -1
- package/dist/src/util/helpHelper.js +497 -0
- package/dist/src/util/logger.js +81 -0
- package/dist/src/util/runnerHelper.js +80 -0
- package/package.json +2 -2
- package/src/api/service/core/TableGeneratorService.ts +1 -0
- package/src/cli/BaseCLI.ts +4 -19
- package/src/service/completion/CompletionServiceProvider.ts +16 -3
- package/src/service/completion/command/CompletionCompleteSubCommand.ts +59 -0
- package/src/service/completion/command/CompletionGroupCommand.ts +21 -0
- package/src/{command/CompletionCommand.ts → service/completion/command/CompletionIntegrationSubCommand.ts} +12 -73
- package/src/service/completion/shell/bash.ts +1 -1
- package/src/service/completion/shell/fish.ts +1 -1
- package/src/service/completion/shell/powershell.ts +1 -1
- package/src/service/completion/shell/zsh.ts +1 -1
- package/src/service/plugin/DefaultPluginServiceProvider.ts +2 -2
- package/src/service/plugin/command/PluginAddSubCommand.ts +64 -0
- package/src/service/plugin/command/PluginGroupCommand.ts +27 -0
- package/src/service/plugin/command/PluginListSubCommand.ts +33 -0
- package/src/service/plugin/command/PluginRemoveSubCommand.ts +32 -0
- package/src/service/plugin/command/PluginSearchSubCommand.ts +42 -0
- package/src/service/plugin/command/PluginUpgradeSubCommand.ts +36 -0
- package/src/service/plugin/command/getPluginId.ts +5 -0
- package/src/service/tableGenerator/DefaultTableGeneratorService.ts +6 -1
- package/src/terminal/ImageRenderer.ts +7 -5
- package/src/util/helpHelper.ts +1 -2
- package/dist/src/command/CompletionCommand.d.ts +0 -32
- package/dist/src/command/CompletionCommand.d.ts.map +0 -1
- package/dist/src/command/PluginCommand.d.ts +0 -67
- package/dist/src/command/PluginCommand.d.ts.map +0 -1
- package/dist/tests/cli/BaseCLI.test.d.ts +0 -2
- package/dist/tests/cli/BaseCLI.test.d.ts.map +0 -1
- package/dist/tests/cli/DynamicPluginRuntimeCLI.test.d.ts +0 -2
- package/dist/tests/cli/DynamicPluginRuntimeCLI.test.d.ts.map +0 -1
- package/dist/tests/command/CompletionCommand.test.d.ts +0 -2
- package/dist/tests/command/CompletionCommand.test.d.ts.map +0 -1
- package/dist/tests/command/MultiCommandCliHelpCommand.test.d.ts +0 -2
- package/dist/tests/command/MultiCommandCliHelpCommand.test.d.ts.map +0 -1
- package/dist/tests/command/PluginCommand.test.d.ts +0 -2
- package/dist/tests/command/PluginCommand.test.d.ts.map +0 -1
- package/dist/tests/command/SingleCommandCliHelpCommand.test.d.ts +0 -2
- package/dist/tests/command/SingleCommandCliHelpCommand.test.d.ts.map +0 -1
- package/dist/tests/command/UsageCommand.test.d.ts +0 -2
- package/dist/tests/command/UsageCommand.test.d.ts.map +0 -1
- package/dist/tests/command/VersionCommand.test.d.ts +0 -2
- package/dist/tests/command/VersionCommand.test.d.ts.map +0 -1
- package/dist/tests/fixtures/CLIConfig.d.ts +0 -3
- package/dist/tests/fixtures/CLIConfig.d.ts.map +0 -1
- package/dist/tests/fixtures/Command.d.ts +0 -20
- package/dist/tests/fixtures/Command.d.ts.map +0 -1
- package/dist/tests/fixtures/CommandRegistry.d.ts +0 -4
- package/dist/tests/fixtures/CommandRegistry.d.ts.map +0 -1
- package/dist/tests/fixtures/ConfigurationServiceProvider.d.ts +0 -10
- package/dist/tests/fixtures/ConfigurationServiceProvider.d.ts.map +0 -1
- package/dist/tests/fixtures/Context.d.ts +0 -4
- package/dist/tests/fixtures/Context.d.ts.map +0 -1
- package/dist/tests/fixtures/ServiceProviderRegistry.d.ts +0 -4
- package/dist/tests/fixtures/ServiceProviderRegistry.d.ts.map +0 -1
- package/dist/tests/fixtures/StreamString.d.ts +0 -10
- package/dist/tests/fixtures/StreamString.d.ts.map +0 -1
- package/dist/tests/fixtures/prettierPluginFoo.d.ts +0 -4
- package/dist/tests/fixtures/prettierPluginFoo.d.ts.map +0 -1
- package/dist/tests/fixtures/util.d.ts +0 -8
- package/dist/tests/fixtures/util.d.ts.map +0 -1
- package/dist/tests/runtime/DefaultContext.test.d.ts +0 -2
- package/dist/tests/runtime/DefaultContext.test.d.ts.map +0 -1
- package/dist/tests/runtime/argument/ArgumentTypeGuards.test.d.ts +0 -2
- package/dist/tests/runtime/argument/ArgumentTypeGuards.test.d.ts.map +0 -1
- package/dist/tests/runtime/command/CommandTypeGuards.test.d.ts +0 -2
- package/dist/tests/runtime/command/CommandTypeGuards.test.d.ts.map +0 -1
- package/dist/tests/runtime/command/CommandValidator.test.d.ts +0 -2
- package/dist/tests/runtime/command/CommandValidator.test.d.ts.map +0 -1
- package/dist/tests/runtime/parser.test.d.ts +0 -2
- package/dist/tests/runtime/parser.test.d.ts.map +0 -1
- package/dist/tests/runtime/registry/DefaultCommandRegistry.test.d.ts +0 -2
- package/dist/tests/runtime/registry/DefaultCommandRegistry.test.d.ts.map +0 -1
- package/dist/tests/runtime/registry/DefaultServiceProviderRegistry.test.d.ts +0 -2
- package/dist/tests/runtime/registry/DefaultServiceProviderRegistry.test.d.ts.map +0 -1
- package/dist/tests/runtime/runner.test.d.ts +0 -2
- package/dist/tests/runtime/runner.test.d.ts.map +0 -1
- package/dist/tests/runtime/scanner.test.d.ts +0 -2
- package/dist/tests/runtime/scanner.test.d.ts.map +0 -1
- package/dist/tests/runtime/values/argumentValueMerge.test.d.ts +0 -2
- package/dist/tests/runtime/values/argumentValueMerge.test.d.ts.map +0 -1
- package/dist/tests/runtime/values/argumentValueValidation.test.d.ts +0 -2
- package/dist/tests/runtime/values/argumentValueValidation.test.d.ts.map +0 -1
- package/dist/tests/runtime/values/globalCommandValuePopulation.test.d.ts +0 -2
- package/dist/tests/runtime/values/globalCommandValuePopulation.test.d.ts.map +0 -1
- package/dist/tests/runtime/values/subCommandValuePopulation.test.d.ts +0 -2
- package/dist/tests/runtime/values/subCommandValuePopulation.test.d.ts.map +0 -1
- package/dist/tests/service/argumentPrompter/ArgumentPrompterServiceProvider.test.d.ts +0 -2
- package/dist/tests/service/argumentPrompter/ArgumentPrompterServiceProvider.test.d.ts.map +0 -1
- package/dist/tests/service/argumentPrompter/DefaultArgumentPrompterService.test.d.ts +0 -2
- package/dist/tests/service/argumentPrompter/DefaultArgumentPrompterService.test.d.ts.map +0 -1
- package/dist/tests/service/asciiBannerGenerator/AsciiBannerGeneratorServiceProvider.test.d.ts +0 -2
- package/dist/tests/service/asciiBannerGenerator/AsciiBannerGeneratorServiceProvider.test.d.ts.map +0 -1
- package/dist/tests/service/asciiBannerGenerator/DefaultAsciiBannerGeneratorService.test.d.ts +0 -2
- package/dist/tests/service/asciiBannerGenerator/DefaultAsciiBannerGeneratorService.test.d.ts.map +0 -1
- package/dist/tests/service/banner/BannerServiceProvider.test.d.ts +0 -2
- package/dist/tests/service/banner/BannerServiceProvider.test.d.ts.map +0 -1
- package/dist/tests/service/banner/command/NoBannerCommand.test.d.ts +0 -2
- package/dist/tests/service/banner/command/NoBannerCommand.test.d.ts.map +0 -1
- package/dist/tests/service/chiselAsciiBannerGenerator/ChiselFontAsciiBannerGeneratorService.test.d.ts +0 -2
- package/dist/tests/service/chiselAsciiBannerGenerator/ChiselFontAsciiBannerGeneratorService.test.d.ts.map +0 -1
- package/dist/tests/service/completion/CompletionServiceProvider.test.d.ts +0 -2
- package/dist/tests/service/completion/CompletionServiceProvider.test.d.ts.map +0 -1
- package/dist/tests/service/completion/DefaultCompletionService.test.d.ts +0 -2
- package/dist/tests/service/completion/DefaultCompletionService.test.d.ts.map +0 -1
- package/dist/tests/service/completion/shell/bash.test.d.ts +0 -2
- package/dist/tests/service/completion/shell/bash.test.d.ts.map +0 -1
- package/dist/tests/service/completion/shell/fish.test.d.ts +0 -2
- package/dist/tests/service/completion/shell/fish.test.d.ts.map +0 -1
- package/dist/tests/service/completion/shell/powershell.test.d.ts +0 -2
- package/dist/tests/service/completion/shell/powershell.test.d.ts.map +0 -1
- package/dist/tests/service/completion/shell/zsh.test.d.ts +0 -2
- package/dist/tests/service/completion/shell/zsh.test.d.ts.map +0 -1
- package/dist/tests/service/configuration/ConfigurationServiceProvider.test.d.ts +0 -2
- package/dist/tests/service/configuration/ConfigurationServiceProvider.test.d.ts.map +0 -1
- package/dist/tests/service/configuration/DefaultKeyValueService.test.d.ts +0 -2
- package/dist/tests/service/configuration/DefaultKeyValueService.test.d.ts.map +0 -1
- package/dist/tests/service/configuration/DefaultSecretService.test.d.ts +0 -2
- package/dist/tests/service/configuration/DefaultSecretService.test.d.ts.map +0 -1
- package/dist/tests/service/configuration/command/ConfigCommand.test.d.ts +0 -2
- package/dist/tests/service/configuration/command/ConfigCommand.test.d.ts.map +0 -1
- package/dist/tests/service/configuration/command/DumpConfigCommand.test.d.ts +0 -2
- package/dist/tests/service/configuration/command/DumpConfigCommand.test.d.ts.map +0 -1
- package/dist/tests/service/dataDumpGenerator/DataDumpGeneratorServiceProvider.test.d.ts +0 -2
- package/dist/tests/service/dataDumpGenerator/DataDumpGeneratorServiceProvider.test.d.ts.map +0 -1
- package/dist/tests/service/dataDumpGenerator/DefaultDataDumpGeneratorService.test.d.ts +0 -2
- package/dist/tests/service/dataDumpGenerator/DefaultDataDumpGeneratorService.test.d.ts.map +0 -1
- package/dist/tests/service/imagePrinter/DefaultImagePrinterService.test.d.ts +0 -2
- package/dist/tests/service/imagePrinter/DefaultImagePrinterService.test.d.ts.map +0 -1
- package/dist/tests/service/imagePrinter/ImagePrinterServiceProvider.test.d.ts +0 -2
- package/dist/tests/service/imagePrinter/ImagePrinterServiceProvider.test.d.ts.map +0 -1
- package/dist/tests/service/plugin/DefaultPluginServiceProvider.test.d.ts +0 -2
- package/dist/tests/service/plugin/DefaultPluginServiceProvider.test.d.ts.map +0 -1
- package/dist/tests/service/prettyPrinter/DefaultPrettyPrinterService.test.d.ts +0 -2
- package/dist/tests/service/prettyPrinter/DefaultPrettyPrinterService.test.d.ts.map +0 -1
- package/dist/tests/service/prettyPrinter/PrettyPrinterServiceProvider.test.d.ts +0 -2
- package/dist/tests/service/prettyPrinter/PrettyPrinterServiceProvider.test.d.ts.map +0 -1
- package/dist/tests/service/printer/DefaultPrinterService.test.d.ts +0 -2
- package/dist/tests/service/printer/DefaultPrinterService.test.d.ts.map +0 -1
- package/dist/tests/service/printer/PrinterServiceProvider.test.d.ts +0 -2
- package/dist/tests/service/printer/PrinterServiceProvider.test.d.ts.map +0 -1
- package/dist/tests/service/printer/command/DarkModeCommand.test.d.ts +0 -2
- package/dist/tests/service/printer/command/DarkModeCommand.test.d.ts.map +0 -1
- package/dist/tests/service/printer/command/LogLevelCommand.test.d.ts +0 -2
- package/dist/tests/service/printer/command/LogLevelCommand.test.d.ts.map +0 -1
- package/dist/tests/service/printer/command/NoColorCommand.test.d.ts +0 -2
- package/dist/tests/service/printer/command/NoColorCommand.test.d.ts.map +0 -1
- package/dist/tests/service/printer/command/NoHyperlinksCommand.test.d.ts +0 -2
- package/dist/tests/service/printer/command/NoHyperlinksCommand.test.d.ts.map +0 -1
- package/dist/tests/service/printer/terminal/Progress.test.d.ts +0 -2
- package/dist/tests/service/printer/terminal/Progress.test.d.ts.map +0 -1
- package/dist/tests/service/printer/terminal/Spinner.test.d.ts +0 -2
- package/dist/tests/service/printer/terminal/Spinner.test.d.ts.map +0 -1
- package/dist/tests/service/prompter/DefaultPrompterService.test.d.ts +0 -2
- package/dist/tests/service/prompter/DefaultPrompterService.test.d.ts.map +0 -1
- package/dist/tests/service/prompter/PrompterServiceProvider.test.d.ts +0 -2
- package/dist/tests/service/prompter/PrompterServiceProvider.test.d.ts.map +0 -1
- package/dist/tests/service/prompter/command/NoPromptCommand.test.d.ts +0 -2
- package/dist/tests/service/prompter/command/NoPromptCommand.test.d.ts.map +0 -1
- package/dist/tests/service/prompter/prompt/PromptContext.test.d.ts +0 -2
- package/dist/tests/service/prompter/prompt/PromptContext.test.d.ts.map +0 -1
- package/dist/tests/service/shutdown/ShutdownServiceProvider.test.d.ts +0 -2
- package/dist/tests/service/shutdown/ShutdownServiceProvider.test.d.ts.map +0 -1
- package/dist/tests/service/syntaxHighlighter/DefaultSyntaxHighlighterService.test.d.ts +0 -2
- package/dist/tests/service/syntaxHighlighter/DefaultSyntaxHighlighterService.test.d.ts.map +0 -1
- package/dist/tests/service/syntaxHighlighter/SyntaxHighlighterServiceProvider.test.d.ts +0 -2
- package/dist/tests/service/syntaxHighlighter/SyntaxHighlighterServiceProvider.test.d.ts.map +0 -1
- package/dist/tests/service/tableGenerator/DefaultTableGeneratorService.test.d.ts +0 -2
- package/dist/tests/service/tableGenerator/DefaultTableGeneratorService.test.d.ts.map +0 -1
- package/dist/tests/service/tableGenerator/TableGeneratorServiceProvider.test.d.ts +0 -2
- package/dist/tests/service/tableGenerator/TableGeneratorServiceProvider.test.d.ts.map +0 -1
- package/dist/tests/service/treePrinter/DefaultTreePrinterService.test.d.ts +0 -2
- package/dist/tests/service/treePrinter/DefaultTreePrinterService.test.d.ts.map +0 -1
- package/dist/tests/service/treePrinter/TreePrinterServiceProvider.test.d.ts +0 -2
- package/dist/tests/service/treePrinter/TreePrinterServiceProvider.test.d.ts.map +0 -1
- package/dist/tests/terminal/ImageRenderer.test.d.ts +0 -2
- package/dist/tests/terminal/ImageRenderer.test.d.ts.map +0 -1
- package/dist/tests/terminal/PngDecoder.test.d.ts +0 -2
- package/dist/tests/terminal/PngDecoder.test.d.ts.map +0 -1
- package/dist/tests/terminal/supportsHyperlinks.test.d.ts +0 -2
- package/dist/tests/terminal/supportsHyperlinks.test.d.ts.map +0 -1
- package/dist/tests/util/configHelper.test.d.ts +0 -2
- package/dist/tests/util/configHelper.test.d.ts.map +0 -1
- package/dist/tests/util/envVarHelper.test.d.ts +0 -2
- package/dist/tests/util/envVarHelper.test.d.ts.map +0 -1
- package/dist/tests/util/logger.test.d.ts +0 -2
- package/dist/tests/util/logger.test.d.ts.map +0 -1
- package/src/command/PluginCommand.ts +0 -197
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { RunState } from "../api/RunResult.js";
|
|
2
|
+
import DefaultRuntimeCLI from "./DefaultRuntimeCLI.js";
|
|
3
|
+
import DefaultPluginServiceProvider from "../service/plugin/DefaultPluginServiceProvider.js";
|
|
4
|
+
import { DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT } from "../api/plugin/CommandFactory.js";
|
|
5
|
+
import { DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT } from "../api/plugin/ServiceProviderFactory.js";
|
|
6
|
+
import process from "node:process";
|
|
7
|
+
/**
|
|
8
|
+
* Extension of {@link DefaultRuntimeCLI} that discovers and loads installed plugins before running.
|
|
9
|
+
*
|
|
10
|
+
* On each invocation of {@link run}, all locally installed plugins are discovered via the
|
|
11
|
+
* {@link MarketplacePluginManager}. Commands provided by {@link CommandFactory} extensions and
|
|
12
|
+
* service providers provided by {@link ServiceProviderFactory} extensions are registered before
|
|
13
|
+
* the runner starts, so they participate in the full initialization lifecycle.
|
|
14
|
+
*/
|
|
15
|
+
export default class DynamicPluginRuntimeCLI extends DefaultRuntimeCLI {
|
|
16
|
+
#pluginManager;
|
|
17
|
+
constructor(cliConfig, pluginManager, options) {
|
|
18
|
+
super(cliConfig, options);
|
|
19
|
+
this.#pluginManager = pluginManager;
|
|
20
|
+
this.addServiceProvider(new DefaultPluginServiceProvider(pluginManager));
|
|
21
|
+
}
|
|
22
|
+
async run() {
|
|
23
|
+
try {
|
|
24
|
+
await this.loadPlugins();
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
console.error(err);
|
|
28
|
+
process.exit(RunState.RUNTIME_ERROR);
|
|
29
|
+
}
|
|
30
|
+
return super.run();
|
|
31
|
+
}
|
|
32
|
+
async loadPlugins() {
|
|
33
|
+
await this.#pluginManager.registerExtensions(DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT);
|
|
34
|
+
await this.#pluginManager.registerExtensions(DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT);
|
|
35
|
+
const commandFactoryExtensions = await this.#pluginManager.getRegisteredExtensions(DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT);
|
|
36
|
+
for (const ext of commandFactoryExtensions) {
|
|
37
|
+
const factory = (await this.#pluginManager.instantiate(ext.extensionHandle));
|
|
38
|
+
for (const command of factory.getCommands()) {
|
|
39
|
+
this.addCommand(command);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const spFactoryExtensions = await this.#pluginManager.getRegisteredExtensions(DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT);
|
|
43
|
+
for (const ext of spFactoryExtensions) {
|
|
44
|
+
const factory = (await this.#pluginManager.instantiate(ext.extensionHandle));
|
|
45
|
+
for (const sp of factory.getServiceProviders()) {
|
|
46
|
+
this.addServiceProvider(sp);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { ArgumentValueTypeName, } from "../api/argument/ArgumentValueTypes.js";
|
|
2
|
+
import { findPossibleCommandNames, getCommandArgsHelpSections, getCommandExamplesHelpSections, getGlobalArgumentHelpEntry, getMultiCommandAppSyntax, getSubCommandArgumentsSyntax, printHelpSections, } from "../util/helpHelper.js";
|
|
3
|
+
import { Icon, PRINTER_SERVICE_ID } from "../api/service/core/PrinterService.js";
|
|
4
|
+
import { TABLE_GENERATOR_SERVICE_ID } from "../api/service/core/TableGeneratorService.js";
|
|
5
|
+
/**
|
|
6
|
+
* Provides common implementation for both {@link MultiCommandCliHelpGlobalCommand} and {@link MultiCommandCliHelpSubCommand}.
|
|
7
|
+
*/
|
|
8
|
+
class MultiCommandCliAbstractHelpCommand {
|
|
9
|
+
name = "help";
|
|
10
|
+
description = "Display application help";
|
|
11
|
+
#includeEnvVars;
|
|
12
|
+
#commandRegistry;
|
|
13
|
+
constructor(includeEnvVars, commandRegistry) {
|
|
14
|
+
this.#includeEnvVars = includeEnvVars;
|
|
15
|
+
this.#commandRegistry = commandRegistry;
|
|
16
|
+
}
|
|
17
|
+
#getGlobalCommandsHelpSection(context, title, globalCommands) {
|
|
18
|
+
const globalCommandsSection = {
|
|
19
|
+
title,
|
|
20
|
+
helpEntries: [],
|
|
21
|
+
};
|
|
22
|
+
globalCommands.forEach((globalCommand) => {
|
|
23
|
+
const { syntax, description } = getGlobalArgumentHelpEntry(context.cliConfig, this.#includeEnvVars, globalCommand);
|
|
24
|
+
globalCommandsSection.helpEntries.push({
|
|
25
|
+
syntax: `--${globalCommand.name} ${syntax}`,
|
|
26
|
+
description,
|
|
27
|
+
});
|
|
28
|
+
if (globalCommand.shortAlias !== undefined) {
|
|
29
|
+
globalCommandsSection.helpEntries.push({
|
|
30
|
+
syntax: `-${globalCommand.shortAlias} ${syntax}`,
|
|
31
|
+
description,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
globalCommandsSection.helpEntries.sort((a, b) => a.syntax.localeCompare(b.syntax));
|
|
36
|
+
return globalCommandsSection;
|
|
37
|
+
}
|
|
38
|
+
#getGenericHelpSections(context, globalModifierCommands, globalCommands, groupCommands, subCommands) {
|
|
39
|
+
const globalPrefix = groupCommands.length > 0 || subCommands.length > 0 ? "Global " : "";
|
|
40
|
+
const helpSections = [];
|
|
41
|
+
if (globalModifierCommands.length > 0) {
|
|
42
|
+
helpSections.push(this.#getGlobalCommandsHelpSection(context, `${globalPrefix}Options`, globalModifierCommands));
|
|
43
|
+
}
|
|
44
|
+
if (globalCommands.length > 0) {
|
|
45
|
+
helpSections.push(this.#getGlobalCommandsHelpSection(context, `${globalPrefix}Commands`, globalCommands));
|
|
46
|
+
}
|
|
47
|
+
groupCommands.forEach((groupCommand) => {
|
|
48
|
+
const visibleMemberSubCommands = groupCommand.memberSubCommands.filter((memberCommand) => !memberCommand.disableGenericHelpDisplay);
|
|
49
|
+
if (visibleMemberSubCommands.length === 0)
|
|
50
|
+
return;
|
|
51
|
+
const topicSection = {
|
|
52
|
+
title: `${groupCommand.name.charAt(0).toUpperCase() + groupCommand.name.slice(1)} Commands`,
|
|
53
|
+
helpEntries: [],
|
|
54
|
+
};
|
|
55
|
+
visibleMemberSubCommands.forEach((memberCommand) => {
|
|
56
|
+
topicSection.helpEntries.push({
|
|
57
|
+
syntax: `${groupCommand.name}:${memberCommand.name}`,
|
|
58
|
+
description: memberCommand.description,
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
topicSection.helpEntries.sort((a, b) => a.syntax.localeCompare(b.syntax));
|
|
62
|
+
helpSections.push(topicSection);
|
|
63
|
+
});
|
|
64
|
+
if (subCommands.length > 0) {
|
|
65
|
+
const subCommandsByTopic = new Map();
|
|
66
|
+
const otherSubCommands = [];
|
|
67
|
+
subCommands.forEach((subCommand) => {
|
|
68
|
+
if (subCommand.helpTopic === undefined) {
|
|
69
|
+
otherSubCommands.push(subCommand);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const commands = subCommandsByTopic.get(subCommand.helpTopic) || [];
|
|
73
|
+
commands.push(subCommand);
|
|
74
|
+
subCommandsByTopic.set(subCommand.helpTopic, commands);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
for (const key of subCommandsByTopic.keys()) {
|
|
78
|
+
const topicCommands = subCommandsByTopic.get(key);
|
|
79
|
+
if (topicCommands !== undefined) {
|
|
80
|
+
const topicSection = {
|
|
81
|
+
title: `${key.charAt(0).toUpperCase() + key.slice(1)} Commands`,
|
|
82
|
+
helpEntries: [],
|
|
83
|
+
};
|
|
84
|
+
topicCommands.sort((a, b) => a.name.localeCompare(b.name));
|
|
85
|
+
topicCommands.forEach((subCommand) => {
|
|
86
|
+
topicSection.helpEntries.push({
|
|
87
|
+
syntax: subCommand.name,
|
|
88
|
+
description: subCommand.description,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
helpSections.push(topicSection);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (otherSubCommands.length > 0) {
|
|
95
|
+
const topicSection = {
|
|
96
|
+
title: subCommandsByTopic.size > 0 || groupCommands.length > 0
|
|
97
|
+
? "Other Commands"
|
|
98
|
+
: "Sub-Commands",
|
|
99
|
+
helpEntries: [],
|
|
100
|
+
};
|
|
101
|
+
otherSubCommands.sort((a, b) => a.name.localeCompare(b.name));
|
|
102
|
+
otherSubCommands.forEach((subCommand) => {
|
|
103
|
+
topicSection.helpEntries.push({
|
|
104
|
+
syntax: subCommand.name,
|
|
105
|
+
description: subCommand.description,
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
helpSections.push(topicSection);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return helpSections;
|
|
112
|
+
}
|
|
113
|
+
async printGenericHelp(context) {
|
|
114
|
+
const printerService = context.getServiceById(PRINTER_SERVICE_ID);
|
|
115
|
+
const tableGeneratorService = context.getServiceById(TABLE_GENERATOR_SERVICE_ID);
|
|
116
|
+
const globalModifierCommands = this.#commandRegistry
|
|
117
|
+
.getGlobalModifierCommands()
|
|
118
|
+
.filter((command) => !command.disableGenericHelpDisplay);
|
|
119
|
+
const globalCommands = this.#commandRegistry
|
|
120
|
+
.getGlobalCommands()
|
|
121
|
+
.filter((command) => !command.disableGenericHelpDisplay);
|
|
122
|
+
const groupCommands = this.#commandRegistry
|
|
123
|
+
.getGroupCommands()
|
|
124
|
+
.filter((command) => !command.disableGenericHelpDisplay);
|
|
125
|
+
const subCommands = this.#commandRegistry
|
|
126
|
+
.getSubCommands()
|
|
127
|
+
.filter((command) => !command.disableGenericHelpDisplay);
|
|
128
|
+
const helpSections = [];
|
|
129
|
+
helpSections.push({
|
|
130
|
+
title: "Usage",
|
|
131
|
+
helpEntries: [
|
|
132
|
+
{
|
|
133
|
+
syntax: getMultiCommandAppSyntax(context, globalModifierCommands, globalCommands, groupCommands, subCommands),
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
});
|
|
137
|
+
helpSections.push(...this.#getGenericHelpSections(context, globalModifierCommands, globalCommands, groupCommands, subCommands));
|
|
138
|
+
await printHelpSections(printerService, tableGeneratorService, helpSections);
|
|
139
|
+
}
|
|
140
|
+
async printUsageHelp(context, commandName) {
|
|
141
|
+
const printerService = context.getServiceById(PRINTER_SERVICE_ID);
|
|
142
|
+
const tableGeneratorService = context.getServiceById(TABLE_GENERATOR_SERVICE_ID);
|
|
143
|
+
const groupCommands = this.#commandRegistry
|
|
144
|
+
.getGroupCommands()
|
|
145
|
+
.filter((command) => !command.disableGenericHelpDisplay);
|
|
146
|
+
const subCommands = this.#commandRegistry
|
|
147
|
+
.getSubCommands()
|
|
148
|
+
.filter((command) => !command.disableGenericHelpDisplay);
|
|
149
|
+
// find sub-command or group sub-command
|
|
150
|
+
let subCommand = this.#commandRegistry.getSubCommandByName(commandName);
|
|
151
|
+
let groupCommand;
|
|
152
|
+
if (subCommand === undefined) {
|
|
153
|
+
const result = this.#commandRegistry.getGroupCommandAndMemberSubCommandByJoinedName(commandName);
|
|
154
|
+
if (result !== undefined) {
|
|
155
|
+
groupCommand = result.groupCommand;
|
|
156
|
+
subCommand = result.command;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (subCommand === undefined) {
|
|
160
|
+
await printerService.print(`Unknown command: ${printerService.red(commandName)}\n\n`, Icon.FAILURE);
|
|
161
|
+
// look for other possible matches
|
|
162
|
+
const possibleCommandNames = findPossibleCommandNames(commandName, groupCommands, subCommands);
|
|
163
|
+
if (possibleCommandNames.length > 0) {
|
|
164
|
+
await printerService.print(`Possible matches: ${possibleCommandNames.join(", ")}\n\n`, Icon.INFORMATION);
|
|
165
|
+
}
|
|
166
|
+
await this.printGenericHelp(context);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
// display command help
|
|
170
|
+
const name = groupCommand === undefined ? subCommand.name : `${groupCommand.name}:${subCommand.name}`;
|
|
171
|
+
const helpSections = [];
|
|
172
|
+
if (subCommand.description !== undefined && subCommand.description.length > 0) {
|
|
173
|
+
helpSections.push({
|
|
174
|
+
title: "Command",
|
|
175
|
+
helpEntries: [
|
|
176
|
+
{
|
|
177
|
+
syntax: subCommand.name,
|
|
178
|
+
description: subCommand.description,
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
helpSections.push({
|
|
184
|
+
title: "Usage",
|
|
185
|
+
helpEntries: [
|
|
186
|
+
{
|
|
187
|
+
syntax: `${context.cliConfig.name}${name.length > 0 ? ` ${name}` : ""}${getSubCommandArgumentsSyntax(subCommand)}`,
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
});
|
|
191
|
+
helpSections.push(...getCommandArgsHelpSections(context.cliConfig, this.#includeEnvVars, subCommand, false));
|
|
192
|
+
helpSections.push(...getCommandExamplesHelpSections(printerService, context, subCommand));
|
|
193
|
+
await printHelpSections(printerService, tableGeneratorService, helpSections);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Implementation of multi-command CLI help available via `myCli --help`, `myCli -h`, `myCli --help <command>` or `myCli -h <command>`.
|
|
198
|
+
*/
|
|
199
|
+
export class MultiCommandCliHelpGlobalCommand extends MultiCommandCliAbstractHelpCommand {
|
|
200
|
+
shortAlias = "h";
|
|
201
|
+
argument = {
|
|
202
|
+
name: "command",
|
|
203
|
+
type: ArgumentValueTypeName.STRING,
|
|
204
|
+
isOptional: true,
|
|
205
|
+
};
|
|
206
|
+
async execute(context, argumentValue) {
|
|
207
|
+
const commandName = argumentValue;
|
|
208
|
+
if (commandName !== undefined) {
|
|
209
|
+
await this.printUsageHelp(context, commandName);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
await this.printGenericHelp(context);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Implementation of multi-command CLI help available via `myCli help` or `myCli help <command>`.
|
|
218
|
+
*/
|
|
219
|
+
export class MultiCommandCliHelpSubCommand extends MultiCommandCliAbstractHelpCommand {
|
|
220
|
+
options = [];
|
|
221
|
+
positionals = [
|
|
222
|
+
{
|
|
223
|
+
name: "command",
|
|
224
|
+
type: ArgumentValueTypeName.STRING,
|
|
225
|
+
isVarargOptional: true,
|
|
226
|
+
description: "Display help for the specific <command>",
|
|
227
|
+
},
|
|
228
|
+
];
|
|
229
|
+
async execute(context, argumentValues) {
|
|
230
|
+
const commandName = argumentValues["command"];
|
|
231
|
+
if (commandName !== undefined) {
|
|
232
|
+
await this.printUsageHelp(context, commandName);
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
await this.printGenericHelp(context);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { getCommandArgsHelpSections, getCommandExamplesHelpSections, getGlobalArgumentHelpEntry, getSubCommandArgumentsSyntax, printHelpSections, } from "../util/helpHelper.js";
|
|
2
|
+
import { PRINTER_SERVICE_ID } from "../api/service/core/PrinterService.js";
|
|
3
|
+
import { TABLE_GENERATOR_SERVICE_ID } from "../api/service/core/TableGeneratorService.js";
|
|
4
|
+
/**
|
|
5
|
+
* Provides common implementation for both {@link SingleCommandCliHelpGlobalCommand} and {@link SingleCommandCliHelpSubCommand}.
|
|
6
|
+
*/
|
|
7
|
+
class SingleCommandCliAbstractHelpCommand {
|
|
8
|
+
#includeEnvVars;
|
|
9
|
+
#defaultCommand;
|
|
10
|
+
#commandRegistry;
|
|
11
|
+
constructor(includeEnvVars, defaultCommand, commandRegistry) {
|
|
12
|
+
this.#includeEnvVars = includeEnvVars;
|
|
13
|
+
this.#defaultCommand = defaultCommand;
|
|
14
|
+
this.#commandRegistry = commandRegistry;
|
|
15
|
+
}
|
|
16
|
+
name = "help";
|
|
17
|
+
description = "Display application help";
|
|
18
|
+
#getAmalgamatedGenericHelpSection(context, globalModifierCommands, globalCommands, groupCommands, subCommands) {
|
|
19
|
+
const helpSection = {
|
|
20
|
+
title: "Other Arguments",
|
|
21
|
+
helpEntries: [],
|
|
22
|
+
};
|
|
23
|
+
if (globalModifierCommands.length > 0) {
|
|
24
|
+
globalModifierCommands.forEach((globalModifierCommand) => {
|
|
25
|
+
const { syntax, description } = getGlobalArgumentHelpEntry(context.cliConfig, this.#includeEnvVars, globalModifierCommand);
|
|
26
|
+
helpSection.helpEntries.push({
|
|
27
|
+
syntax: `--${globalModifierCommand.name} ${syntax}`,
|
|
28
|
+
description,
|
|
29
|
+
});
|
|
30
|
+
if (globalModifierCommand.shortAlias !== undefined) {
|
|
31
|
+
helpSection.helpEntries.push({
|
|
32
|
+
syntax: `-${globalModifierCommand.shortAlias} ${syntax}`,
|
|
33
|
+
description,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (globalCommands.length > 0) {
|
|
39
|
+
globalCommands.forEach((globalCommand) => {
|
|
40
|
+
const { syntax, description } = getGlobalArgumentHelpEntry(context.cliConfig, this.#includeEnvVars, globalCommand);
|
|
41
|
+
helpSection.helpEntries.push({
|
|
42
|
+
syntax: `--${globalCommand.name} ${syntax}`,
|
|
43
|
+
description,
|
|
44
|
+
});
|
|
45
|
+
if (globalCommand.shortAlias !== undefined) {
|
|
46
|
+
helpSection.helpEntries.push({
|
|
47
|
+
syntax: `-${globalCommand.shortAlias} ${syntax}`,
|
|
48
|
+
description,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
groupCommands.forEach((groupCommand) => {
|
|
54
|
+
groupCommand.memberSubCommands.forEach((memberCommand) => {
|
|
55
|
+
helpSection.helpEntries.push({
|
|
56
|
+
syntax: `${groupCommand.name}:${memberCommand.name}`,
|
|
57
|
+
description: memberCommand.description,
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
if (subCommands.length > 0) {
|
|
62
|
+
subCommands.forEach((subCommand) => {
|
|
63
|
+
helpSection.helpEntries.push({
|
|
64
|
+
syntax: subCommand.name,
|
|
65
|
+
description: subCommand.description,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
helpSection.helpEntries.sort((a, b) => a.syntax.localeCompare(b.syntax));
|
|
70
|
+
return helpSection;
|
|
71
|
+
}
|
|
72
|
+
async execute(context) {
|
|
73
|
+
const helpSections = [];
|
|
74
|
+
helpSections.push({
|
|
75
|
+
title: "Usage",
|
|
76
|
+
helpEntries: [
|
|
77
|
+
{
|
|
78
|
+
syntax: `${context.cliConfig.name || ""}${getSubCommandArgumentsSyntax(this.#defaultCommand)}`,
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
});
|
|
82
|
+
helpSections.push(...getCommandArgsHelpSections(context.cliConfig, this.#includeEnvVars, this.#defaultCommand, true));
|
|
83
|
+
const globalModifierCommands = this.#commandRegistry.getGlobalModifierCommands();
|
|
84
|
+
const globalCommands = this.#commandRegistry.getGlobalCommands();
|
|
85
|
+
helpSections.push(this.#getAmalgamatedGenericHelpSection(context, globalModifierCommands, globalCommands, [], []));
|
|
86
|
+
const printerService = context.getServiceById(PRINTER_SERVICE_ID);
|
|
87
|
+
const tableGeneratorService = context.getServiceById(TABLE_GENERATOR_SERVICE_ID);
|
|
88
|
+
helpSections.push(...getCommandExamplesHelpSections(printerService, context, this.#defaultCommand));
|
|
89
|
+
await printHelpSections(printerService, tableGeneratorService, helpSections);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Implementation of default command CLI help available via `myCli --help` or `myCli -h`.
|
|
94
|
+
*/
|
|
95
|
+
export class SingleCommandCliHelpGlobalCommand extends SingleCommandCliAbstractHelpCommand {
|
|
96
|
+
shortAlias = "h";
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Implementation of default-command CLI help available via `myCli help`.
|
|
100
|
+
*/
|
|
101
|
+
export class SingleCommandCliHelpSubCommand extends SingleCommandCliAbstractHelpCommand {
|
|
102
|
+
options = [];
|
|
103
|
+
positionals = [];
|
|
104
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PRINTER_SERVICE_ID } from "../api/service/core/PrinterService.js";
|
|
2
|
+
/**
|
|
3
|
+
* Command printing basic CLI usage.
|
|
4
|
+
*/
|
|
5
|
+
export default class UsageCommand {
|
|
6
|
+
name = "usage";
|
|
7
|
+
description = "Show usage information";
|
|
8
|
+
#helpCommand;
|
|
9
|
+
constructor(helpCommand) {
|
|
10
|
+
this.#helpCommand = helpCommand;
|
|
11
|
+
}
|
|
12
|
+
async execute(context) {
|
|
13
|
+
const printerService = context.getServiceById(PRINTER_SERVICE_ID);
|
|
14
|
+
await printerService.print(`${printerService.secondary("Try running:")}\n\n ${printerService.primary(context.cliConfig.name)} --${printerService.primary(this.#helpCommand.name)}\n\n`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PRINTER_SERVICE_ID } from "../api/service/core/PrinterService.js";
|
|
2
|
+
/**
|
|
3
|
+
* Implementation of a {@link GlobalCommand} which outputs the version of the CLI.
|
|
4
|
+
*/
|
|
5
|
+
export default class VersionCommand {
|
|
6
|
+
name = "version";
|
|
7
|
+
description = "Show version information";
|
|
8
|
+
shortAlias = "v";
|
|
9
|
+
async execute(context) {
|
|
10
|
+
const printerService = context.getServiceById(PRINTER_SERVICE_ID);
|
|
11
|
+
await printerService.print(`${context.cliConfig.version}\n`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import DefaultRuntimeCLI from "./cli/DefaultRuntimeCLI.js";
|
|
4
|
+
import DynamicPluginRuntimeCLI from "./cli/DynamicPluginRuntimeCLI.js";
|
|
5
|
+
export async function launchSingleCommandCLI(command, description, name, version, serviceProviders, options) {
|
|
6
|
+
if (!name) {
|
|
7
|
+
name = path.basename(process.execPath);
|
|
8
|
+
}
|
|
9
|
+
const cliConfig = {
|
|
10
|
+
description,
|
|
11
|
+
name,
|
|
12
|
+
version: version || "N/A",
|
|
13
|
+
};
|
|
14
|
+
const mergedOptions = {
|
|
15
|
+
...options,
|
|
16
|
+
validateAllCommands: (options?.validateAllCommands ?? false) ||
|
|
17
|
+
process.env.DYNAMIC_CLI_FRAMEWORK_VALIDATE_ALL !== undefined,
|
|
18
|
+
};
|
|
19
|
+
const cli = new DefaultRuntimeCLI(cliConfig, mergedOptions);
|
|
20
|
+
cli.addCommand(command);
|
|
21
|
+
serviceProviders?.forEach((service) => cli.addServiceProvider(service));
|
|
22
|
+
return await cli.run();
|
|
23
|
+
}
|
|
24
|
+
export async function launchMultiCommandCLI(commands, description, name, version, serviceProviders, options) {
|
|
25
|
+
if (!name) {
|
|
26
|
+
name = path.basename(process.execPath);
|
|
27
|
+
}
|
|
28
|
+
const cliConfig = {
|
|
29
|
+
description,
|
|
30
|
+
name,
|
|
31
|
+
version: version || "N/A",
|
|
32
|
+
};
|
|
33
|
+
const mergedOptions = {
|
|
34
|
+
...options,
|
|
35
|
+
validateAllCommands: (options?.validateAllCommands ?? false) ||
|
|
36
|
+
process.env.DYNAMIC_CLI_FRAMEWORK_VALIDATE_ALL !== undefined,
|
|
37
|
+
};
|
|
38
|
+
const cli = new DefaultRuntimeCLI(cliConfig, mergedOptions);
|
|
39
|
+
commands.forEach((command) => cli.addCommand(command));
|
|
40
|
+
serviceProviders?.forEach((service) => cli.addServiceProvider(service));
|
|
41
|
+
return await cli.run();
|
|
42
|
+
}
|
|
43
|
+
export async function launchDynamicPluginMultiCommandCLI(pluginManager, commands, description, name, version, serviceProviders, options) {
|
|
44
|
+
if (!name) {
|
|
45
|
+
name = path.basename(process.execPath);
|
|
46
|
+
}
|
|
47
|
+
const cliConfig = {
|
|
48
|
+
description,
|
|
49
|
+
name,
|
|
50
|
+
version: version || "N/A",
|
|
51
|
+
};
|
|
52
|
+
const mergedOptions = {
|
|
53
|
+
...options,
|
|
54
|
+
validateAllCommands: (options?.validateAllCommands ?? false) ||
|
|
55
|
+
process.env.DYNAMIC_CLI_FRAMEWORK_VALIDATE_ALL !== undefined,
|
|
56
|
+
};
|
|
57
|
+
const cli = new DynamicPluginRuntimeCLI(cliConfig, pluginManager, mergedOptions);
|
|
58
|
+
commands.forEach((command) => cli.addCommand(command));
|
|
59
|
+
serviceProviders?.forEach((service) => cli.addServiceProvider(service));
|
|
60
|
+
return await cli.run();
|
|
61
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default implementation of a {@link Context}.
|
|
3
|
+
*/
|
|
4
|
+
export default class DefaultContext {
|
|
5
|
+
cliConfig;
|
|
6
|
+
#serviceInstancesById = new Map();
|
|
7
|
+
constructor(cliConfig) {
|
|
8
|
+
this.cliConfig = cliConfig;
|
|
9
|
+
}
|
|
10
|
+
addServiceInstance(id, serviceInstance) {
|
|
11
|
+
if (this.#serviceInstancesById.has(id)) {
|
|
12
|
+
throw new Error(`Service ID: ${id} duplicates the ID of an existing service`);
|
|
13
|
+
}
|
|
14
|
+
this.#serviceInstancesById.set(id, serviceInstance);
|
|
15
|
+
}
|
|
16
|
+
getServiceById(id) {
|
|
17
|
+
if (!this.#serviceInstancesById.has(id)) {
|
|
18
|
+
throw new Error(`Service with ID: ${id} does not exist`);
|
|
19
|
+
}
|
|
20
|
+
return this.#serviceInstancesById.get(id);
|
|
21
|
+
}
|
|
22
|
+
doesServiceExist(id) {
|
|
23
|
+
return this.#serviceInstancesById.has(id);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function isGroupCommand(command) {
|
|
2
|
+
return command.memberSubCommands !== undefined;
|
|
3
|
+
}
|
|
4
|
+
export function isSubCommand(command) {
|
|
5
|
+
return command.options !== undefined;
|
|
6
|
+
}
|
|
7
|
+
export function isGlobalModifierCommand(command) {
|
|
8
|
+
return command.executePriority !== undefined;
|
|
9
|
+
}
|
|
10
|
+
export function isGlobalCommand(command) {
|
|
11
|
+
return !isGroupCommand(command) && !isSubCommand(command) && !isGlobalModifierCommand(command);
|
|
12
|
+
}
|