@flowscripter/dynamic-cli-framework 1.7.3 → 1.7.4

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.
Files changed (367) hide show
  1. package/cli-plugin.ts +1 -1
  2. package/dist/cli-plugin.d.ts +1 -1
  3. package/dist/cli-plugin.d.ts.map +1 -1
  4. package/dist/cli-plugin.js +25 -247
  5. package/dist/index.js +70 -105754
  6. package/dist/src/api/BaseCLIFeatureOptions.js +0 -0
  7. package/dist/src/api/CLI.js +0 -0
  8. package/dist/src/api/CLIConfig.js +0 -0
  9. package/dist/src/api/Context.js +0 -0
  10. package/dist/src/api/RunResult.js +73 -0
  11. package/dist/src/api/argument/Argument.js +0 -0
  12. package/dist/src/api/argument/ArgumentValueTypes.js +18 -0
  13. package/dist/src/api/argument/ComplexOption.js +1 -0
  14. package/dist/src/api/argument/GlobalCommandArgument.js +0 -0
  15. package/dist/src/api/argument/Option.js +0 -0
  16. package/dist/src/api/argument/Positional.js +0 -0
  17. package/dist/src/api/argument/SubCommandArgument.js +1 -0
  18. package/dist/src/api/command/Command.js +0 -0
  19. package/dist/src/api/command/GlobalCommand.js +0 -0
  20. package/dist/src/api/command/GlobalModifierCommand.js +0 -0
  21. package/dist/src/api/command/GroupCommand.js +0 -0
  22. package/dist/src/api/command/SubCommand.js +0 -0
  23. package/dist/src/api/command/UsageExample.js +0 -0
  24. package/dist/src/api/plugin/CLIPlugin.js +2 -0
  25. package/dist/src/api/plugin/CommandFactory.js +7 -0
  26. package/dist/src/api/plugin/ServiceProviderFactory.js +7 -0
  27. package/dist/src/api/plugin/createCLIPlugin.js +30 -0
  28. package/dist/src/api/service/ServiceProvider.js +0 -0
  29. package/dist/src/api/service/core/ArgumentPrompterService.js +1 -0
  30. package/dist/src/api/service/core/AsciiBannerGeneratorService.js +1 -0
  31. package/dist/src/api/service/core/CompletionService.js +8 -0
  32. package/dist/src/api/service/core/DataDumpGeneratorService.js +7 -0
  33. package/dist/src/api/service/core/ImagePrinterService.js +1 -0
  34. package/dist/src/api/service/core/KeyValueService.js +7 -0
  35. package/dist/src/api/service/core/PluginService.js +6 -0
  36. package/dist/src/api/service/core/PrettyPrinterService.js +1 -0
  37. package/dist/src/api/service/core/PrinterService.js +42 -0
  38. package/dist/src/api/service/core/PrompterService.js +10 -0
  39. package/dist/src/api/service/core/SecretService.js +0 -0
  40. package/dist/src/api/service/core/ShutdownService.js +1 -0
  41. package/dist/src/api/service/core/SyntaxHighlighterService.js +1 -0
  42. package/dist/src/api/service/core/Table.js +49 -0
  43. package/dist/src/api/service/core/TableGeneratorService.d.ts +1 -0
  44. package/dist/src/api/service/core/TableGeneratorService.d.ts.map +1 -1
  45. package/dist/src/api/service/core/TableGeneratorService.js +7 -0
  46. package/dist/src/api/service/core/TreePrinterService.js +1 -0
  47. package/dist/src/cli/BaseCLI.d.ts.map +1 -1
  48. package/dist/src/cli/BaseCLI.js +233 -0
  49. package/dist/src/cli/DefaultRuntimeCLI.js +20 -0
  50. package/dist/src/cli/DynamicPluginRuntimeCLI.js +50 -0
  51. package/dist/src/command/MultiCommandCliHelpCommand.js +238 -0
  52. package/dist/src/command/SingleCommandCliHelpCommand.js +104 -0
  53. package/dist/src/command/UsageCommand.js +16 -0
  54. package/dist/src/command/VersionCommand.js +13 -0
  55. package/dist/src/launcher.js +61 -0
  56. package/dist/src/runtime/DefaultContext.js +25 -0
  57. package/dist/src/runtime/argument/ArgumentTypeGuards.js +3 -0
  58. package/dist/src/runtime/command/CommandTypeGuards.js +12 -0
  59. package/dist/src/runtime/command/CommandValidator.js +371 -0
  60. package/dist/src/runtime/parser.js +105 -0
  61. package/dist/src/runtime/registry/CommandRegistry.js +0 -0
  62. package/dist/src/runtime/registry/DefaultCommandRegistry.js +190 -0
  63. package/dist/src/runtime/registry/DefaultServiceProviderRegistry.js +20 -0
  64. package/dist/src/runtime/registry/ServiceProviderRegistry.js +0 -0
  65. package/dist/src/runtime/runner.js +507 -0
  66. package/dist/src/runtime/scanner.js +244 -0
  67. package/dist/src/runtime/values/ValuePopulationResult.js +0 -0
  68. package/dist/src/runtime/values/argumentValueMerge.js +122 -0
  69. package/dist/src/runtime/values/argumentValueValidation.js +505 -0
  70. package/dist/src/runtime/values/globalCommandValuePopulation.js +67 -0
  71. package/dist/src/runtime/values/subCommandValuePopulation.js +549 -0
  72. package/dist/src/service/argumentPrompter/ArgumentPrompterServiceProvider.js +19 -0
  73. package/dist/src/service/argumentPrompter/DefaultArgumentPrompterService.js +197 -0
  74. package/dist/src/service/asciiBannerGenerator/AsciiBannerGeneratorServiceProvider.js +28 -0
  75. package/dist/src/service/asciiBannerGenerator/DefaultAsciiBannerGeneratorService.js +233 -0
  76. package/dist/src/service/asciiBannerGenerator/standard.flf.json +3 -0
  77. package/dist/src/service/banner/BannerServiceProvider.js +60 -0
  78. package/dist/src/service/banner/command/NoBannerCommand.js +24 -0
  79. package/dist/src/service/chiselAsciiBannerGenerator/ChiselFontAsciiBannerGeneratorService.js +51 -0
  80. package/dist/src/service/chiselAsciiBannerGenerator/chisel.flf.json +3 -0
  81. package/dist/src/service/completion/CompletionServiceProvider.d.ts +2 -1
  82. package/dist/src/service/completion/CompletionServiceProvider.d.ts.map +1 -1
  83. package/dist/src/service/completion/CompletionServiceProvider.js +160 -0
  84. package/dist/src/service/completion/DefaultCompletionService.js +279 -0
  85. package/dist/src/service/completion/command/CompletionCompleteSubCommand.d.ts +15 -0
  86. package/dist/src/service/completion/command/CompletionCompleteSubCommand.d.ts.map +1 -0
  87. package/dist/src/service/completion/command/CompletionCompleteSubCommand.js +37 -0
  88. package/dist/src/service/completion/command/CompletionGroupCommand.d.ts +14 -0
  89. package/dist/src/service/completion/command/CompletionGroupCommand.d.ts.map +1 -0
  90. package/dist/src/service/completion/command/CompletionGroupCommand.js +10 -0
  91. package/dist/src/service/completion/command/CompletionIntegrationSubCommand.d.ts +14 -0
  92. package/dist/src/service/completion/command/CompletionIntegrationSubCommand.d.ts.map +1 -0
  93. package/dist/src/service/completion/command/CompletionIntegrationSubCommand.js +67 -0
  94. package/dist/src/service/completion/shell/ShellHandler.js +0 -0
  95. package/dist/src/service/completion/shell/bash.js +39 -0
  96. package/dist/src/service/completion/shell/fish.js +35 -0
  97. package/dist/src/service/completion/shell/powershell.js +51 -0
  98. package/dist/src/service/completion/shell/zsh.js +42 -0
  99. package/dist/src/service/configuration/ConfigurationServiceProvider.js +482 -0
  100. package/dist/src/service/configuration/DefaultKeyValueService.js +80 -0
  101. package/dist/src/service/configuration/DefaultSecretService.js +60 -0
  102. package/dist/src/service/configuration/command/ConfigCommand.js +24 -0
  103. package/dist/src/service/configuration/command/DumpConfigCommand.js +18 -0
  104. package/dist/src/service/dataDumpGenerator/DataDumpGeneratorServiceProvider.js +24 -0
  105. package/dist/src/service/dataDumpGenerator/DefaultDataDumpGeneratorService.js +59 -0
  106. package/dist/src/service/imagePrinter/DefaultImagePrinterService.js +10 -0
  107. package/dist/src/service/imagePrinter/ImagePrinterServiceProvider.js +20 -0
  108. package/dist/src/service/plugin/DefaultPluginService.js +21 -0
  109. package/dist/src/service/plugin/DefaultPluginServiceProvider.d.ts +1 -1
  110. package/dist/src/service/plugin/DefaultPluginServiceProvider.d.ts.map +1 -1
  111. package/dist/src/service/plugin/DefaultPluginServiceProvider.js +21 -0
  112. package/dist/src/service/plugin/command/PluginAddSubCommand.d.ts +17 -0
  113. package/dist/src/service/plugin/command/PluginAddSubCommand.d.ts.map +1 -0
  114. package/dist/src/service/plugin/command/PluginAddSubCommand.js +49 -0
  115. package/dist/src/service/plugin/command/PluginGroupCommand.d.ts +12 -0
  116. package/dist/src/service/plugin/command/PluginGroupCommand.d.ts.map +1 -0
  117. package/dist/src/service/plugin/command/PluginGroupCommand.js +21 -0
  118. package/dist/src/service/plugin/command/PluginListSubCommand.d.ts +12 -0
  119. package/dist/src/service/plugin/command/PluginListSubCommand.d.ts.map +1 -0
  120. package/dist/src/service/plugin/command/PluginListSubCommand.js +25 -0
  121. package/dist/src/service/plugin/command/PluginRemoveSubCommand.d.ts +17 -0
  122. package/dist/src/service/plugin/command/PluginRemoveSubCommand.d.ts.map +1 -0
  123. package/dist/src/service/plugin/command/PluginRemoveSubCommand.js +24 -0
  124. package/dist/src/service/plugin/command/PluginSearchSubCommand.d.ts +18 -0
  125. package/dist/src/service/plugin/command/PluginSearchSubCommand.d.ts.map +1 -0
  126. package/dist/src/service/plugin/command/PluginSearchSubCommand.js +34 -0
  127. package/dist/src/service/plugin/command/PluginUpgradeSubCommand.d.ts +12 -0
  128. package/dist/src/service/plugin/command/PluginUpgradeSubCommand.d.ts.map +1 -0
  129. package/dist/src/service/plugin/command/PluginUpgradeSubCommand.js +25 -0
  130. package/dist/src/service/plugin/command/getPluginId.d.ts +3 -0
  131. package/dist/src/service/plugin/command/getPluginId.d.ts.map +1 -0
  132. package/dist/src/service/plugin/command/getPluginId.js +3 -0
  133. package/dist/src/service/prettyPrinter/DefaultPrettyPrinterService.js +45 -0
  134. package/dist/src/service/prettyPrinter/PrettyPrinterServiceProvider.js +28 -0
  135. package/dist/src/service/printer/DefaultPrinterService.js +250 -0
  136. package/dist/src/service/printer/PrinterServiceProvider.js +43 -0
  137. package/dist/src/service/printer/command/DarkModeCommand.js +24 -0
  138. package/dist/src/service/printer/command/LogLevelCommand.js +41 -0
  139. package/dist/src/service/printer/command/NoColorCommand.js +24 -0
  140. package/dist/src/service/printer/command/NoHyperlinksCommand.js +21 -0
  141. package/dist/src/service/printer/terminal/Color.js +15 -0
  142. package/dist/src/service/printer/terminal/Progress.js +271 -0
  143. package/dist/src/service/printer/terminal/Spinner.js +83 -0
  144. package/dist/src/service/printer/terminal/Theme.js +26 -0
  145. package/dist/src/service/prompter/DefaultPrompterService.js +52 -0
  146. package/dist/src/service/prompter/PrompterServiceProvider.js +20 -0
  147. package/dist/src/service/prompter/command/NoPromptCommand.js +21 -0
  148. package/dist/src/service/prompter/prompt/PromptContext.js +22 -0
  149. package/dist/src/service/prompter/prompt/promptAcknowledge.js +19 -0
  150. package/dist/src/service/prompter/prompt/promptMultiSelect.js +74 -0
  151. package/dist/src/service/prompter/prompt/promptOpenUrl.js +70 -0
  152. package/dist/src/service/prompter/prompt/promptSingleSelect.js +73 -0
  153. package/dist/src/service/prompter/prompt/promptText.js +75 -0
  154. package/dist/src/service/prompter/prompt/promptToggle.js +21 -0
  155. package/dist/src/service/shutdown/DefaultShutdownService.js +16 -0
  156. package/dist/src/service/shutdown/ShutdownServiceProvider.js +60 -0
  157. package/dist/src/service/shutdown/ShutdownState.js +5 -0
  158. package/dist/src/service/syntaxHighlighter/DefaultSyntaxHighlighterService.js +54 -0
  159. package/dist/src/service/syntaxHighlighter/SyntaxHighlighterServiceProvider.js +32 -0
  160. package/dist/src/service/tableGenerator/DefaultTableGeneratorService.d.ts +3 -1
  161. package/dist/src/service/tableGenerator/DefaultTableGeneratorService.d.ts.map +1 -1
  162. package/dist/src/service/tableGenerator/DefaultTableGeneratorService.js +344 -0
  163. package/dist/src/service/tableGenerator/TableGeneratorServiceProvider.js +26 -0
  164. package/dist/src/service/treePrinter/DefaultTreePrinterService.js +35 -0
  165. package/dist/src/service/treePrinter/TreePrinterServiceProvider.js +24 -0
  166. package/dist/src/terminal/Ansi.js +23 -0
  167. package/dist/src/terminal/ImageRenderer.js +164 -0
  168. package/dist/src/terminal/KeyReader.js +13 -0
  169. package/dist/src/terminal/PngDecoder.js +115 -0
  170. package/dist/src/terminal/Styler.js +0 -0
  171. package/dist/src/terminal/Terminal.js +0 -0
  172. package/dist/src/terminal/TtyKeyReader.js +87 -0
  173. package/dist/src/terminal/TtyStyler.js +55 -0
  174. package/dist/src/terminal/TtyTerminal.js +52 -0
  175. package/dist/src/terminal/supportsHyperlinks.js +95 -0
  176. package/dist/src/util/configHelper.js +61 -0
  177. package/dist/src/util/envVarHelper.js +216 -0
  178. package/dist/src/util/helpHelper.d.ts.map +1 -1
  179. package/dist/src/util/helpHelper.js +497 -0
  180. package/dist/src/util/logger.js +81 -0
  181. package/dist/src/util/runnerHelper.js +80 -0
  182. package/package.json +2 -2
  183. package/src/api/service/core/TableGeneratorService.ts +1 -0
  184. package/src/cli/BaseCLI.ts +4 -18
  185. package/src/service/completion/CompletionServiceProvider.ts +16 -2
  186. package/src/service/completion/command/CompletionCompleteSubCommand.ts +59 -0
  187. package/src/service/completion/command/CompletionGroupCommand.ts +21 -0
  188. package/src/{command/CompletionCommand.ts → service/completion/command/CompletionIntegrationSubCommand.ts} +12 -73
  189. package/src/service/completion/shell/bash.ts +1 -1
  190. package/src/service/completion/shell/fish.ts +1 -1
  191. package/src/service/completion/shell/powershell.ts +1 -1
  192. package/src/service/completion/shell/zsh.ts +1 -1
  193. package/src/service/plugin/DefaultPluginServiceProvider.ts +2 -2
  194. package/src/service/plugin/command/PluginAddSubCommand.ts +64 -0
  195. package/src/service/plugin/command/PluginGroupCommand.ts +27 -0
  196. package/src/service/plugin/command/PluginListSubCommand.ts +33 -0
  197. package/src/service/plugin/command/PluginRemoveSubCommand.ts +32 -0
  198. package/src/service/plugin/command/PluginSearchSubCommand.ts +42 -0
  199. package/src/service/plugin/command/PluginUpgradeSubCommand.ts +36 -0
  200. package/src/service/plugin/command/getPluginId.ts +5 -0
  201. package/src/service/tableGenerator/DefaultTableGeneratorService.ts +6 -1
  202. package/src/util/helpHelper.ts +1 -2
  203. package/dist/src/command/CompletionCommand.d.ts +0 -32
  204. package/dist/src/command/CompletionCommand.d.ts.map +0 -1
  205. package/dist/src/command/PluginCommand.d.ts +0 -67
  206. package/dist/src/command/PluginCommand.d.ts.map +0 -1
  207. package/dist/tests/cli/BaseCLI.test.d.ts +0 -2
  208. package/dist/tests/cli/BaseCLI.test.d.ts.map +0 -1
  209. package/dist/tests/cli/DynamicPluginRuntimeCLI.test.d.ts +0 -2
  210. package/dist/tests/cli/DynamicPluginRuntimeCLI.test.d.ts.map +0 -1
  211. package/dist/tests/command/CompletionCommand.test.d.ts +0 -2
  212. package/dist/tests/command/CompletionCommand.test.d.ts.map +0 -1
  213. package/dist/tests/command/MultiCommandCliHelpCommand.test.d.ts +0 -2
  214. package/dist/tests/command/MultiCommandCliHelpCommand.test.d.ts.map +0 -1
  215. package/dist/tests/command/PluginCommand.test.d.ts +0 -2
  216. package/dist/tests/command/PluginCommand.test.d.ts.map +0 -1
  217. package/dist/tests/command/SingleCommandCliHelpCommand.test.d.ts +0 -2
  218. package/dist/tests/command/SingleCommandCliHelpCommand.test.d.ts.map +0 -1
  219. package/dist/tests/command/UsageCommand.test.d.ts +0 -2
  220. package/dist/tests/command/UsageCommand.test.d.ts.map +0 -1
  221. package/dist/tests/command/VersionCommand.test.d.ts +0 -2
  222. package/dist/tests/command/VersionCommand.test.d.ts.map +0 -1
  223. package/dist/tests/fixtures/CLIConfig.d.ts +0 -3
  224. package/dist/tests/fixtures/CLIConfig.d.ts.map +0 -1
  225. package/dist/tests/fixtures/Command.d.ts +0 -20
  226. package/dist/tests/fixtures/Command.d.ts.map +0 -1
  227. package/dist/tests/fixtures/CommandRegistry.d.ts +0 -4
  228. package/dist/tests/fixtures/CommandRegistry.d.ts.map +0 -1
  229. package/dist/tests/fixtures/ConfigurationServiceProvider.d.ts +0 -10
  230. package/dist/tests/fixtures/ConfigurationServiceProvider.d.ts.map +0 -1
  231. package/dist/tests/fixtures/Context.d.ts +0 -4
  232. package/dist/tests/fixtures/Context.d.ts.map +0 -1
  233. package/dist/tests/fixtures/ServiceProviderRegistry.d.ts +0 -4
  234. package/dist/tests/fixtures/ServiceProviderRegistry.d.ts.map +0 -1
  235. package/dist/tests/fixtures/StreamString.d.ts +0 -10
  236. package/dist/tests/fixtures/StreamString.d.ts.map +0 -1
  237. package/dist/tests/fixtures/prettierPluginFoo.d.ts +0 -4
  238. package/dist/tests/fixtures/prettierPluginFoo.d.ts.map +0 -1
  239. package/dist/tests/fixtures/util.d.ts +0 -8
  240. package/dist/tests/fixtures/util.d.ts.map +0 -1
  241. package/dist/tests/runtime/DefaultContext.test.d.ts +0 -2
  242. package/dist/tests/runtime/DefaultContext.test.d.ts.map +0 -1
  243. package/dist/tests/runtime/argument/ArgumentTypeGuards.test.d.ts +0 -2
  244. package/dist/tests/runtime/argument/ArgumentTypeGuards.test.d.ts.map +0 -1
  245. package/dist/tests/runtime/command/CommandTypeGuards.test.d.ts +0 -2
  246. package/dist/tests/runtime/command/CommandTypeGuards.test.d.ts.map +0 -1
  247. package/dist/tests/runtime/command/CommandValidator.test.d.ts +0 -2
  248. package/dist/tests/runtime/command/CommandValidator.test.d.ts.map +0 -1
  249. package/dist/tests/runtime/parser.test.d.ts +0 -2
  250. package/dist/tests/runtime/parser.test.d.ts.map +0 -1
  251. package/dist/tests/runtime/registry/DefaultCommandRegistry.test.d.ts +0 -2
  252. package/dist/tests/runtime/registry/DefaultCommandRegistry.test.d.ts.map +0 -1
  253. package/dist/tests/runtime/registry/DefaultServiceProviderRegistry.test.d.ts +0 -2
  254. package/dist/tests/runtime/registry/DefaultServiceProviderRegistry.test.d.ts.map +0 -1
  255. package/dist/tests/runtime/runner.test.d.ts +0 -2
  256. package/dist/tests/runtime/runner.test.d.ts.map +0 -1
  257. package/dist/tests/runtime/scanner.test.d.ts +0 -2
  258. package/dist/tests/runtime/scanner.test.d.ts.map +0 -1
  259. package/dist/tests/runtime/values/argumentValueMerge.test.d.ts +0 -2
  260. package/dist/tests/runtime/values/argumentValueMerge.test.d.ts.map +0 -1
  261. package/dist/tests/runtime/values/argumentValueValidation.test.d.ts +0 -2
  262. package/dist/tests/runtime/values/argumentValueValidation.test.d.ts.map +0 -1
  263. package/dist/tests/runtime/values/globalCommandValuePopulation.test.d.ts +0 -2
  264. package/dist/tests/runtime/values/globalCommandValuePopulation.test.d.ts.map +0 -1
  265. package/dist/tests/runtime/values/subCommandValuePopulation.test.d.ts +0 -2
  266. package/dist/tests/runtime/values/subCommandValuePopulation.test.d.ts.map +0 -1
  267. package/dist/tests/service/argumentPrompter/ArgumentPrompterServiceProvider.test.d.ts +0 -2
  268. package/dist/tests/service/argumentPrompter/ArgumentPrompterServiceProvider.test.d.ts.map +0 -1
  269. package/dist/tests/service/argumentPrompter/DefaultArgumentPrompterService.test.d.ts +0 -2
  270. package/dist/tests/service/argumentPrompter/DefaultArgumentPrompterService.test.d.ts.map +0 -1
  271. package/dist/tests/service/asciiBannerGenerator/AsciiBannerGeneratorServiceProvider.test.d.ts +0 -2
  272. package/dist/tests/service/asciiBannerGenerator/AsciiBannerGeneratorServiceProvider.test.d.ts.map +0 -1
  273. package/dist/tests/service/asciiBannerGenerator/DefaultAsciiBannerGeneratorService.test.d.ts +0 -2
  274. package/dist/tests/service/asciiBannerGenerator/DefaultAsciiBannerGeneratorService.test.d.ts.map +0 -1
  275. package/dist/tests/service/banner/BannerServiceProvider.test.d.ts +0 -2
  276. package/dist/tests/service/banner/BannerServiceProvider.test.d.ts.map +0 -1
  277. package/dist/tests/service/banner/command/NoBannerCommand.test.d.ts +0 -2
  278. package/dist/tests/service/banner/command/NoBannerCommand.test.d.ts.map +0 -1
  279. package/dist/tests/service/chiselAsciiBannerGenerator/ChiselFontAsciiBannerGeneratorService.test.d.ts +0 -2
  280. package/dist/tests/service/chiselAsciiBannerGenerator/ChiselFontAsciiBannerGeneratorService.test.d.ts.map +0 -1
  281. package/dist/tests/service/completion/CompletionServiceProvider.test.d.ts +0 -2
  282. package/dist/tests/service/completion/CompletionServiceProvider.test.d.ts.map +0 -1
  283. package/dist/tests/service/completion/DefaultCompletionService.test.d.ts +0 -2
  284. package/dist/tests/service/completion/DefaultCompletionService.test.d.ts.map +0 -1
  285. package/dist/tests/service/completion/shell/bash.test.d.ts +0 -2
  286. package/dist/tests/service/completion/shell/bash.test.d.ts.map +0 -1
  287. package/dist/tests/service/completion/shell/fish.test.d.ts +0 -2
  288. package/dist/tests/service/completion/shell/fish.test.d.ts.map +0 -1
  289. package/dist/tests/service/completion/shell/powershell.test.d.ts +0 -2
  290. package/dist/tests/service/completion/shell/powershell.test.d.ts.map +0 -1
  291. package/dist/tests/service/completion/shell/zsh.test.d.ts +0 -2
  292. package/dist/tests/service/completion/shell/zsh.test.d.ts.map +0 -1
  293. package/dist/tests/service/configuration/ConfigurationServiceProvider.test.d.ts +0 -2
  294. package/dist/tests/service/configuration/ConfigurationServiceProvider.test.d.ts.map +0 -1
  295. package/dist/tests/service/configuration/DefaultKeyValueService.test.d.ts +0 -2
  296. package/dist/tests/service/configuration/DefaultKeyValueService.test.d.ts.map +0 -1
  297. package/dist/tests/service/configuration/DefaultSecretService.test.d.ts +0 -2
  298. package/dist/tests/service/configuration/DefaultSecretService.test.d.ts.map +0 -1
  299. package/dist/tests/service/configuration/command/ConfigCommand.test.d.ts +0 -2
  300. package/dist/tests/service/configuration/command/ConfigCommand.test.d.ts.map +0 -1
  301. package/dist/tests/service/configuration/command/DumpConfigCommand.test.d.ts +0 -2
  302. package/dist/tests/service/configuration/command/DumpConfigCommand.test.d.ts.map +0 -1
  303. package/dist/tests/service/dataDumpGenerator/DataDumpGeneratorServiceProvider.test.d.ts +0 -2
  304. package/dist/tests/service/dataDumpGenerator/DataDumpGeneratorServiceProvider.test.d.ts.map +0 -1
  305. package/dist/tests/service/dataDumpGenerator/DefaultDataDumpGeneratorService.test.d.ts +0 -2
  306. package/dist/tests/service/dataDumpGenerator/DefaultDataDumpGeneratorService.test.d.ts.map +0 -1
  307. package/dist/tests/service/imagePrinter/DefaultImagePrinterService.test.d.ts +0 -2
  308. package/dist/tests/service/imagePrinter/DefaultImagePrinterService.test.d.ts.map +0 -1
  309. package/dist/tests/service/imagePrinter/ImagePrinterServiceProvider.test.d.ts +0 -2
  310. package/dist/tests/service/imagePrinter/ImagePrinterServiceProvider.test.d.ts.map +0 -1
  311. package/dist/tests/service/plugin/DefaultPluginServiceProvider.test.d.ts +0 -2
  312. package/dist/tests/service/plugin/DefaultPluginServiceProvider.test.d.ts.map +0 -1
  313. package/dist/tests/service/prettyPrinter/DefaultPrettyPrinterService.test.d.ts +0 -2
  314. package/dist/tests/service/prettyPrinter/DefaultPrettyPrinterService.test.d.ts.map +0 -1
  315. package/dist/tests/service/prettyPrinter/PrettyPrinterServiceProvider.test.d.ts +0 -2
  316. package/dist/tests/service/prettyPrinter/PrettyPrinterServiceProvider.test.d.ts.map +0 -1
  317. package/dist/tests/service/printer/DefaultPrinterService.test.d.ts +0 -2
  318. package/dist/tests/service/printer/DefaultPrinterService.test.d.ts.map +0 -1
  319. package/dist/tests/service/printer/PrinterServiceProvider.test.d.ts +0 -2
  320. package/dist/tests/service/printer/PrinterServiceProvider.test.d.ts.map +0 -1
  321. package/dist/tests/service/printer/command/DarkModeCommand.test.d.ts +0 -2
  322. package/dist/tests/service/printer/command/DarkModeCommand.test.d.ts.map +0 -1
  323. package/dist/tests/service/printer/command/LogLevelCommand.test.d.ts +0 -2
  324. package/dist/tests/service/printer/command/LogLevelCommand.test.d.ts.map +0 -1
  325. package/dist/tests/service/printer/command/NoColorCommand.test.d.ts +0 -2
  326. package/dist/tests/service/printer/command/NoColorCommand.test.d.ts.map +0 -1
  327. package/dist/tests/service/printer/command/NoHyperlinksCommand.test.d.ts +0 -2
  328. package/dist/tests/service/printer/command/NoHyperlinksCommand.test.d.ts.map +0 -1
  329. package/dist/tests/service/printer/terminal/Progress.test.d.ts +0 -2
  330. package/dist/tests/service/printer/terminal/Progress.test.d.ts.map +0 -1
  331. package/dist/tests/service/printer/terminal/Spinner.test.d.ts +0 -2
  332. package/dist/tests/service/printer/terminal/Spinner.test.d.ts.map +0 -1
  333. package/dist/tests/service/prompter/DefaultPrompterService.test.d.ts +0 -2
  334. package/dist/tests/service/prompter/DefaultPrompterService.test.d.ts.map +0 -1
  335. package/dist/tests/service/prompter/PrompterServiceProvider.test.d.ts +0 -2
  336. package/dist/tests/service/prompter/PrompterServiceProvider.test.d.ts.map +0 -1
  337. package/dist/tests/service/prompter/command/NoPromptCommand.test.d.ts +0 -2
  338. package/dist/tests/service/prompter/command/NoPromptCommand.test.d.ts.map +0 -1
  339. package/dist/tests/service/prompter/prompt/PromptContext.test.d.ts +0 -2
  340. package/dist/tests/service/prompter/prompt/PromptContext.test.d.ts.map +0 -1
  341. package/dist/tests/service/shutdown/ShutdownServiceProvider.test.d.ts +0 -2
  342. package/dist/tests/service/shutdown/ShutdownServiceProvider.test.d.ts.map +0 -1
  343. package/dist/tests/service/syntaxHighlighter/DefaultSyntaxHighlighterService.test.d.ts +0 -2
  344. package/dist/tests/service/syntaxHighlighter/DefaultSyntaxHighlighterService.test.d.ts.map +0 -1
  345. package/dist/tests/service/syntaxHighlighter/SyntaxHighlighterServiceProvider.test.d.ts +0 -2
  346. package/dist/tests/service/syntaxHighlighter/SyntaxHighlighterServiceProvider.test.d.ts.map +0 -1
  347. package/dist/tests/service/tableGenerator/DefaultTableGeneratorService.test.d.ts +0 -2
  348. package/dist/tests/service/tableGenerator/DefaultTableGeneratorService.test.d.ts.map +0 -1
  349. package/dist/tests/service/tableGenerator/TableGeneratorServiceProvider.test.d.ts +0 -2
  350. package/dist/tests/service/tableGenerator/TableGeneratorServiceProvider.test.d.ts.map +0 -1
  351. package/dist/tests/service/treePrinter/DefaultTreePrinterService.test.d.ts +0 -2
  352. package/dist/tests/service/treePrinter/DefaultTreePrinterService.test.d.ts.map +0 -1
  353. package/dist/tests/service/treePrinter/TreePrinterServiceProvider.test.d.ts +0 -2
  354. package/dist/tests/service/treePrinter/TreePrinterServiceProvider.test.d.ts.map +0 -1
  355. package/dist/tests/terminal/ImageRenderer.test.d.ts +0 -2
  356. package/dist/tests/terminal/ImageRenderer.test.d.ts.map +0 -1
  357. package/dist/tests/terminal/PngDecoder.test.d.ts +0 -2
  358. package/dist/tests/terminal/PngDecoder.test.d.ts.map +0 -1
  359. package/dist/tests/terminal/supportsHyperlinks.test.d.ts +0 -2
  360. package/dist/tests/terminal/supportsHyperlinks.test.d.ts.map +0 -1
  361. package/dist/tests/util/configHelper.test.d.ts +0 -2
  362. package/dist/tests/util/configHelper.test.d.ts.map +0 -1
  363. package/dist/tests/util/envVarHelper.test.d.ts +0 -2
  364. package/dist/tests/util/envVarHelper.test.d.ts.map +0 -1
  365. package/dist/tests/util/logger.test.d.ts +0 -2
  366. package/dist/tests/util/logger.test.d.ts.map +0 -1
  367. package/src/command/PluginCommand.ts +0 -197
