@bemoje/cli 0.0.14 → 0.0.16

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