@@ -0,0 +1,549 @@
1
+ import { ArgumentValueTypeName, } from "../../api/argument/ArgumentValueTypes.js";
2
+ import getLogger from "../../util/logger.js";
3
+ import argumentValueMerge from "./argumentValueMerge.js";
4
+ import { MAXIMUM_COMPLEX_OPTION_NESTING_DEPTH } from "../../api/argument/ComplexOption.js";
5
+ import { isComplexOption } from "../argument/ArgumentTypeGuards.js";
6
+ import { InvalidArgumentReason } from "../../api/RunResult.js";
7
+ import { MAXIMUM_ARGUMENT_ARRAY_SIZE } from "../../api/argument/SubCommandArgument.js";
8
+ const logger = getLogger("subCommandValuePopulation");
9
+ /**
10
+ * Parse states for parsing loop logic
11
+ */
12
+ var ParseState;
13
+ (function (ParseState) {
14
+ /**
15
+ * Initial state: expecting either an {@link Option} argument (`--x`, `-x`, `--x=y`, `-x=y`) or {@link Positional} value next.
16
+ */
17
+ ParseState[ParseState["EMPTY"] = 0] = "EMPTY";
18
+ /**
19
+ * Error while parsing.
20
+ */
21
+ ParseState[ParseState["ERROR"] = 1] = "ERROR";
22
+ /**
23
+ * The argument was not used.
24
+ */
25
+ ParseState[ParseState["UNUSED"] = 2] = "UNUSED";
26
+ /**
27
+ * Found an {@link Option} name, expecting an {@link Option} value next.
28
+ */
29
+ ParseState[ParseState["OPTION_VALUE_EXPECTED"] = 3] = "OPTION_VALUE_EXPECTED";
30
+ })(ParseState || (ParseState = {}));
31
+ /**
32
+ * Context container for the state of the parsing loop.
33
+ */
34
+ class ParseContext {
35
+ /**
36
+ * The {@link SubCommand} for which args are being parsed.
37
+ */
38
+ subCommand;
39
+ /**
40
+ * The current populated values for the sub-command.
41
+ */
42
+ populatedArgumentValues;
43
+ /**
44
+ * Current parse state.
45
+ */
46
+ state;
47
+ /**
48
+ * If {@link state} = {@link ParseState.ERROR} this will be populated with the details.
49
+ */
50
+ invalidArgument;
51
+ /**
52
+ * An array of either option names or indices used to navigate through the {@link populatedArgumentValues} when
53
+ * setting a value for the {@link currentOption}.
54
+ */
55
+ currentOptionPath;
56
+ /**
57
+ * An optional reference to the current {@link Option} being addressed when {@link state} = {@link ParseState.OPTION_VALUE_EXPECTED}.
58
+ */
59
+ currentOption;
60
+ /**
61
+ * Current index of {@link Positional} defined for the current {@link SubCommand} being passed
62
+ * which will be populated with a positional value if found.
63
+ */
64
+ currentPositionalIndex;
65
+ /**
66
+ * Use to store lazily created map of option paths e.g. --alpha.b.g and -a.b.gamma for {@link ComplexOption} or {@link Option} instances.
67
+ */
68
+ optionLookupMapsByPath;
69
+ /**
70
+ * Use to store map of root {@link ComplexOption} or {@link Option} instances by name.
71
+ */
72
+ rootOptionsByName;
73
+ /**
74
+ * Use to store map of root {@link ComplexOption} or {@link Option} instances by short alias.
75
+ */
76
+ rootOptionsByAlias;
77
+ /**
78
+ * Create a new instance with {@link state} = {@link ParseState.EMPTY} for the specified {@link SubCommand}.
79
+ *
80
+ * @param subCommand the {@link SubCommand} for which args are being parsed.
81
+ */
82
+ constructor(subCommand) {
83
+ this.subCommand = subCommand;
84
+ this.state = ParseState.EMPTY;
85
+ this.populatedArgumentValues = {};
86
+ this.currentPositionalIndex = 0;
87
+ this.optionLookupMapsByPath = new Map();
88
+ this.rootOptionsByName = new Map();
89
+ this.rootOptionsByAlias = new Map();
90
+ subCommand.options.forEach((option) => {
91
+ this.rootOptionsByName.set(option.name, option);
92
+ if (option.shortAlias) {
93
+ this.rootOptionsByAlias.set(option.shortAlias, option);
94
+ }
95
+ });
96
+ }
97
+ /**
98
+ * Attempt to parse the {@link Option} path specified by the provided option argument.
99
+ *
100
+ * NOTE: the provided path could:
101
+ *
102
+ * * be either a reference to a simple option or a property on a nested complex option: `foo` or `alpha.beta.gamma.delta`
103
+ * * include either the option names or short aliases may be specified: `alpha.b.gamma.d`
104
+ * * include array indices e.g. `alpha[0].beta.gamma[1].delta`
105
+ *
106
+ * @param optionPath the option path argument to parse.
107
+ *
108
+ * @return `true` if successful, which means either:
109
+ * 1. the {@link state} will be set to {@link ParseState.OPTION_VALUE_EXPECTED} and the {@link currentOptionPath} and {@link currentOption} will be populated OR
110
+ * 2. the option path was not recognised as an option for the current sub-command.
111
+ * If `false` the {@link state} will be set to
112
+ * {@link ParseState.ERROR} and {@link invalidArgument} will be populated. This will be the case if the specified option path was initially
113
+ * found to be referring to a complex property for the current sub-command but parsing the entire path failed either due to an invalid expression
114
+ * or an unknown property.
115
+ */
116
+ #parseOptionPath(optionPath) {
117
+ logger.debug("Parsing option path: %s", optionPath);
118
+ this.currentOptionPath = undefined;
119
+ this.currentOption = undefined;
120
+ // split up the path into elements
121
+ const complexPathElements = optionPath.split(".", MAXIMUM_COMPLEX_OPTION_NESTING_DEPTH + 1);
122
+ // check nesting depth
123
+ if (complexPathElements.length > MAXIMUM_COMPLEX_OPTION_NESTING_DEPTH) {
124
+ this.invalidArgument = {
125
+ name: optionPath,
126
+ reason: InvalidArgumentReason.NESTING_DEPTH_EXCEEDED,
127
+ };
128
+ this.state = ParseState.ERROR;
129
+ return false;
130
+ }
131
+ const complexAndArrayPathElements = [];
132
+ let option = undefined;
133
+ let currentValue = this.populatedArgumentValues;
134
+ for (let i = 0; i < complexPathElements.length; i++) {
135
+ let arrayIndexString;
136
+ let complexPathElement = complexPathElements[i];
137
+ // look for array index
138
+ if (complexPathElement.endsWith("]")) {
139
+ [complexPathElement, arrayIndexString] = complexPathElement
140
+ .slice(0, complexPathElement.length - 1)
141
+ .split("[");
142
+ }
143
+ let lookupPath = this.subCommand.name;
144
+ // root option navigation
145
+ if (i === 0) {
146
+ if (complexPathElement.startsWith("--")) {
147
+ complexPathElement = complexPathElement.slice(2);
148
+ option = this.rootOptionsByName.get(complexPathElement);
149
+ }
150
+ else {
151
+ complexPathElement = complexPathElement.slice(1);
152
+ // ignore if illegal syntax of `-more_than_one_letter`
153
+ if (complexPathElement.length > 1) {
154
+ this.state = ParseState.UNUSED;
155
+ return false;
156
+ }
157
+ option = this.rootOptionsByAlias.get(complexPathElement);
158
+ }
159
+ // if path doesn't refer to an option don't use it
160
+ if (option === undefined) {
161
+ return true;
162
+ }
163
+ // if we did find an option make sure we using the name and not the alias
164
+ complexPathElement = option.name;
165
+ } // complex option property navigation
166
+ else {
167
+ lookupPath = `${lookupPath}${option.name}`;
168
+ // lazy creation of nested option paths to options
169
+ if (!this.optionLookupMapsByPath.has(lookupPath)) {
170
+ const properties = option.properties;
171
+ if (properties === undefined) {
172
+ this.invalidArgument = {
173
+ name: optionPath,
174
+ reason: InvalidArgumentReason.UNKNOWN_PROPERTY,
175
+ };
176
+ this.state = ParseState.ERROR;
177
+ return false;
178
+ }
179
+ const lookupMap = new Map();
180
+ properties.forEach((option) => {
181
+ lookupMap.set(option.name, option);
182
+ if (option.shortAlias) {
183
+ lookupMap.set(option.shortAlias, option);
184
+ }
185
+ });
186
+ this.optionLookupMapsByPath.set(lookupPath, lookupMap);
187
+ }
188
+ option = this.optionLookupMapsByPath.get(lookupPath).get(complexPathElement);
189
+ // now we are parsing properties of complex options it is an error if we cannot match an option name or alias
190
+ if (option === undefined) {
191
+ this.invalidArgument = {
192
+ name: optionPath,
193
+ reason: InvalidArgumentReason.UNKNOWN_PROPERTY,
194
+ };
195
+ this.state = ParseState.ERROR;
196
+ return false;
197
+ }
198
+ // ensure we convert to option name if lookup was via option alias
199
+ complexPathElement = option.name;
200
+ }
201
+ // check index size
202
+ let arrayIndex;
203
+ if (arrayIndexString !== undefined) {
204
+ const parsedArrayIndex = parseInt(arrayIndexString);
205
+ if (Number.isInteger(parsedArrayIndex)) {
206
+ if (parsedArrayIndex > MAXIMUM_ARGUMENT_ARRAY_SIZE) {
207
+ this.invalidArgument = {
208
+ argument: option,
209
+ name: option.name,
210
+ reason: InvalidArgumentReason.ARRAY_SIZE_EXCEEDED,
211
+ };
212
+ this.state = ParseState.ERROR;
213
+ return false;
214
+ }
215
+ arrayIndex = parsedArrayIndex;
216
+ }
217
+ }
218
+ // check for indexing when not allowed
219
+ if (!option.isArray && arrayIndex !== undefined) {
220
+ this.invalidArgument = {
221
+ argument: option,
222
+ name: optionPath,
223
+ reason: InvalidArgumentReason.ILLEGAL_MULTIPLE_VALUES,
224
+ };
225
+ this.state = ParseState.ERROR;
226
+ return false;
227
+ }
228
+ if (currentValue[complexPathElement] === undefined) {
229
+ // ensure we have a placeholder value
230
+ if (option.isArray) {
231
+ currentValue = currentValue[complexPathElement] = [];
232
+ if (isComplexOption(option)) {
233
+ // if we are retrieving a property by name only use the last entry in the array by default
234
+ // (this is the scenario when array indices are implicit)
235
+ let index = 0;
236
+ if (arrayIndex !== undefined) {
237
+ index = arrayIndex;
238
+ }
239
+ currentValue = currentValue[index] = {};
240
+ }
241
+ }
242
+ else if (isComplexOption(option)) {
243
+ currentValue = currentValue[complexPathElement] = {};
244
+ }
245
+ }
246
+ else {
247
+ currentValue = currentValue[complexPathElement];
248
+ if (Array.isArray(currentValue)) {
249
+ // if we are retrieving a property by name only use the last entry in the array by default
250
+ // (this is the scenario when array indices are implicit)
251
+ let index = currentValue.length - 1;
252
+ if (arrayIndex !== undefined) {
253
+ index = arrayIndex;
254
+ }
255
+ if (currentValue[index] === undefined && isComplexOption(option)) {
256
+ // ensure we have a placeholder value
257
+ currentValue = currentValue[index] = {};
258
+ }
259
+ else {
260
+ currentValue = currentValue[index];
261
+ }
262
+ }
263
+ }
264
+ // add to the path elements
265
+ complexAndArrayPathElements.push(complexPathElement);
266
+ if (arrayIndex !== undefined) {
267
+ complexAndArrayPathElements.push(arrayIndex);
268
+ }
269
+ }
270
+ // if path doesn't refer to an option don't use it
271
+ if (option === undefined) {
272
+ return true;
273
+ }
274
+ // check if path ends up referring to a non-primitive
275
+ if (isComplexOption(option)) {
276
+ this.invalidArgument = {
277
+ argument: option,
278
+ name: option.name,
279
+ reason: InvalidArgumentReason.OPTION_IS_COMPLEX,
280
+ };
281
+ this.state = ParseState.ERROR;
282
+ return false;
283
+ }
284
+ this.currentOptionPath = complexAndArrayPathElements;
285
+ this.currentOption = option;
286
+ this.state = ParseState.OPTION_VALUE_EXPECTED;
287
+ return true;
288
+ }
289
+ /**
290
+ * Attempt to set the value for the current {@link Option}.
291
+ *
292
+ * @param value the value to attempt to set.
293
+ *
294
+ * @return `false` if there is a problem populating the value, in which case the {@link state} will be set to
295
+ * {@link ParseState.ERROR} and {@link invalidArgument} will be populated.
296
+ */
297
+ setOptionValue(value) {
298
+ let optionValue = this.populatedArgumentValues;
299
+ const optionPath = this.currentOptionPath;
300
+ // traverse the current populated values using the validated option path elements
301
+ for (let i = 0; i < optionPath.length; i++) {
302
+ const pathElement = optionPath[i];
303
+ // if on last path element, set the value
304
+ if (i === optionPath.length - 1) {
305
+ if (typeof pathElement === "string") {
306
+ const currentValue = optionValue[pathElement];
307
+ // if we haven't populated the argument value before...
308
+ if (currentValue === undefined) {
309
+ optionValue[pathElement] = value;
310
+ } // if we have already populated the argument value as an array...
311
+ else if (Array.isArray(currentValue)) {
312
+ if (currentValue.length === MAXIMUM_ARGUMENT_ARRAY_SIZE) {
313
+ this.invalidArgument = {
314
+ argument: this.currentOption,
315
+ name: this.currentOption.name,
316
+ reason: InvalidArgumentReason.ARRAY_SIZE_EXCEEDED,
317
+ };
318
+ this.state = ParseState.ERROR;
319
+ return false;
320
+ }
321
+ // push the new value
322
+ currentValue.push(value);
323
+ } // else the value to add would make an array where it is not allowed
324
+ else {
325
+ this.invalidArgument = {
326
+ argument: this.currentOption,
327
+ name: this.currentOption.name,
328
+ reason: InvalidArgumentReason.ILLEGAL_MULTIPLE_VALUES,
329
+ };
330
+ this.state = ParseState.ERROR;
331
+ return false;
332
+ }
333
+ }
334
+ else {
335
+ // set the new value on the array
336
+ optionValue[pathElement] = value;
337
+ }
338
+ } // otherwise continue to navigate the path
339
+ else {
340
+ if (typeof pathElement === "string") {
341
+ if (Array.isArray(optionValue)) {
342
+ optionValue = optionValue[optionValue.length - 1][pathElement];
343
+ }
344
+ else {
345
+ optionValue = optionValue[pathElement];
346
+ }
347
+ }
348
+ else {
349
+ optionValue = optionValue[pathElement];
350
+ }
351
+ }
352
+ }
353
+ // Update the state
354
+ this.currentOption = undefined;
355
+ this.currentOptionPath = undefined;
356
+ this.state = ParseState.EMPTY;
357
+ return true;
358
+ }
359
+ /**
360
+ * Attempt to set the value for the current {@link Positional}.
361
+ * If there is a problem populating the value the {@link state} will be set to
362
+ * {@link ParseState.ERROR} and {@link invalidArgument} will be populated.
363
+ *
364
+ * @param value the value to attempt to set.
365
+ */
366
+ setPositionalValue(value) {
367
+ const positional = this.subCommand.positionals[this.currentPositionalIndex];
368
+ const currentValue = this.populatedArgumentValues[positional.name];
369
+ // if we haven't populated the argument value before...
370
+ if (currentValue === undefined) {
371
+ if (positional.isVarargMultiple) {
372
+ this.populatedArgumentValues[positional.name] = [value];
373
+ }
374
+ else {
375
+ this.populatedArgumentValues[positional.name] = value;
376
+ }
377
+ } // if we have already populated the argument value as an array...
378
+ else if (Array.isArray(currentValue)) {
379
+ if (currentValue.length === MAXIMUM_ARGUMENT_ARRAY_SIZE) {
380
+ this.invalidArgument = {
381
+ argument: positional,
382
+ name: positional.name,
383
+ reason: InvalidArgumentReason.ARRAY_SIZE_EXCEEDED,
384
+ };
385
+ this.state = ParseState.ERROR;
386
+ return false;
387
+ }
388
+ this.populatedArgumentValues[positional.name] = [
389
+ ...currentValue,
390
+ value,
391
+ ];
392
+ }
393
+ // Update the state
394
+ if (!positional.isVarargMultiple) {
395
+ this.currentPositionalIndex += 1;
396
+ }
397
+ this.state = ParseState.EMPTY;
398
+ return true;
399
+ }
400
+ /**
401
+ * Attempt to parse the next argument and update the state of this context based on the result.
402
+ *
403
+ * @param potentialArg the argument to parse
404
+ */
405
+ parse(potentialArg) {
406
+ if (this.state === ParseState.OPTION_VALUE_EXPECTED) {
407
+ // If the potential arg is a potential value, check if it is a non-boolean value
408
+ // and if so, see if the current option is boolean. In this scenario prefer to
409
+ // assume the boolean value was implicitly `true` and treat
410
+ // the potential arg as a following option arg or positional value
411
+ if (potentialArg !== "true" &&
412
+ potentialArg !== "false" &&
413
+ this.currentOption.type === ArgumentValueTypeName.BOOLEAN) {
414
+ // Set the value to implicit value of true and return ony error.
415
+ if (!this.setOptionValue("true")) {
416
+ return;
417
+ }
418
+ // Because of the implicit value, the current potential arg is either a new option arg or positional value
419
+ // and it will be processed in the `ParseState.EMPTY` logic further below.
420
+ }
421
+ else {
422
+ // Treat the potential arg as the value for the current option and set the value.
423
+ this.setOptionValue(potentialArg);
424
+ // Return regardless.
425
+ return;
426
+ }
427
+ }
428
+ // Now either expecting option argument (`--x`, `-x`, `--x=y`, `-x=y`, `--x.z[1]`, `--x.z[1]=y` etc.) or positional value next.
429
+ if (this.state === ParseState.EMPTY) {
430
+ // Look for an option argument first.
431
+ if (potentialArg.startsWith("-")) {
432
+ let potentialOptionPath = potentialArg;
433
+ let potentialOptionValue;
434
+ // check for option AND value
435
+ if (potentialOptionPath.includes("=")) {
436
+ [potentialOptionPath, potentialOptionValue] = potentialOptionPath.split(/=(.*)/);
437
+ // check for illegal syntax e.g. --optionName=
438
+ if (potentialOptionValue === "") {
439
+ this.state = ParseState.ERROR;
440
+ if (potentialOptionPath.startsWith("--")) {
441
+ potentialOptionPath = potentialOptionPath.slice(2);
442
+ }
443
+ else {
444
+ potentialOptionPath = potentialOptionPath.slice(1);
445
+ }
446
+ this.invalidArgument = {
447
+ reason: InvalidArgumentReason.MISSING_VALUE,
448
+ name: potentialOptionPath,
449
+ };
450
+ return;
451
+ }
452
+ }
453
+ // Parse the option path and return if it failed
454
+ if (!this.#parseOptionPath(potentialOptionPath)) {
455
+ return;
456
+ }
457
+ // Check if the option path did refer to an option
458
+ if (this.currentOption !== undefined) {
459
+ // try to set the value if we have one
460
+ if (potentialOptionValue !== undefined) {
461
+ // set the value
462
+ this.setOptionValue(potentialOptionValue);
463
+ // return regardless
464
+ return;
465
+ }
466
+ // otherwise we just got the option and the next arg will be a value
467
+ return;
468
+ }
469
+ // As no option was found, in the logic below, the potential arg will be either assigned as a positional value or returned as unused.
470
+ }
471
+ // Not an option argument so try as positional value.
472
+ if (this.currentPositionalIndex < this.subCommand.positionals.length) {
473
+ // Treat the potential arg as the value for the current positional and set the value.
474
+ this.setPositionalValue(potentialArg);
475
+ // Return regardless of success or not.
476
+ return;
477
+ }
478
+ // If neither option argument nor positional value so treat as unused.
479
+ this.state = ParseState.UNUSED;
480
+ return;
481
+ }
482
+ throw new Error(`Unexpected parse state: ${this.state}`);
483
+ }
484
+ }
485
+ /**
486
+ * Populate {@link PopulatedArgumentValues} for the provided {@link SubCommand} using the provided potential args.
487
+ *
488
+ * @param subCommand the {@link SubCommand} for which {@link PopulatedArgumentValues} values should be populated.
489
+ * @param potentialArgs the potential args to use for population.
490
+ * @param defaultValues optional default {@link ArgumentValues} to use for population before parsing the provided arguments.
491
+ */
492
+ export default function populateSubCommandValues(subCommand, potentialArgs, defaultValues) {
493
+ logger.debug(() => {
494
+ const message = `Populating values for sub-command: '${subCommand.name}' using potential args: ${potentialArgs.join(" ")}`;
495
+ if (defaultValues !== undefined) {
496
+ return `${message} and configured values: ${JSON.stringify(defaultValues)}`;
497
+ }
498
+ return message;
499
+ });
500
+ const parseContext = new ParseContext(subCommand);
501
+ const unusedArgs = [];
502
+ for (let i = 0; i < potentialArgs.length; i++) {
503
+ const potentialArg = potentialArgs[i];
504
+ // parse the next arg
505
+ parseContext.parse(potentialArg);
506
+ // check if we had a parsing error, record the error, flush the remaining args and stop parsing
507
+ if (parseContext.state === ParseState.ERROR) {
508
+ if (i + 1 < potentialArgs.length) {
509
+ unusedArgs.push(...potentialArgs.slice(i + 1));
510
+ }
511
+ break;
512
+ }
513
+ // check if the arg was unused, save it and reset state for the next arg
514
+ if (parseContext.state === ParseState.UNUSED) {
515
+ unusedArgs.push(potentialArg);
516
+ parseContext.state = ParseState.EMPTY;
517
+ }
518
+ }
519
+ // Check if the last arg specified an option but no value
520
+ if (parseContext.state === ParseState.OPTION_VALUE_EXPECTED) {
521
+ // special case if the last arg was for a boolean option where the value was implicitly `true`
522
+ if (parseContext.currentOption.type === ArgumentValueTypeName.BOOLEAN) {
523
+ parseContext.setOptionValue("true");
524
+ }
525
+ else {
526
+ parseContext.invalidArgument = {
527
+ argument: parseContext.currentOption,
528
+ reason: InvalidArgumentReason.MISSING_VALUE,
529
+ name: potentialArgs[potentialArgs.length - 1],
530
+ };
531
+ }
532
+ }
533
+ if (parseContext.invalidArgument) {
534
+ return {
535
+ populatedArgumentValues: parseContext.populatedArgumentValues,
536
+ unusedArgs: unusedArgs,
537
+ invalidArgument: parseContext.invalidArgument,
538
+ };
539
+ }
540
+ // merge the configured values with the parsed values
541
+ let populatedArgumentValues = parseContext.populatedArgumentValues;
542
+ if (defaultValues) {
543
+ populatedArgumentValues = argumentValueMerge(populatedArgumentValues, defaultValues);
544
+ }
545
+ return {
546
+ populatedArgumentValues,
547
+ unusedArgs: unusedArgs,
548
+ };
549
+ }
@@ -0,0 +1,19 @@
1
+ import { ARGUMENT_PROMPTER_SERVICE_ID } from "../../api/service/core/ArgumentPrompterService.js";
2
+ export default class ArgumentPrompterServiceProvider {
3
+ serviceId = ARGUMENT_PROMPTER_SERVICE_ID;
4
+ servicePriority;
5
+ argumentPrompterService;
6
+ constructor(servicePriority, argumentPrompterService) {
7
+ this.servicePriority = servicePriority;
8
+ this.argumentPrompterService = argumentPrompterService;
9
+ }
10
+ getServiceInfo(_cliConfig) {
11
+ return Promise.resolve({
12
+ service: this.argumentPrompterService,
13
+ commands: [],
14
+ });
15
+ }
16
+ initService(_context) {
17
+ return Promise.resolve();
18
+ }
19
+ }