@bemoje/cli 0.0.4 → 0.0.6

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 (698) hide show
  1. package/.eslintrc.json +5 -0
  2. package/.swcrc +32 -0
  3. package/dist/cjs/_example/bFindIn.js +189 -0
  4. package/dist/cjs/_example/bFindIn.js.map +1 -0
  5. package/dist/cjs/arg/ArgumentBuilder.js +45 -0
  6. package/dist/cjs/arg/ArgumentBuilder.js.map +1 -0
  7. package/dist/cjs/arg/ArgumentParserSelector.js +15 -0
  8. package/dist/cjs/arg/ArgumentParserSelector.js.map +1 -0
  9. package/dist/cjs/arg/ArgumentReader.js +38 -0
  10. package/dist/cjs/arg/ArgumentReader.js.map +1 -0
  11. package/dist/cjs/arg/ArgumentValidatorSelector.js +16 -0
  12. package/dist/cjs/arg/ArgumentValidatorSelector.js.map +1 -0
  13. package/dist/cjs/cmd/CommandBuilder.js +1080 -0
  14. package/dist/cjs/cmd/CommandBuilder.js.map +1 -0
  15. package/dist/cjs/cmd/CommandBuilderMetaData.js +44 -0
  16. package/dist/cjs/cmd/CommandBuilderMetaData.js.map +1 -0
  17. package/dist/cjs/cmd/CommandFeatureSelector.js +112 -0
  18. package/dist/cjs/cmd/CommandFeatureSelector.js.map +1 -0
  19. package/dist/cjs/cmd/DefaultHelpConfig.js +141 -0
  20. package/dist/cjs/cmd/DefaultHelpConfig.js.map +1 -0
  21. package/dist/cjs/cmd/asdas.js +27 -0
  22. package/dist/cjs/cmd/asdas.js.map +1 -0
  23. package/dist/cjs/core/OutputManager.js +99 -0
  24. package/dist/cjs/core/OutputManager.js.map +1 -0
  25. package/dist/cjs/core/ParserSelector.js +36 -0
  26. package/dist/cjs/core/ParserSelector.js.map +1 -0
  27. package/dist/cjs/core/ValidatorSelector.js +36 -0
  28. package/dist/cjs/core/ValidatorSelector.js.map +1 -0
  29. package/dist/cjs/core/splitCombinedArgvShorts.js +15 -0
  30. package/dist/cjs/core/splitCombinedArgvShorts.js.map +1 -0
  31. package/dist/cjs/db/AbstractJsonFileSection.js +190 -0
  32. package/dist/cjs/db/AbstractJsonFileSection.js.map +1 -0
  33. package/dist/cjs/db/AppDataSection.js +48 -0
  34. package/dist/cjs/db/AppDataSection.js.map +1 -0
  35. package/dist/cjs/db/ConfigSection.js +71 -0
  36. package/dist/cjs/db/ConfigSection.js.map +1 -0
  37. package/dist/cjs/db/JsonFile.js +55 -0
  38. package/dist/cjs/db/JsonFile.js.map +1 -0
  39. package/dist/cjs/db/PresetsSection.js +92 -0
  40. package/dist/cjs/db/PresetsSection.js.map +1 -0
  41. package/dist/cjs/index.js +119 -0
  42. package/dist/cjs/index.js.map +1 -0
  43. package/dist/cjs/opt/OptionArgumentParserSelector.js +16 -0
  44. package/dist/cjs/opt/OptionArgumentParserSelector.js.map +1 -0
  45. package/dist/cjs/opt/OptionArgumentValidatorSelector.js +19 -0
  46. package/dist/cjs/opt/OptionArgumentValidatorSelector.js.map +1 -0
  47. package/dist/cjs/opt/OptionBuilder.js +88 -0
  48. package/dist/cjs/opt/OptionBuilder.js.map +1 -0
  49. package/dist/cjs/opt/OptionHelpers.js +57 -0
  50. package/dist/cjs/opt/OptionHelpers.js.map +1 -0
  51. package/dist/cjs/opt/OptionReader.js +66 -0
  52. package/dist/cjs/opt/OptionReader.js.map +1 -0
  53. package/dist/cjs/types/IConfig.js +3 -0
  54. package/dist/cjs/types/IConfig.js.map +1 -0
  55. package/dist/cjs/types/IPreset.js +3 -0
  56. package/dist/cjs/types/IPreset.js.map +1 -0
  57. package/dist/cjs/util/array/arrLast.js +21 -0
  58. package/dist/cjs/util/array/arrLast.js.map +1 -0
  59. package/dist/cjs/util/array/arrSome.js +26 -0
  60. package/dist/cjs/util/array/arrSome.js.map +1 -0
  61. package/dist/cjs/util/array/types/ArrayPredicate.js +3 -0
  62. package/dist/cjs/util/array/types/ArrayPredicate.js.map +1 -0
  63. package/dist/cjs/util/db/JsonDB.js +145 -0
  64. package/dist/cjs/util/db/JsonDB.js.map +1 -0
  65. package/dist/cjs/util/errors/ErrorParser.js +164 -0
  66. package/dist/cjs/util/errors/ErrorParser.js.map +1 -0
  67. package/dist/cjs/util/fs/promptUserEditInTextEditor/IGetUserInputFromEditorOptions.js +3 -0
  68. package/dist/cjs/util/fs/promptUserEditInTextEditor/IGetUserInputFromEditorOptions.js.map +1 -0
  69. package/dist/cjs/util/fs/promptUserEditInTextEditor/promptUserEditInTextEditorSync.js +32 -0
  70. package/dist/cjs/util/fs/promptUserEditInTextEditor/promptUserEditInTextEditorSync.js.map +1 -0
  71. package/dist/cjs/util/fs/promptUserEditInTextEditor/promptUserEditJsonInTextEditorSync.js +25 -0
  72. package/dist/cjs/util/fs/promptUserEditInTextEditor/promptUserEditJsonInTextEditorSync.js.map +1 -0
  73. package/dist/cjs/util/fs/readFile/readFileSafeSync.js +28 -0
  74. package/dist/cjs/util/fs/readFile/readFileSafeSync.js.map +1 -0
  75. package/dist/cjs/util/fs/readFile/readFileSync.js +20 -0
  76. package/dist/cjs/util/fs/readFile/readFileSync.js.map +1 -0
  77. package/dist/cjs/util/fs/readJsonFile/readJsonFileSafeSync.js +24 -0
  78. package/dist/cjs/util/fs/readJsonFile/readJsonFileSafeSync.js.map +1 -0
  79. package/dist/cjs/util/fs/removeFile/removeFile.js +6 -0
  80. package/dist/cjs/util/fs/removeFile/removeFile.js.map +1 -0
  81. package/dist/cjs/util/fs/tempFile/tempFileSync.js +28 -0
  82. package/dist/cjs/util/fs/tempFile/tempFileSync.js.map +1 -0
  83. package/dist/cjs/util/fs/types/IReadJsonFileOptions.js +3 -0
  84. package/dist/cjs/util/fs/types/IReadJsonFileOptions.js.map +1 -0
  85. package/dist/cjs/util/fs/writeFile/writeFileSafeSync.js +6 -0
  86. package/dist/cjs/util/fs/writeFile/writeFileSafeSync.js.map +1 -0
  87. package/dist/cjs/util/fs/writeFile/writeFileSync.js +6 -0
  88. package/dist/cjs/util/fs/writeFile/writeFileSync.js.map +1 -0
  89. package/dist/cjs/util/fs/writeJsonFile/writeJsonFileSafe.js +6 -0
  90. package/dist/cjs/util/fs/writeJsonFile/writeJsonFileSafe.js.map +1 -0
  91. package/dist/cjs/util/function/MethodDisabler.js +94 -0
  92. package/dist/cjs/util/function/MethodDisabler.js.map +1 -0
  93. package/dist/cjs/util/function/funSetName.js +21 -0
  94. package/dist/cjs/util/function/funSetName.js.map +1 -0
  95. package/dist/cjs/util/node/execInherit.js +19 -0
  96. package/dist/cjs/util/node/execInherit.js.map +1 -0
  97. package/dist/cjs/util/node/formatTableForTerminal.js +21 -0
  98. package/dist/cjs/util/node/formatTableForTerminal.js.map +1 -0
  99. package/dist/cjs/util/object/arrAssign.js +6 -0
  100. package/dist/cjs/util/object/arrAssign.js.map +1 -0
  101. package/dist/cjs/util/object/createArrayMerger.js +20 -0
  102. package/dist/cjs/util/object/createArrayMerger.js.map +1 -0
  103. package/dist/cjs/util/object/createObjectMerger.js +20 -0
  104. package/dist/cjs/util/object/createObjectMerger.js.map +1 -0
  105. package/dist/cjs/util/object/objAssign.js +6 -0
  106. package/dist/cjs/util/object/objAssign.js.map +1 -0
  107. package/dist/cjs/util/object/objUpdatePropertyDescriptors.js +28 -0
  108. package/dist/cjs/util/object/objUpdatePropertyDescriptors.js.map +1 -0
  109. package/dist/cjs/util/object/realizeLazyProperty.js +14 -0
  110. package/dist/cjs/util/object/realizeLazyProperty.js.map +1 -0
  111. package/dist/cjs/util/object/setNonEnumerable.js +25 -0
  112. package/dist/cjs/util/object/setNonEnumerable.js.map +1 -0
  113. package/dist/cjs/util/os/defaultOpenInEditorCommand.js +18 -0
  114. package/dist/cjs/util/os/defaultOpenInEditorCommand.js.map +1 -0
  115. package/dist/cjs/util/os/isOSX.js +13 -0
  116. package/dist/cjs/util/os/isOSX.js.map +1 -0
  117. package/dist/cjs/util/os/isVsCodeInstalled.js +19 -0
  118. package/dist/cjs/util/os/isVsCodeInstalled.js.map +1 -0
  119. package/dist/cjs/util/os/isWindows.js +16 -0
  120. package/dist/cjs/util/os/isWindows.js.map +1 -0
  121. package/dist/cjs/util/path/getTempDataPath.js +20 -0
  122. package/dist/cjs/util/path/getTempDataPath.js.map +1 -0
  123. package/dist/cjs/util/regex/regexEscapeString.js +18 -0
  124. package/dist/cjs/util/regex/regexEscapeString.js.map +1 -0
  125. package/dist/cjs/util/string/strEnsureStartsWith.js +19 -0
  126. package/dist/cjs/util/string/strEnsureStartsWith.js.map +1 -0
  127. package/dist/cjs/util/string/strFirstCharToUpperCase.js +16 -0
  128. package/dist/cjs/util/string/strFirstCharToUpperCase.js.map +1 -0
  129. package/dist/cjs/util/string/strIsLowerCase.js +18 -0
  130. package/dist/cjs/util/string/strIsLowerCase.js.map +1 -0
  131. package/dist/cjs/util/string/strIsUpperCase.js +18 -0
  132. package/dist/cjs/util/string/strIsUpperCase.js.map +1 -0
  133. package/dist/cjs/util/string/strSplitCamelCase.js +55 -0
  134. package/dist/cjs/util/string/strSplitCamelCase.js.map +1 -0
  135. package/dist/cjs/util/string-parsers/createBooleanParser.js +21 -0
  136. package/dist/cjs/util/string-parsers/createBooleanParser.js.map +1 -0
  137. package/dist/cjs/util/string-parsers/createTypedListParser.js +22 -0
  138. package/dist/cjs/util/string-parsers/createTypedListParser.js.map +1 -0
  139. package/dist/cjs/util/string-parsers/parseBoolean.js +15 -0
  140. package/dist/cjs/util/string-parsers/parseBoolean.js.map +1 -0
  141. package/dist/cjs/util/string-parsers/parseInteger.js +17 -0
  142. package/dist/cjs/util/string-parsers/parseInteger.js.map +1 -0
  143. package/dist/cjs/util/string-parsers/parseNumber.js +13 -0
  144. package/dist/cjs/util/string-parsers/parseNumber.js.map +1 -0
  145. package/dist/cjs/util/string-parsers/parseString.js +8 -0
  146. package/dist/cjs/util/string-parsers/parseString.js.map +1 -0
  147. package/dist/cjs/util/types/Any.js +3 -0
  148. package/dist/cjs/util/types/Any.js.map +1 -0
  149. package/dist/cjs/util/types/DeepArray.js +3 -0
  150. package/dist/cjs/util/types/DeepArray.js.map +1 -0
  151. package/dist/cjs/util/types/DeepObject.js +3 -0
  152. package/dist/cjs/util/types/DeepObject.js.map +1 -0
  153. package/dist/cjs/util/types/JsonArray.js +3 -0
  154. package/dist/cjs/util/types/JsonArray.js.map +1 -0
  155. package/dist/cjs/util/types/JsonDefinedPrimitive.js +6 -0
  156. package/dist/cjs/util/types/JsonDefinedPrimitive.js.map +1 -0
  157. package/dist/cjs/util/types/JsonObject.js +3 -0
  158. package/dist/cjs/util/types/JsonObject.js.map +1 -0
  159. package/dist/cjs/util/types/JsonRawPrimitive.js +3 -0
  160. package/dist/cjs/util/types/JsonRawPrimitive.js.map +1 -0
  161. package/dist/cjs/util/types/JsonValue.js +3 -0
  162. package/dist/cjs/util/types/JsonValue.js.map +1 -0
  163. package/dist/cjs/util/types/ObjectKey.js +3 -0
  164. package/dist/cjs/util/types/ObjectKey.js.map +1 -0
  165. package/dist/cjs/util/types/TConstructor.js +3 -0
  166. package/dist/cjs/util/types/TConstructor.js.map +1 -0
  167. package/dist/cjs/util/types/TFunction.js +3 -0
  168. package/dist/cjs/util/types/TFunction.js.map +1 -0
  169. package/dist/cjs/util/types/TFunctionNoNew.js +3 -0
  170. package/dist/cjs/util/types/TFunctionNoNew.js.map +1 -0
  171. package/dist/cjs/util/types/TPlainObject.js +3 -0
  172. package/dist/cjs/util/types/TPlainObject.js.map +1 -0
  173. package/dist/cjs/util/types/TPrimitive.js +3 -0
  174. package/dist/cjs/util/types/TPrimitive.js.map +1 -0
  175. package/dist/cjs/util/types/TStringParser.js +3 -0
  176. package/dist/cjs/util/types/TStringParser.js.map +1 -0
  177. package/dist/cjs/util/types/TValidator.js +3 -0
  178. package/dist/cjs/util/types/TValidator.js.map +1 -0
  179. package/dist/cjs/util/validation/createTypedArrayValidator.js +26 -0
  180. package/dist/cjs/util/validation/createTypedArrayValidator.js.map +1 -0
  181. package/dist/cjs/util/validation/ensureThat.js +12 -0
  182. package/dist/cjs/util/validation/ensureThat.js.map +1 -0
  183. package/dist/cjs/util/validation/isArray.js +5 -0
  184. package/dist/cjs/util/validation/isArray.js.map +1 -0
  185. package/dist/cjs/util/validation/isBoolean.js +8 -0
  186. package/dist/cjs/util/validation/isBoolean.js.map +1 -0
  187. package/dist/cjs/util/validation/isFunction.js +17 -0
  188. package/dist/cjs/util/validation/isFunction.js.map +1 -0
  189. package/dist/cjs/util/validation/isNamedFunction.js +11 -0
  190. package/dist/cjs/util/validation/isNamedFunction.js.map +1 -0
  191. package/dist/cjs/util/validation/isNamedFunctionArray.js +9 -0
  192. package/dist/cjs/util/validation/isNamedFunctionArray.js.map +1 -0
  193. package/dist/cjs/util/validation/isObject.js +22 -0
  194. package/dist/cjs/util/validation/isObject.js.map +1 -0
  195. package/dist/cjs/util/validation/isPlainObject.js +19 -0
  196. package/dist/cjs/util/validation/isPlainObject.js.map +1 -0
  197. package/dist/cjs/util/validation/isPrimitive.js +18 -0
  198. package/dist/cjs/util/validation/isPrimitive.js.map +1 -0
  199. package/dist/cjs/util/validation/isString.js +8 -0
  200. package/dist/cjs/util/validation/isString.js.map +1 -0
  201. package/dist/cjs/util/validation/isStringArray.js +12 -0
  202. package/dist/cjs/util/validation/isStringArray.js.map +1 -0
  203. package/dist/cjs/util/validation/isStringWithNoSpacesOrDashes.js +9 -0
  204. package/dist/cjs/util/validation/isStringWithNoSpacesOrDashes.js.map +1 -0
  205. package/dist/cjs/util/validation/numbers/isInteger.js +17 -0
  206. package/dist/cjs/util/validation/numbers/isInteger.js.map +1 -0
  207. package/dist/cjs/util/validation/numbers/isValidNumber.js +22 -0
  208. package/dist/cjs/util/validation/numbers/isValidNumber.js.map +1 -0
  209. package/dist/esm/_example/bFindIn.js +187 -0
  210. package/dist/esm/_example/bFindIn.js.map +1 -0
  211. package/dist/esm/arg/ArgumentBuilder.js +41 -0
  212. package/dist/esm/arg/ArgumentBuilder.js.map +1 -0
  213. package/dist/esm/arg/ArgumentParserSelector.js +11 -0
  214. package/dist/esm/arg/ArgumentParserSelector.js.map +1 -0
  215. package/dist/esm/arg/ArgumentReader.js +34 -0
  216. package/dist/esm/arg/ArgumentReader.js.map +1 -0
  217. package/dist/esm/arg/ArgumentValidatorSelector.js +12 -0
  218. package/dist/esm/arg/ArgumentValidatorSelector.js.map +1 -0
  219. package/dist/esm/cmd/CommandBuilder.js +1073 -0
  220. package/dist/esm/cmd/CommandBuilder.js.map +1 -0
  221. package/dist/esm/cmd/CommandBuilderMetaData.js +40 -0
  222. package/dist/esm/cmd/CommandBuilderMetaData.js.map +1 -0
  223. package/dist/esm/cmd/CommandFeatureSelector.js +108 -0
  224. package/dist/esm/cmd/CommandFeatureSelector.js.map +1 -0
  225. package/dist/esm/cmd/DefaultHelpConfig.js +135 -0
  226. package/dist/esm/cmd/DefaultHelpConfig.js.map +1 -0
  227. package/dist/esm/cmd/asdas.js +25 -0
  228. package/dist/esm/cmd/asdas.js.map +1 -0
  229. package/dist/esm/core/OutputManager.js +92 -0
  230. package/dist/esm/core/OutputManager.js.map +1 -0
  231. package/dist/esm/core/ParserSelector.js +32 -0
  232. package/dist/esm/core/ParserSelector.js.map +1 -0
  233. package/dist/esm/core/ValidatorSelector.js +32 -0
  234. package/dist/esm/core/ValidatorSelector.js.map +1 -0
  235. package/dist/esm/core/splitCombinedArgvShorts.js +11 -0
  236. package/dist/esm/core/splitCombinedArgvShorts.js.map +1 -0
  237. package/dist/esm/db/AbstractJsonFileSection.js +186 -0
  238. package/dist/esm/db/AbstractJsonFileSection.js.map +1 -0
  239. package/dist/esm/db/AppDataSection.js +44 -0
  240. package/dist/esm/db/AppDataSection.js.map +1 -0
  241. package/dist/esm/db/ConfigSection.js +67 -0
  242. package/dist/esm/db/ConfigSection.js.map +1 -0
  243. package/dist/esm/db/JsonFile.js +51 -0
  244. package/dist/esm/db/JsonFile.js.map +1 -0
  245. package/dist/esm/db/PresetsSection.js +88 -0
  246. package/dist/esm/db/PresetsSection.js.map +1 -0
  247. package/dist/esm/index.js +103 -0
  248. package/dist/esm/index.js.map +1 -0
  249. package/dist/esm/opt/OptionArgumentParserSelector.js +12 -0
  250. package/dist/esm/opt/OptionArgumentParserSelector.js.map +1 -0
  251. package/dist/esm/opt/OptionArgumentValidatorSelector.js +15 -0
  252. package/dist/esm/opt/OptionArgumentValidatorSelector.js.map +1 -0
  253. package/dist/esm/opt/OptionBuilder.js +84 -0
  254. package/dist/esm/opt/OptionBuilder.js.map +1 -0
  255. package/dist/esm/opt/OptionHelpers.js +54 -0
  256. package/dist/esm/opt/OptionHelpers.js.map +1 -0
  257. package/dist/esm/opt/OptionReader.js +62 -0
  258. package/dist/esm/opt/OptionReader.js.map +1 -0
  259. package/dist/esm/types/IConfig.js +2 -0
  260. package/dist/esm/types/IConfig.js.map +1 -0
  261. package/dist/esm/types/IPreset.js +2 -0
  262. package/dist/esm/types/IPreset.js.map +1 -0
  263. package/dist/esm/util/array/arrLast.js +17 -0
  264. package/dist/esm/util/array/arrLast.js.map +1 -0
  265. package/dist/esm/util/array/arrSome.js +22 -0
  266. package/dist/esm/util/array/arrSome.js.map +1 -0
  267. package/dist/esm/util/array/types/ArrayPredicate.js +2 -0
  268. package/dist/esm/util/array/types/ArrayPredicate.js.map +1 -0
  269. package/dist/esm/util/db/JsonDB.js +141 -0
  270. package/dist/esm/util/db/JsonDB.js.map +1 -0
  271. package/dist/esm/util/errors/ErrorParser.js +154 -0
  272. package/dist/esm/util/errors/ErrorParser.js.map +1 -0
  273. package/dist/esm/util/fs/promptUserEditInTextEditor/IGetUserInputFromEditorOptions.js +2 -0
  274. package/dist/esm/util/fs/promptUserEditInTextEditor/IGetUserInputFromEditorOptions.js.map +1 -0
  275. package/dist/esm/util/fs/promptUserEditInTextEditor/promptUserEditInTextEditorSync.js +28 -0
  276. package/dist/esm/util/fs/promptUserEditInTextEditor/promptUserEditInTextEditorSync.js.map +1 -0
  277. package/dist/esm/util/fs/promptUserEditInTextEditor/promptUserEditJsonInTextEditorSync.js +21 -0
  278. package/dist/esm/util/fs/promptUserEditInTextEditor/promptUserEditJsonInTextEditorSync.js.map +1 -0
  279. package/dist/esm/util/fs/readFile/readFileSafeSync.js +21 -0
  280. package/dist/esm/util/fs/readFile/readFileSafeSync.js.map +1 -0
  281. package/dist/esm/util/fs/readFile/readFileSync.js +13 -0
  282. package/dist/esm/util/fs/readFile/readFileSync.js.map +1 -0
  283. package/dist/esm/util/fs/readJsonFile/readJsonFileSafeSync.js +17 -0
  284. package/dist/esm/util/fs/readJsonFile/readJsonFileSafeSync.js.map +1 -0
  285. package/dist/esm/util/fs/removeFile/removeFile.js +2 -0
  286. package/dist/esm/util/fs/removeFile/removeFile.js.map +1 -0
  287. package/dist/esm/util/fs/tempFile/tempFileSync.js +21 -0
  288. package/dist/esm/util/fs/tempFile/tempFileSync.js.map +1 -0
  289. package/dist/esm/util/fs/types/IReadJsonFileOptions.js +2 -0
  290. package/dist/esm/util/fs/types/IReadJsonFileOptions.js.map +1 -0
  291. package/dist/esm/util/fs/writeFile/writeFileSafeSync.js +2 -0
  292. package/dist/esm/util/fs/writeFile/writeFileSafeSync.js.map +1 -0
  293. package/dist/esm/util/fs/writeFile/writeFileSync.js +2 -0
  294. package/dist/esm/util/fs/writeFile/writeFileSync.js.map +1 -0
  295. package/dist/esm/util/fs/writeJsonFile/writeJsonFileSafe.js +2 -0
  296. package/dist/esm/util/fs/writeJsonFile/writeJsonFileSafe.js.map +1 -0
  297. package/dist/esm/util/function/MethodDisabler.js +90 -0
  298. package/dist/esm/util/function/MethodDisabler.js.map +1 -0
  299. package/dist/esm/util/function/funSetName.js +17 -0
  300. package/dist/esm/util/function/funSetName.js.map +1 -0
  301. package/dist/esm/util/node/execInherit.js +15 -0
  302. package/dist/esm/util/node/execInherit.js.map +1 -0
  303. package/dist/esm/util/node/formatTableForTerminal.js +14 -0
  304. package/dist/esm/util/node/formatTableForTerminal.js.map +1 -0
  305. package/dist/esm/util/object/arrAssign.js +3 -0
  306. package/dist/esm/util/object/arrAssign.js.map +1 -0
  307. package/dist/esm/util/object/createArrayMerger.js +16 -0
  308. package/dist/esm/util/object/createArrayMerger.js.map +1 -0
  309. package/dist/esm/util/object/createObjectMerger.js +16 -0
  310. package/dist/esm/util/object/createObjectMerger.js.map +1 -0
  311. package/dist/esm/util/object/objAssign.js +3 -0
  312. package/dist/esm/util/object/objAssign.js.map +1 -0
  313. package/dist/esm/util/object/objUpdatePropertyDescriptors.js +24 -0
  314. package/dist/esm/util/object/objUpdatePropertyDescriptors.js.map +1 -0
  315. package/dist/esm/util/object/realizeLazyProperty.js +10 -0
  316. package/dist/esm/util/object/realizeLazyProperty.js.map +1 -0
  317. package/dist/esm/util/object/setNonEnumerable.js +21 -0
  318. package/dist/esm/util/object/setNonEnumerable.js.map +1 -0
  319. package/dist/esm/util/os/defaultOpenInEditorCommand.js +14 -0
  320. package/dist/esm/util/os/defaultOpenInEditorCommand.js.map +1 -0
  321. package/dist/esm/util/os/isOSX.js +9 -0
  322. package/dist/esm/util/os/isOSX.js.map +1 -0
  323. package/dist/esm/util/os/isVsCodeInstalled.js +15 -0
  324. package/dist/esm/util/os/isVsCodeInstalled.js.map +1 -0
  325. package/dist/esm/util/os/isWindows.js +12 -0
  326. package/dist/esm/util/os/isWindows.js.map +1 -0
  327. package/dist/esm/util/path/getTempDataPath.js +13 -0
  328. package/dist/esm/util/path/getTempDataPath.js.map +1 -0
  329. package/dist/esm/util/regex/regexEscapeString.js +14 -0
  330. package/dist/esm/util/regex/regexEscapeString.js.map +1 -0
  331. package/dist/esm/util/string/strEnsureStartsWith.js +15 -0
  332. package/dist/esm/util/string/strEnsureStartsWith.js.map +1 -0
  333. package/dist/esm/util/string/strFirstCharToUpperCase.js +12 -0
  334. package/dist/esm/util/string/strFirstCharToUpperCase.js.map +1 -0
  335. package/dist/esm/util/string/strIsLowerCase.js +14 -0
  336. package/dist/esm/util/string/strIsLowerCase.js.map +1 -0
  337. package/dist/esm/util/string/strIsUpperCase.js +14 -0
  338. package/dist/esm/util/string/strIsUpperCase.js.map +1 -0
  339. package/dist/esm/util/string/strSplitCamelCase.js +51 -0
  340. package/dist/esm/util/string/strSplitCamelCase.js.map +1 -0
  341. package/dist/esm/util/string-parsers/createBooleanParser.js +17 -0
  342. package/dist/esm/util/string-parsers/createBooleanParser.js.map +1 -0
  343. package/dist/esm/util/string-parsers/createTypedListParser.js +18 -0
  344. package/dist/esm/util/string-parsers/createTypedListParser.js.map +1 -0
  345. package/dist/esm/util/string-parsers/parseBoolean.js +12 -0
  346. package/dist/esm/util/string-parsers/parseBoolean.js.map +1 -0
  347. package/dist/esm/util/string-parsers/parseInteger.js +13 -0
  348. package/dist/esm/util/string-parsers/parseInteger.js.map +1 -0
  349. package/dist/esm/util/string-parsers/parseNumber.js +9 -0
  350. package/dist/esm/util/string-parsers/parseNumber.js.map +1 -0
  351. package/dist/esm/util/string-parsers/parseString.js +4 -0
  352. package/dist/esm/util/string-parsers/parseString.js.map +1 -0
  353. package/dist/esm/util/types/Any.js +2 -0
  354. package/dist/esm/util/types/Any.js.map +1 -0
  355. package/dist/esm/util/types/DeepArray.js +2 -0
  356. package/dist/esm/util/types/DeepArray.js.map +1 -0
  357. package/dist/esm/util/types/DeepObject.js +2 -0
  358. package/dist/esm/util/types/DeepObject.js.map +1 -0
  359. package/dist/esm/util/types/JsonArray.js +2 -0
  360. package/dist/esm/util/types/JsonArray.js.map +1 -0
  361. package/dist/esm/util/types/JsonDefinedPrimitive.js +5 -0
  362. package/dist/esm/util/types/JsonDefinedPrimitive.js.map +1 -0
  363. package/dist/esm/util/types/JsonObject.js +2 -0
  364. package/dist/esm/util/types/JsonObject.js.map +1 -0
  365. package/dist/esm/util/types/JsonRawPrimitive.js +2 -0
  366. package/dist/esm/util/types/JsonRawPrimitive.js.map +1 -0
  367. package/dist/esm/util/types/JsonValue.js +2 -0
  368. package/dist/esm/util/types/JsonValue.js.map +1 -0
  369. package/dist/esm/util/types/ObjectKey.js +2 -0
  370. package/dist/esm/util/types/ObjectKey.js.map +1 -0
  371. package/dist/esm/util/types/TConstructor.js +2 -0
  372. package/dist/esm/util/types/TConstructor.js.map +1 -0
  373. package/dist/esm/util/types/TFunction.js +2 -0
  374. package/dist/esm/util/types/TFunction.js.map +1 -0
  375. package/dist/esm/util/types/TFunctionNoNew.js +2 -0
  376. package/dist/esm/util/types/TFunctionNoNew.js.map +1 -0
  377. package/dist/esm/util/types/TPlainObject.js +2 -0
  378. package/dist/esm/util/types/TPlainObject.js.map +1 -0
  379. package/dist/esm/util/types/TPrimitive.js +2 -0
  380. package/dist/esm/util/types/TPrimitive.js.map +1 -0
  381. package/dist/esm/util/types/TStringParser.js +2 -0
  382. package/dist/esm/util/types/TStringParser.js.map +1 -0
  383. package/dist/esm/util/types/TValidator.js +2 -0
  384. package/dist/esm/util/types/TValidator.js.map +1 -0
  385. package/dist/esm/util/validation/createTypedArrayValidator.js +22 -0
  386. package/dist/esm/util/validation/createTypedArrayValidator.js.map +1 -0
  387. package/dist/esm/util/validation/ensureThat.js +8 -0
  388. package/dist/esm/util/validation/ensureThat.js.map +1 -0
  389. package/dist/esm/util/validation/isArray.js +2 -0
  390. package/dist/esm/util/validation/isArray.js.map +1 -0
  391. package/dist/esm/util/validation/isBoolean.js +4 -0
  392. package/dist/esm/util/validation/isBoolean.js.map +1 -0
  393. package/dist/esm/util/validation/isFunction.js +13 -0
  394. package/dist/esm/util/validation/isFunction.js.map +1 -0
  395. package/dist/esm/util/validation/isNamedFunction.js +7 -0
  396. package/dist/esm/util/validation/isNamedFunction.js.map +1 -0
  397. package/dist/esm/util/validation/isNamedFunctionArray.js +5 -0
  398. package/dist/esm/util/validation/isNamedFunctionArray.js.map +1 -0
  399. package/dist/esm/util/validation/isObject.js +18 -0
  400. package/dist/esm/util/validation/isObject.js.map +1 -0
  401. package/dist/esm/util/validation/isPlainObject.js +15 -0
  402. package/dist/esm/util/validation/isPlainObject.js.map +1 -0
  403. package/dist/esm/util/validation/isPrimitive.js +14 -0
  404. package/dist/esm/util/validation/isPrimitive.js.map +1 -0
  405. package/dist/esm/util/validation/isString.js +4 -0
  406. package/dist/esm/util/validation/isString.js.map +1 -0
  407. package/dist/esm/util/validation/isStringArray.js +8 -0
  408. package/dist/esm/util/validation/isStringArray.js.map +1 -0
  409. package/dist/esm/util/validation/isStringWithNoSpacesOrDashes.js +5 -0
  410. package/dist/esm/util/validation/isStringWithNoSpacesOrDashes.js.map +1 -0
  411. package/dist/esm/util/validation/numbers/isInteger.js +14 -0
  412. package/dist/esm/util/validation/numbers/isInteger.js.map +1 -0
  413. package/dist/esm/util/validation/numbers/isValidNumber.js +18 -0
  414. package/dist/esm/util/validation/numbers/isValidNumber.js.map +1 -0
  415. package/dist/types/_example/bFindIn.d.ts +1 -0
  416. package/{src → dist/types}/arg/ArgumentBuilder.d.ts +1 -1
  417. package/{src → dist/types}/arg/ArgumentParserSelector.d.ts +2 -2
  418. package/{src → dist/types}/arg/ArgumentReader.d.ts +3 -3
  419. package/{src → dist/types}/arg/ArgumentValidatorSelector.d.ts +2 -2
  420. package/{src → dist/types}/cmd/CommandBuilder.d.ts +32 -28
  421. package/{src → dist/types}/cmd/CommandBuilderMetaData.d.ts +8 -7
  422. package/{src → dist/types}/cmd/CommandFeatureSelector.d.ts +1 -1
  423. package/dist/types/cmd/DefaultHelpConfig.d.ts +28 -0
  424. package/dist/types/cmd/asdas.d.ts +6 -0
  425. package/{src → dist/types}/core/OutputManager.d.ts +1 -1
  426. package/{src → dist/types}/core/ParserSelector.d.ts +3 -3
  427. package/{src → dist/types}/core/ValidatorSelector.d.ts +2 -2
  428. package/{src → dist/types}/db/AbstractJsonFileSection.d.ts +3 -3
  429. package/{src → dist/types}/db/AppDataSection.d.ts +1 -1
  430. package/{src → dist/types}/db/ConfigSection.d.ts +4 -4
  431. package/{src → dist/types}/db/PresetsSection.d.ts +2 -2
  432. package/{src → dist/types}/index.d.ts +2 -2
  433. package/{src → dist/types}/opt/OptionArgumentParserSelector.d.ts +1 -1
  434. package/{src → dist/types}/opt/OptionArgumentValidatorSelector.d.ts +2 -2
  435. package/{src → dist/types}/opt/OptionBuilder.d.ts +2 -1
  436. package/{src → dist/types}/opt/OptionHelpers.d.ts +2 -2
  437. package/{src → dist/types}/opt/OptionReader.d.ts +7 -7
  438. package/{src → dist/types}/types/IConfig.d.ts +3 -3
  439. package/{src → dist/types}/types/IPreset.d.ts +4 -3
  440. package/{src → dist/types}/util/db/JsonDB.d.ts +2 -2
  441. package/{src → dist/types}/util/fs/promptUserEditInTextEditor/promptUserEditInTextEditorSync.d.ts +1 -1
  442. package/{src → dist/types}/util/fs/promptUserEditInTextEditor/promptUserEditJsonInTextEditorSync.d.ts +1 -1
  443. package/{src → dist/types}/util/fs/readJsonFile/readJsonFileSafeSync.d.ts +1 -1
  444. package/{src → dist/types}/util/fs/tempFile/tempFileSync.d.ts +1 -1
  445. package/{src → dist/types}/util/function/MethodDisabler.d.ts +3 -3
  446. package/{src → dist/types}/util/object/createObjectMerger.d.ts +1 -1
  447. package/{src → dist/types}/util/object/objUpdatePropertyDescriptors.d.ts +1 -1
  448. package/{src → dist/types}/util/object/setNonEnumerable.d.ts +1 -1
  449. package/{src → dist/types}/util/string-parsers/createTypedListParser.d.ts +1 -1
  450. package/{src → dist/types}/util/types/DeepArray.d.ts +2 -2
  451. package/{src → dist/types}/util/types/DeepObject.d.ts +2 -2
  452. package/{src → dist/types}/util/types/JsonArray.d.ts +2 -2
  453. package/{src → dist/types}/util/types/JsonObject.d.ts +2 -2
  454. package/{src → dist/types}/util/types/JsonRawPrimitive.d.ts +1 -1
  455. package/{src → dist/types}/util/types/JsonValue.d.ts +3 -3
  456. package/{src → dist/types}/util/types/TConstructor.d.ts +1 -1
  457. package/dist/types/util/types/TFunction.d.ts +4 -0
  458. package/{src → dist/types}/util/types/TFunctionNoNew.d.ts +1 -1
  459. package/{src → dist/types}/util/types/TPlainObject.d.ts +1 -1
  460. package/dist/types/util/types/TValidator.d.ts +2 -0
  461. package/{src → dist/types}/util/validation/ensureThat.d.ts +2 -2
  462. package/{src → dist/types}/util/validation/isFunction.d.ts +1 -1
  463. package/{src → dist/types}/util/validation/isNamedFunction.d.ts +1 -1
  464. package/{src → dist/types}/util/validation/isPlainObject.d.ts +2 -2
  465. package/{src → dist/types}/util/validation/isPrimitive.d.ts +1 -1
  466. package/jest.config.ts +11 -0
  467. package/notes/tsc.md +1 -0
  468. package/package.json +13 -6
  469. package/project.json +44 -0
  470. package/scripts/currentBemojeUtils.txt +41 -0
  471. package/scripts/rollupUtils.ts +184 -0
  472. package/src/_example/CommandBuilder.example.ts +92 -0
  473. package/src/_example/CommandBuilder.example2.ts +30 -0
  474. package/src/_example/bFindIn.ts +200 -0
  475. package/src/arg/ArgumentBuilder.test.ts +102 -0
  476. package/src/arg/ArgumentBuilder.ts +47 -0
  477. package/src/arg/ArgumentParserSelector.test.ts +53 -0
  478. package/src/arg/ArgumentParserSelector.ts +14 -0
  479. package/src/arg/ArgumentReader.test.ts +60 -0
  480. package/src/arg/ArgumentReader.ts +33 -0
  481. package/src/arg/ArgumentValidatorSelector.test.ts +80 -0
  482. package/src/arg/ArgumentValidatorSelector.ts +14 -0
  483. package/src/cmd/CommandBuilder.test.ts +611 -0
  484. package/src/cmd/CommandBuilder.ts +1164 -0
  485. package/src/cmd/CommandBuilderMetaData.test.ts +54 -0
  486. package/src/cmd/CommandBuilderMetaData.ts +45 -0
  487. package/src/cmd/CommandFeatureSelector.test.ts +185 -0
  488. package/src/cmd/CommandFeatureSelector.ts +113 -0
  489. package/src/cmd/DefaultHelpConfig.test.ts +22 -0
  490. package/src/cmd/DefaultHelpConfig.ts +141 -0
  491. package/src/cmd/asdas.ts +40 -0
  492. package/src/core/OutputManager.test.ts +129 -0
  493. package/src/core/OutputManager.ts +103 -0
  494. package/src/core/ParserSelector.test.ts +7 -0
  495. package/src/core/ParserSelector.ts +38 -0
  496. package/src/core/ValidatorSelector.test.ts +7 -0
  497. package/src/core/ValidatorSelector.ts +38 -0
  498. package/src/core/splitCombinedArgvShorts.test.ts +9 -0
  499. package/src/core/splitCombinedArgvShorts.ts +10 -0
  500. package/src/db/AbstractJsonFileSection.test.ts +274 -0
  501. package/src/db/AbstractJsonFileSection.ts +218 -0
  502. package/src/db/AppDataSection.test.ts +69 -0
  503. package/src/db/AppDataSection.ts +46 -0
  504. package/src/db/ConfigSection.test.ts +95 -0
  505. package/src/db/ConfigSection.ts +74 -0
  506. package/src/db/JsonFile.test.ts +56 -0
  507. package/src/db/JsonFile.ts +52 -0
  508. package/src/db/PresetsSection.test.ts +130 -0
  509. package/src/db/PresetsSection.ts +92 -0
  510. package/src/index.ts +102 -0
  511. package/src/opt/OptionArgumentParserSelector.test.ts +55 -0
  512. package/src/opt/OptionArgumentParserSelector.ts +14 -0
  513. package/src/opt/OptionArgumentValidatorSelector.test.ts +89 -0
  514. package/src/opt/OptionArgumentValidatorSelector.ts +16 -0
  515. package/src/opt/OptionBuilder.test.ts +229 -0
  516. package/src/opt/OptionBuilder.ts +85 -0
  517. package/src/opt/OptionHelpers.test.ts +229 -0
  518. package/src/opt/OptionHelpers.ts +57 -0
  519. package/src/opt/OptionReader.test.ts +106 -0
  520. package/src/opt/OptionReader.ts +61 -0
  521. package/src/types/IConfig.ts +25 -0
  522. package/src/types/IPreset.ts +16 -0
  523. package/src/util/array/arrLast.test.ts +25 -0
  524. package/src/util/array/arrLast.ts +15 -0
  525. package/src/util/array/arrSome.test.ts +78 -0
  526. package/src/util/array/arrSome.ts +23 -0
  527. package/src/util/array/types/ArrayPredicate.ts +10 -0
  528. package/src/util/db/JsonDB.test.ts +214 -0
  529. package/src/util/db/JsonDB.ts +138 -0
  530. package/src/util/errors/ErrorParser.ts +165 -0
  531. package/src/util/fs/promptUserEditInTextEditor/IGetUserInputFromEditorOptions.ts +15 -0
  532. package/src/util/fs/promptUserEditInTextEditor/promptUserEditInTextEditorSync.ts +30 -0
  533. package/src/util/fs/promptUserEditInTextEditor/promptUserEditJsonInTextEditorSync.ts +25 -0
  534. package/src/util/fs/readFile/readFileSafeSync.ts +20 -0
  535. package/src/util/fs/readFile/readFileSync.ts +13 -0
  536. package/src/util/fs/readJsonFile/readJsonFileSafeSync.ts +17 -0
  537. package/src/util/fs/removeFile/removeFile.ts +1 -0
  538. package/src/util/fs/tempFile/tempFileSync.ts +21 -0
  539. package/src/util/fs/types/IReadJsonFileOptions.ts +1 -0
  540. package/src/util/fs/writeFile/writeFileSafeSync.ts +1 -0
  541. package/src/util/fs/writeFile/writeFileSync.ts +1 -0
  542. package/src/util/fs/writeJsonFile/writeJsonFileSafe.ts +1 -0
  543. package/src/util/function/MethodDisabler.test.ts +112 -0
  544. package/src/util/function/MethodDisabler.ts +94 -0
  545. package/src/util/function/funSetName.test.ts +12 -0
  546. package/src/util/function/funSetName.ts +16 -0
  547. package/src/util/node/execInherit.ts +14 -0
  548. package/src/util/node/formatTableForTerminal.ts +12 -0
  549. package/src/util/object/arrAssign.ts +3 -0
  550. package/src/util/object/createArrayMerger.test.ts +11 -0
  551. package/src/util/object/createArrayMerger.ts +15 -0
  552. package/src/util/object/createObjectMerger.test.ts +11 -0
  553. package/src/util/object/createObjectMerger.ts +17 -0
  554. package/src/util/object/objAssign.ts +3 -0
  555. package/src/util/object/objUpdatePropertyDescriptors.test.ts +40 -0
  556. package/src/util/object/objUpdatePropertyDescriptors.ts +29 -0
  557. package/src/util/object/realizeLazyProperty.ts +9 -0
  558. package/src/util/object/setNonEnumerable.test.ts +63 -0
  559. package/src/util/object/setNonEnumerable.ts +22 -0
  560. package/src/util/os/defaultOpenInEditorCommand.ts +14 -0
  561. package/src/util/os/isOSX.ts +9 -0
  562. package/src/util/os/isVsCodeInstalled.test.ts +7 -0
  563. package/src/util/os/isVsCodeInstalled.ts +14 -0
  564. package/src/util/os/isWindows.ts +12 -0
  565. package/src/util/path/getTempDataPath.test.ts +9 -0
  566. package/src/util/path/getTempDataPath.ts +14 -0
  567. package/src/util/regex/regexEscapeString.test.ts +35 -0
  568. package/src/util/regex/regexEscapeString.ts +13 -0
  569. package/src/util/string/strEnsureStartsWith.test.ts +13 -0
  570. package/src/util/string/strEnsureStartsWith.ts +14 -0
  571. package/src/util/string/strFirstCharToUpperCase.test.ts +33 -0
  572. package/src/util/string/strFirstCharToUpperCase.ts +11 -0
  573. package/src/util/string/strIsLowerCase.test.ts +42 -0
  574. package/src/util/string/strIsLowerCase.ts +13 -0
  575. package/src/util/string/strIsUpperCase.test.ts +48 -0
  576. package/src/util/string/strIsUpperCase.ts +13 -0
  577. package/src/util/string/strSplitCamelCase.test.ts +54 -0
  578. package/src/util/string/strSplitCamelCase.ts +51 -0
  579. package/src/util/string-parsers/createBooleanParser.test.ts +58 -0
  580. package/src/util/string-parsers/createBooleanParser.ts +21 -0
  581. package/src/util/string-parsers/createTypedListParser.test.ts +19 -0
  582. package/src/util/string-parsers/createTypedListParser.ts +19 -0
  583. package/src/util/string-parsers/parseBoolean.test.ts +30 -0
  584. package/src/util/string-parsers/parseBoolean.ts +12 -0
  585. package/src/util/string-parsers/parseInteger.test.ts +52 -0
  586. package/src/util/string-parsers/parseInteger.ts +9 -0
  587. package/src/util/string-parsers/parseNumber.test.ts +53 -0
  588. package/src/util/string-parsers/parseNumber.ts +6 -0
  589. package/src/util/string-parsers/parseString.test.ts +7 -0
  590. package/src/util/string-parsers/parseString.ts +3 -0
  591. package/src/util/types/Any.ts +2 -0
  592. package/src/util/types/DeepArray.ts +12 -0
  593. package/src/util/types/DeepObject.ts +16 -0
  594. package/src/util/types/JsonArray.ts +8 -0
  595. package/src/util/types/JsonDefinedPrimitive.ts +5 -0
  596. package/src/util/types/JsonObject.ts +8 -0
  597. package/src/util/types/JsonRawPrimitive.ts +7 -0
  598. package/src/util/types/JsonValue.ts +14 -0
  599. package/src/util/types/ObjectKey.ts +1 -0
  600. package/src/util/types/TConstructor.ts +6 -0
  601. package/src/util/types/TFunction.ts +5 -0
  602. package/src/util/types/TFunctionNoNew.ts +3 -0
  603. package/src/util/types/TPlainObject.ts +4 -0
  604. package/src/util/types/TPrimitive.ts +1 -0
  605. package/src/util/types/TStringParser.ts +1 -0
  606. package/src/util/types/TValidator.ts +3 -0
  607. package/src/util/validation/createTypedArrayValidator.test.ts +34 -0
  608. package/src/util/validation/createTypedArrayValidator.ts +25 -0
  609. package/src/util/validation/ensureThat.test.ts +37 -0
  610. package/src/util/validation/ensureThat.ts +14 -0
  611. package/src/util/validation/isArray.test.ts +7 -0
  612. package/src/util/validation/isArray.ts +1 -0
  613. package/src/util/validation/isBoolean.test.ts +31 -0
  614. package/src/util/validation/isBoolean.ts +3 -0
  615. package/src/util/validation/isFunction.test.ts +54 -0
  616. package/src/util/validation/isFunction.ts +14 -0
  617. package/src/util/validation/isNamedFunction.test.ts +28 -0
  618. package/src/util/validation/isNamedFunction.ts +8 -0
  619. package/src/util/validation/isNamedFunctionArray.test.ts +14 -0
  620. package/src/util/validation/isNamedFunctionArray.ts +5 -0
  621. package/src/util/validation/isObject.test.ts +57 -0
  622. package/src/util/validation/isObject.ts +17 -0
  623. package/src/util/validation/isPlainObject.test.ts +21 -0
  624. package/src/util/validation/isPlainObject.ts +14 -0
  625. package/src/util/validation/isPrimitive.ts +15 -0
  626. package/src/util/validation/isString.test.ts +23 -0
  627. package/src/util/validation/isString.ts +3 -0
  628. package/src/util/validation/isStringArray.test.ts +24 -0
  629. package/src/util/validation/isStringArray.ts +8 -0
  630. package/src/util/validation/isStringWithNoSpacesOrDashes.test.ts +28 -0
  631. package/src/util/validation/isStringWithNoSpacesOrDashes.ts +5 -0
  632. package/src/util/validation/numbers/isInteger.test.ts +25 -0
  633. package/src/util/validation/numbers/isInteger.ts +13 -0
  634. package/src/util/validation/numbers/isValidNumber.test.ts +20 -0
  635. package/src/util/validation/numbers/isValidNumber.ts +17 -0
  636. package/tsconfig.json +32 -0
  637. package/tsconfig.lib.json +18 -0
  638. package/tsconfig.spec.json +10 -0
  639. package/index.cjs.d.ts +0 -1
  640. package/index.cjs.js +0 -3231
  641. package/index.esm.js +0 -3119
  642. package/src/cmd/CLI.d.ts +0 -2
  643. package/src/cmd/DefaultHelpConfig.d.ts +0 -2
  644. package/src/proto/overrideCommanderPrototype.d.ts +0 -8
  645. package/src/util/types/TFunction.d.ts +0 -4
  646. package/src/util/types/TValidator.d.ts +0 -1
  647. /package/{src → dist/types}/core/splitCombinedArgvShorts.d.ts +0 -0
  648. /package/{src → dist/types}/db/JsonFile.d.ts +0 -0
  649. /package/{src → dist/types}/util/array/arrLast.d.ts +0 -0
  650. /package/{src → dist/types}/util/array/arrSome.d.ts +0 -0
  651. /package/{src → dist/types}/util/array/types/ArrayPredicate.d.ts +0 -0
  652. /package/{src → dist/types}/util/errors/ErrorParser.d.ts +0 -0
  653. /package/{src → dist/types}/util/fs/promptUserEditInTextEditor/IGetUserInputFromEditorOptions.d.ts +0 -0
  654. /package/{src → dist/types}/util/fs/readFile/readFileSafeSync.d.ts +0 -0
  655. /package/{src → dist/types}/util/fs/readFile/readFileSync.d.ts +0 -0
  656. /package/{src → dist/types}/util/fs/removeFile/removeFile.d.ts +0 -0
  657. /package/{src → dist/types}/util/fs/types/IReadJsonFileOptions.d.ts +0 -0
  658. /package/{src → dist/types}/util/fs/writeFile/writeFileSafeSync.d.ts +0 -0
  659. /package/{src → dist/types}/util/fs/writeFile/writeFileSync.d.ts +0 -0
  660. /package/{src → dist/types}/util/fs/writeJsonFile/writeJsonFileSafe.d.ts +0 -0
  661. /package/{src → dist/types}/util/function/funSetName.d.ts +0 -0
  662. /package/{src → dist/types}/util/node/execInherit.d.ts +0 -0
  663. /package/{src → dist/types}/util/node/formatTableForTerminal.d.ts +0 -0
  664. /package/{src → dist/types}/util/object/arrAssign.d.ts +0 -0
  665. /package/{src → dist/types}/util/object/createArrayMerger.d.ts +0 -0
  666. /package/{src → dist/types}/util/object/objAssign.d.ts +0 -0
  667. /package/{src → dist/types}/util/object/realizeLazyProperty.d.ts +0 -0
  668. /package/{src → dist/types}/util/os/defaultOpenInEditorCommand.d.ts +0 -0
  669. /package/{src → dist/types}/util/os/isOSX.d.ts +0 -0
  670. /package/{src → dist/types}/util/os/isVsCodeInstalled.d.ts +0 -0
  671. /package/{src → dist/types}/util/os/isWindows.d.ts +0 -0
  672. /package/{src → dist/types}/util/path/getTempDataPath.d.ts +0 -0
  673. /package/{src → dist/types}/util/regex/regexEscapeString.d.ts +0 -0
  674. /package/{src → dist/types}/util/string/strEnsureStartsWith.d.ts +0 -0
  675. /package/{src → dist/types}/util/string/strFirstCharToUpperCase.d.ts +0 -0
  676. /package/{src → dist/types}/util/string/strIsLowerCase.d.ts +0 -0
  677. /package/{src → dist/types}/util/string/strIsUpperCase.d.ts +0 -0
  678. /package/{src → dist/types}/util/string/strSplitCamelCase.d.ts +0 -0
  679. /package/{src → dist/types}/util/string-parsers/createBooleanParser.d.ts +0 -0
  680. /package/{src → dist/types}/util/string-parsers/parseBoolean.d.ts +0 -0
  681. /package/{src → dist/types}/util/string-parsers/parseInteger.d.ts +0 -0
  682. /package/{src → dist/types}/util/string-parsers/parseNumber.d.ts +0 -0
  683. /package/{src → dist/types}/util/string-parsers/parseString.d.ts +0 -0
  684. /package/{src → dist/types}/util/types/Any.d.ts +0 -0
  685. /package/{src → dist/types}/util/types/JsonDefinedPrimitive.d.ts +0 -0
  686. /package/{src → dist/types}/util/types/ObjectKey.d.ts +0 -0
  687. /package/{src → dist/types}/util/types/TPrimitive.d.ts +0 -0
  688. /package/{src → dist/types}/util/types/TStringParser.d.ts +0 -0
  689. /package/{src → dist/types}/util/validation/createTypedArrayValidator.d.ts +0 -0
  690. /package/{src → dist/types}/util/validation/isArray.d.ts +0 -0
  691. /package/{src → dist/types}/util/validation/isBoolean.d.ts +0 -0
  692. /package/{src → dist/types}/util/validation/isNamedFunctionArray.d.ts +0 -0
  693. /package/{src → dist/types}/util/validation/isObject.d.ts +0 -0
  694. /package/{src → dist/types}/util/validation/isString.d.ts +0 -0
  695. /package/{src → dist/types}/util/validation/isStringArray.d.ts +0 -0
  696. /package/{src → dist/types}/util/validation/isStringWithNoSpacesOrDashes.d.ts +0 -0
  697. /package/{src → dist/types}/util/validation/numbers/isInteger.d.ts +0 -0
  698. /package/{src → dist/types}/util/validation/numbers/isValidNumber.d.ts +0 -0
package/index.esm.js DELETED
@@ -1,3119 +0,0 @@
1
- import { Argument, Command, Help, Option, CommanderError, InvalidArgumentError } from 'commander';
2
- export * from 'commander';
3
- import colors from 'ansi-colors';
4
- import fs, { writeFileSync, outputJson, remove } from 'fs-extra';
5
- export { remove as removeFile, outputFileSync as writeFileSafeSync, writeFileSync, outputJson as writeJsonFileSafe } from 'fs-extra';
6
- import isAsyncFunction from 'is-async-function';
7
- import os from 'os';
8
- import path from 'path';
9
- import Table from 'cli-table';
10
- import { execSync } from 'child_process';
11
-
12
- /**
13
- * Creates a parser function that parses a delimited string into a list of typed values.
14
- * The parser function takes a string and returns an array of typed values.
15
- *
16
- * @param delimiter - The delimiter used to split the string into individual values.
17
- * @param parser - The function used to parse each individual value in the string.
18
- * @returns A function that takes a delimited string and returns an array of typed values.
19
- * @template T - The type of the values in the list.
20
- */ function createTypedListParser(delimiter, parser) {
21
- return function parseList(string) {
22
- return string.split(delimiter).map((str)=>str.trim()).map(parser);
23
- };
24
- }
25
-
26
- function parseInteger(string) {
27
- const errMsg = 'Not an integer. Got: ';
28
- if (string.includes('.')) throw new TypeError(errMsg + string);
29
- string = string.replace(/[^-0-9]/g, '');
30
- if (!string) throw new TypeError(errMsg + string);
31
- const int = parseInt(string);
32
- if (isNaN(int)) throw new TypeError(errMsg + string);
33
- return int;
34
- }
35
-
36
- function parseNumber(string) {
37
- if (string.endsWith('Infinity')) return Number(string);
38
- string = string.replace(/[^-0-9.]/g, '');
39
- if (!string) return NaN;
40
- return Number(string);
41
- }
42
-
43
- function parseString(string) {
44
- return string;
45
- }
46
-
47
- class ParserSelector {
48
- constructor(builder){
49
- this.builder = builder;
50
- }
51
- string() {
52
- return this.custom(parseString);
53
- }
54
- number() {
55
- return this.custom(parseNumber);
56
- }
57
- integer() {
58
- return this.custom(parseInteger);
59
- }
60
- delimitedStrings(delimiter = ',') {
61
- return this.delimited(delimiter, parseString);
62
- }
63
- delimitedNumbers(delimiter = ',') {
64
- return this.delimited(delimiter, parseNumber);
65
- }
66
- delimitedIntegers(delimiter = ',') {
67
- return this.delimited(delimiter, parseInteger);
68
- }
69
- delimited(delimiter = ',', parser) {
70
- return this.custom(createTypedListParser(delimiter, parser));
71
- }
72
- }
73
-
74
- class ArgumentParserSelector extends ParserSelector {
75
- constructor(builder){
76
- super(builder);
77
- }
78
- custom(parser) {
79
- this.builder.cmd.meta.argParsers[this.builder.index] = parser;
80
- return this.builder;
81
- }
82
- }
83
-
84
- class ArgumentReader {
85
- constructor(parent){
86
- this.parent = parent;
87
- }
88
- get $() {
89
- return this.parent.$;
90
- }
91
- get argument() {
92
- return this.$;
93
- }
94
- get name() {
95
- return this.$.name();
96
- }
97
- get choices() {
98
- return this.$.argChoices;
99
- }
100
- get default() {
101
- return this.$.defaultValue;
102
- }
103
- get description() {
104
- return this.$.description;
105
- }
106
- get variadic() {
107
- return this.$.variadic;
108
- }
109
- get required() {
110
- return this.$.required;
111
- }
112
- get optional() {
113
- return !this.$.required;
114
- }
115
- }
116
-
117
- /**
118
- * Returns the last element of an array.
119
- * Throws an error if the array is empty.
120
- * @template T The type of elements in the array.
121
- * @param array The array to get the last element from.
122
- * @returns The last element of the array.
123
- * @throws If the array is empty.
124
- * @example const numbers = [1, 2, 3, 4, 5];
125
- * const lastNumber = arrLast(numbers);
126
- * //=> 5
127
- */ function arrLast(array) {
128
- if (!array.length) throw new Error('Cannot get last element of empty array.');
129
- return array[array.length - 1];
130
- }
131
-
132
- function ensureThat(value, validator, options = {}) {
133
- const result = validator(value, ...options.args ?? []);
134
- if (result === true) return value;
135
- const message = typeof result === 'string' ? `${result}. Got: ${value}` : `Expected '${validator.name}'. Got: ${value}`;
136
- throw new (options.Err ?? Error)(message);
137
- }
138
-
139
- /**
140
- * This function sets the name of a function and returns the function with the new name.
141
- * @template T - The type of the function.
142
- * @param name The new name to be set for the function.
143
- * @param fun The function whose name is to be set.
144
- * @returns The function with the new name.
145
- * @example ```ts
146
- * const myFun = () => 'Hello World';
147
- * funSetName('newFun', myFun).name;;
148
- * //=> 'newFun'
149
- * ```
150
- */ function funSetName(name, fun) {
151
- Object.defineProperty(fun, 'name', {
152
- value: name,
153
- configurable: true,
154
- writable: true,
155
- enumerable: false
156
- });
157
- return fun;
158
- }
159
-
160
- /**
161
- * Checks if the provided value is a named function.
162
- */ function isNamedFunction(func) {
163
- return typeof func === 'function' && !!func.name;
164
- }
165
-
166
- function isNamedFunctionArray(array) {
167
- return Array.isArray(array) && array.every(isNamedFunction);
168
- }
169
-
170
- /**
171
- * Converts the first character of a string to uppercase.
172
- * @param string The string to be converted.
173
- * @example ```ts
174
- * strFirstCharToUpperCase('hello');
175
- * //=> 'Hello'
176
- * ```
177
- */ function strFirstCharToUpperCase(string) {
178
- return string.charAt(0).toUpperCase() + string.substring(1);
179
- }
180
-
181
- /**
182
- * Creates a validator function that checks whether the input is an array where all elements are valid according to every validator provided.
183
- *
184
- * @param validators - An array of validator functions.
185
- * @param name - The name of the validator function. If not provided, the name will be derived from the validator functions.
186
- *
187
- * @throws TypeError - if no name is provided and not all validators are named functions.
188
- */ function createTypedArrayValidator(validators, name) {
189
- if (!name) {
190
- ensureThat(validators, isNamedFunctionArray);
191
- name = 'isArrayWhereEach' + validators.map((fun)=>strFirstCharToUpperCase(fun.name)).join('And');
192
- }
193
- return funSetName(name, function(array) {
194
- return Array.isArray(array) && array.every((value)=>validators.every((isValid)=>isValid(value)));
195
- });
196
- }
197
-
198
- /**
199
- * Checks if the provided number is an integer.
200
- * @remarks This function uses the built-in `Number.isInteger` method.
201
- * @param int The number to check.
202
- * @returns A boolean indicating whether the provided number is an integer.
203
- * @example ```ts
204
- * isInteger(5);
205
- * //=> true
206
- * isInteger(5.5);
207
- * //=> false
208
- * ```
209
- */ const isInteger = Number.isInteger;
210
-
211
- function isString(value) {
212
- return typeof value === 'string';
213
- }
214
-
215
- /**
216
- * Checks if the provided value is a valid number.
217
- * @remarks This function checks if the provided value is a finite number and not NaN.
218
- * @param number The value to check.
219
- * @returns A boolean indicating whether the provided value is a valid number.
220
- * @example ```ts
221
- * isValidNumber(123);
222
- * //=> true
223
- * isValidNumber(NaN);
224
- * //=> false
225
- * isValidNumber(Infinity);
226
- * //=> false
227
- * ```
228
- */ function isValidNumber(number) {
229
- return isFinite(number) && !isNaN(number);
230
- }
231
-
232
- class ValidatorSelector {
233
- constructor(builder){
234
- this.builder = builder;
235
- }
236
- isString() {
237
- return this.custom(isString);
238
- }
239
- isNumber() {
240
- return this.custom(isValidNumber);
241
- }
242
- isInteger() {
243
- return this.custom(isInteger);
244
- }
245
- isStringArray() {
246
- return this.arrayWhereEach(isString);
247
- }
248
- isNumberArray() {
249
- return this.arrayWhereEach(isValidNumber);
250
- }
251
- isIntegerArray() {
252
- return this.arrayWhereEach(isInteger);
253
- }
254
- arrayWhereEach(...validators) {
255
- return this.custom(createTypedArrayValidator(validators));
256
- }
257
- }
258
-
259
- class ArgumentValidatorSelector extends ValidatorSelector {
260
- constructor(builder){
261
- super(builder);
262
- }
263
- custom(validator) {
264
- arrLast(this.builder.cmd.meta.argValidators).push(validator);
265
- return this.builder;
266
- }
267
- }
268
-
269
- function realizeLazyProperty(obj, key, value) {
270
- Object.defineProperty(obj, key, {
271
- enumerable: true,
272
- writable: false,
273
- configurable: false,
274
- value
275
- });
276
- return value;
277
- }
278
-
279
- /**
280
- * Wrapper around the @see Argument class from 'commander'.
281
- */ class ArgumentBuilder {
282
- constructor(cmd, name){
283
- this.cmd = cmd;
284
- this.$ = new Argument(name);
285
- this.index = cmd.meta.argValidators.length;
286
- cmd.meta.argValidators[this.index] = [];
287
- }
288
- description(string) {
289
- this.$.description = string;
290
- return this;
291
- }
292
- default(value, description) {
293
- this.$.default(value, description);
294
- return this;
295
- }
296
- choices(values) {
297
- this.$.choices(values);
298
- return this;
299
- }
300
- get parser() {
301
- return new ArgumentParserSelector(this);
302
- }
303
- get validator() {
304
- return new ArgumentValidatorSelector(this);
305
- }
306
- get get() {
307
- return realizeLazyProperty(this, 'get', new ArgumentReader(this));
308
- }
309
- }
310
-
311
- /**
312
- * Creates a function that merges arrays based on a predicate function.
313
- */ function createArrayMerger(predicate) {
314
- return function arrMerge(target, ...sources) {
315
- for (const src of sources){
316
- for(let i = 0; i < src.length; i++){
317
- if (predicate(src[i], i, src)) {
318
- target[i] = src[i];
319
- }
320
- }
321
- }
322
- return target;
323
- };
324
- }
325
-
326
- const arrAssign = createArrayMerger((value)=>value != null);
327
-
328
- /**
329
- * Checks if at least one element in the array satisfies the provided predicate.
330
- * @param predicate The predicate function to apply to each element.
331
- * @template T The type of elements in the input array.
332
- * @returns Returns `true` if at least one element in the array passes the test implemented by the provided function, otherwise `false`.
333
- * @param input The array to check.
334
- * @example ```ts
335
- * const numbers = [1, 2, 3, 4, 5];
336
- * const isEven = (num) => num % 2 === 0;
337
- * arrSome(numbers, isEven);
338
- * //=> true
339
- * ```
340
- */ function arrSome(input, predicate) {
341
- for(let i = 0, len = input.length; i < len; i++){
342
- if (predicate(input[i], i, input) === true) {
343
- return true;
344
- }
345
- }
346
- return false;
347
- }
348
-
349
- /**
350
- * Checks if the provided value is a plain object, i.e. an object created by the native base `Object` constructor.
351
- */ function isPlainObject(value) {
352
- if (Object.prototype.toString.call(value) !== '[object Object]') return false;
353
- if (!value?.constructor) return true;
354
- if (Object.prototype.toString.call(value.constructor.prototype) !== '[object Object]') return false;
355
- if (!Object.prototype.hasOwnProperty.call(value.constructor.prototype, 'isPrototypeOf')) return false;
356
- return true;
357
- }
358
-
359
- /**
360
- * Checks if the provided value is a primitive type (null, undefined, bigint, boolean, number, string or symbol).
361
- * @param value The value to check.
362
- * @returns A boolean indicating whether the provided value is a primitive type.
363
- * @example
364
- * isPrimitive(123);
365
- * //=> true
366
- * isPrimitive({});
367
- * //=> false
368
- */ function isPrimitive(value) {
369
- return typeof value !== 'object' && typeof value !== 'function' || value === null;
370
- }
371
-
372
- /**
373
- * Escapes special characters in a string to be used in a regular expression.
374
- * @param str The input string to escape.
375
- * @returns The escaped string.
376
- * @example ```ts
377
- * const input = 'Hello, world!';
378
- * regexEscapeString(input);;
379
- * //=> 'Hello, world!'
380
- * ```
381
- */ function regexEscapeString(str) {
382
- return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') // $& means the whole matched string
383
- ;
384
- }
385
-
386
- class ErrorParser {
387
- constructor(error){
388
- this.error = error instanceof Error ? error : new Error(String(error));
389
- }
390
- get name() {
391
- return this.error.name;
392
- }
393
- get message() {
394
- return this.error.message;
395
- }
396
- get stack() {
397
- return this.error.stack || '';
398
- }
399
- summary() {
400
- return this.name + ': ' + this.message;
401
- }
402
- parseStackFrames() {
403
- return errParseStack(this.stack);
404
- }
405
- prettyStack(parsedStackFrames) {
406
- return errPrettyStack(this.error, parsedStackFrames);
407
- }
408
- toObject() {
409
- return errToObject(this.error);
410
- }
411
- toJSON() {
412
- return this.toObject();
413
- }
414
- }
415
- function errPrettyStack(error, parsedStackFrames) {
416
- const frames = parsedStackFrames ?? errParseStack(error.stack || '');
417
- // width of the first column = the longest frame.cell string
418
- const offset = 2 + frames.reduce((acc, frame)=>Math.max(acc, frame[0].length), 0);
419
- // type and message
420
- const result = [
421
- colors.bold(colors.red(error.name)) + ': ' + ' '.repeat(Math.max(0, offset - error.name.length)) + colors.red(error.message)
422
- ];
423
- // stack trace
424
- result.push(colors.yellow('stack') + ':');
425
- result.push(frames.map((frame)=>{
426
- const [call, file] = frame;
427
- let s = ' ';
428
- let fp;
429
- if (file.startsWith('node:')) {
430
- s += colors.gray(call);
431
- fp = colors.gray(file);
432
- } else if (file.includes('node_modules')) {
433
- s += call;
434
- const base = path.basename(file.split(':')[0]);
435
- fp = file.replace(base, colors.yellow(base));
436
- } else {
437
- s += call;
438
- const base = path.basename(file.split(':')[0]);
439
- fp = file.replace(base, colors.red(base));
440
- }
441
- s += ' '.repeat(offset - call.length);
442
- s += fp;
443
- return s;
444
- }).join('\n'));
445
- // other properties
446
- const ignore = [
447
- 'name',
448
- 'message',
449
- 'frames',
450
- 'stack'
451
- ];
452
- const keys = Object.getOwnPropertyNames(error).filter((key)=>!ignore.includes(key));
453
- for (const k of keys){
454
- if (typeof k === 'symbol') continue;
455
- const key = k;
456
- let s = colors.yellow(key.toString()) + ': ';
457
- if (isPlainObject(error[key])) {
458
- const json = JSON.stringify(error[key], null, 2);
459
- if (json.length < 350) {
460
- s += JSON.stringify(error[key], null, 2).split('\n').map((line)=>{
461
- const arr = line.split('": ');
462
- arr[0] = colors.gray(arr[0].replace('"', ''));
463
- return arr.join(': ');
464
- }).join('\n');
465
- } else {
466
- s += JSON.stringify(error[key]);
467
- }
468
- } else if (isPrimitive(error[key])) {
469
- s += String(error[key]);
470
- } else if (error[key] != null && typeof error[key] === 'object') {
471
- s += error[key].toString();
472
- } else {
473
- s += JSON.stringify(error[key]);
474
- }
475
- result.push(s.trim());
476
- }
477
- return '\n' + result.join('\n') + '\n';
478
- }
479
- function errParseStack(stack) {
480
- if (!stack) return [];
481
- const nodeRe = /^\s*at (?:((?:\[object object\])?[^\\/]+(?: \[as \S+\])?) )?\(?(.*?):(\d+)(?::(\d+))?\)?\s*$/i;
482
- const recwd = new RegExp('^' + regexEscapeString(process.cwd() + path.sep), 'i');
483
- const frames = [];
484
- for (const line of stack.split('\n')){
485
- const parts = nodeRe.exec(line);
486
- if (!parts) continue;
487
- frames.push([
488
- parts[1] || '<unknown>',
489
- `${(parts[2] || '').replace(recwd, '').replace(/\\\\?/g, '/')}:${+parts[3]}:${parts[4] ? +parts[4] : null}`
490
- ]);
491
- }
492
- return frames;
493
- }
494
- function errToObject(error) {
495
- const own = Object.getOwnPropertyNames(error).filter((key)=>typeof key === 'string');
496
- const keys = new Set([
497
- 'name',
498
- 'message',
499
- 'frames',
500
- ...own
501
- ]);
502
- keys.delete('stack');
503
- const entries = Array.from(keys).filter((key)=>error[key] !== undefined).map((key)=>[
504
- key,
505
- error[key]
506
- ]);
507
- return Object.fromEntries(entries);
508
- } // try {
509
- // throw new TypeError('wow ok oops')
510
- // } catch (error) {
511
- // const err = new ErrorParser(error)
512
- // console.log('----------------------')
513
- // console.log({
514
- // name: err.name,
515
- // message: err.message,
516
- // summary: err.summary,
517
- // })
518
- // console.log('----------------------')
519
- // console.log(err.stack)
520
- // console.log('----------------------')
521
- // console.log(err.prettyStack())
522
- // console.log('----------------------')
523
- // console.log(err.toObject())
524
- // console.log('----------------------')
525
- // }
526
-
527
- /**
528
- * Checks if the given value is a function.
529
- *
530
- * @example ```ts
531
- * isFunction(class {}); //=> true
532
- * isFunction(function () {}); //=> true
533
- * isFunction(() => {}); //=> true
534
- * ```
535
- */ function isFunction(value) {
536
- return typeof value === 'function' && value !== Function.prototype;
537
- }
538
-
539
- /**
540
- * A class that creates an object with methods for disabling/enabling a given method on a given object.
541
- *
542
- * @example
543
- * const md = new MethodDisabler(process.stdout, 'write')
544
- *
545
- * md.disable()
546
- * assert(!md.isEnabled)
547
- * console.log('This will not print')
548
- *
549
- * md.enable()
550
- * assert(md.isEnabled)
551
- * console.log('This will print')
552
- *
553
- * assert(md.original === process.stdout.write)
554
- */ class MethodDisabler {
555
- static #defaultDescriptor(value) {
556
- return {
557
- value,
558
- writable: true,
559
- enumerable: true,
560
- configurable: true
561
- };
562
- }
563
- static #noop = (...args)=>void 0;
564
- static #memoized = new WeakMap();
565
- #obj;
566
- #key;
567
- #original;
568
- #hasOwn;
569
- #originalDescriptor;
570
- #noopDescriptor;
571
- #isEnabled;
572
- /**
573
- * @param obj - The object on which the method is defined.
574
- * @param key - The property name of the method.
575
- */ constructor(obj, key){
576
- this.#isEnabled = true;
577
- ensureThat(obj[key], isFunction);
578
- this.#obj = obj;
579
- this.#key = key;
580
- this.#original = obj[key];
581
- this.#hasOwn = Object.hasOwn(obj, key);
582
- this.#originalDescriptor = this.#hasOwn ? Object.getOwnPropertyDescriptor(obj, key) : MethodDisabler.#defaultDescriptor(this.#original);
583
- this.#noopDescriptor = Object.assign({}, this.#originalDescriptor, {
584
- value: MethodDisabler.#noop
585
- });
586
- // return stored if memoized
587
- if (MethodDisabler.#memoized.get(obj)?.has(key)) {
588
- return MethodDisabler.#memoized.get(obj)?.get(key);
589
- }
590
- //memoize
591
- if (!MethodDisabler.#memoized.has(obj)) MethodDisabler.#memoized.set(obj, new Map());
592
- const methods = MethodDisabler.#memoized.get(obj);
593
- methods.set(key, this);
594
- }
595
- /**
596
- * Disable the method.
597
- */ disable() {
598
- if (!this.isEnabled) return;
599
- Object.defineProperty(this.#obj, this.#key, this.#noopDescriptor);
600
- this.#isEnabled = false;
601
- }
602
- /**
603
- * Enable the method.
604
- */ enable() {
605
- if (this.isEnabled) return;
606
- if (this.#hasOwn) Object.defineProperty(this.#obj, this.#key, this.#originalDescriptor);
607
- else delete this.#obj[this.#key];
608
- this.#isEnabled = true;
609
- }
610
- /**
611
- * The original method before it was disabled.
612
- */ get original() {
613
- return this.#original;
614
- }
615
- /**
616
- * Whether the method is currently enabled.
617
- */ get isEnabled() {
618
- return this.#isEnabled;
619
- }
620
- }
621
-
622
- /**
623
- * The OutputManager class manages the output of debug messages to the console.
624
- */ class OutputManager {
625
- /**
626
- * Returns the singleton instance of the OutputManager class.
627
- * If the instance does not exist, it creates a new one.
628
- */ static getInstance() {
629
- if (!this.instance) this.instance = new OutputManager();
630
- return this.instance;
631
- }
632
- /**
633
- * Constructs a new instance of the OutputManager class.
634
- * console.debug is disabled by default.
635
- */ constructor(){
636
- /**
637
- * Ansi-colors object
638
- */ this.colors = colors;
639
- /**
640
- * A MethodDisabler instance for disabling the write method of the process.stdout object.
641
- */ this.stdout = new MethodDisabler(process.stdout, 'write');
642
- /**
643
- * A MethodDisabler instance for disabling the write method of the process.stderr object.
644
- */ this.stderr = new MethodDisabler(process.stderr, 'write');
645
- /**
646
- * A MethodDisabler instance for disabling the debug method of the console object.
647
- */ this.debug = new MethodDisabler(console, 'debug');
648
- /**
649
- * An array that holds queued debug messages.
650
- */ this.debugMsgQueue = [];
651
- this.debug.disable();
652
- colors.enabled = (()=>{
653
- const { FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env;
654
- return !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== 'dumb' && (FORCE_COLOR != null && FORCE_COLOR !== '0' || process.stdout && process.stdout.isTTY);
655
- })();
656
- }
657
- get queueSize() {
658
- return this.debugMsgQueue.length;
659
- }
660
- /**
661
- * Resets the OutputManager to its default state.
662
- * - Enables colors.
663
- * - Enables the write method of the process.stdout object.
664
- * - Enables the write method of the process.stderr object.
665
- * - Disables the debug method of the console object.
666
- * @returns The OutputManager instance.
667
- */ reset() {
668
- this.colors.enabled = true;
669
- this.stdout.enable();
670
- this.stderr.enable();
671
- this.debug.disable();
672
- return this;
673
- }
674
- /**
675
- * Outputs a debug message to the console.
676
- * If the debug method is enabled, the message is immediately logged to the console.
677
- * Otherwise, the message is added to the debug message queue.
678
- * @param fn - A function that returns the debug message.
679
- */ outputDebug(fn) {
680
- if (this.debug.isEnabled) console.debug(fn());
681
- else this.debugMsgQueue.push(fn);
682
- }
683
- /**
684
- * Drains the debug message queue by logging all the messages to the console.
685
- */ drainDebugMessageQueue() {
686
- this.debugMsgQueue.forEach((fn)=>console.debug(fn()));
687
- this.debugMsgQueue.splice(0, this.debugMsgQueue.length);
688
- }
689
- }
690
-
691
- class CommandBuilderMetaData {
692
- get actionHandler() {
693
- return async function defaultActionHandler() {
694
- this.outputHelp();
695
- };
696
- }
697
- get errorHandler() {
698
- return function defaultErrorHandler(error) {
699
- const parsed = new ErrorParser(error);
700
- if (OutputManager.getInstance().debug.isEnabled) {
701
- console.error(parsed.prettyStack());
702
- this.outputError(parsed.summary());
703
- } else {
704
- this.outputError(parsed.summary());
705
- }
706
- };
707
- }
708
- get hasCustomActionHandler() {
709
- return Object.hasOwn(this, 'actionHandler');
710
- }
711
- get hasCustomErrorHandler() {
712
- return Object.hasOwn(this, 'errorHandler');
713
- }
714
- constructor(){
715
- this.subcommands = [];
716
- this.globalOptions = [];
717
- this.hiddenGlobalOptions = new Set();
718
- this.presetOptionKeys = [];
719
- this.argParsers = [];
720
- this.argValidators = [];
721
- this.optParsers = {};
722
- this.optValidators = {};
723
- this.rawArgs = [];
724
- this.isNative = false;
725
- this.isInitialized = false;
726
- }
727
- }
728
-
729
- function splitCombinedArgvShorts(argv) {
730
- return argv.map((arg)=>{
731
- if (arg.length < 3 || !arg.startsWith('-') || arg.startsWith('--') || arg.includes('=')) {
732
- return arg;
733
- }
734
- return Array.from(arg.replace('-', '')).map((s)=>'-' + s);
735
- }).flat();
736
- }
737
-
738
- const commanderBackRefs = new WeakMap();
739
- const oldParse = Command.prototype.parse;
740
- Command.prototype.parse = function parse(argv, options) {
741
- if (argv) {
742
- argv = splitCombinedArgvShorts(argv.slice());
743
- this.builder.meta.rawArgs = argv.slice(options?.from === 'user' ? 0 : 2);
744
- } else {
745
- this.builder.meta.rawArgs = process.argv.slice(2);
746
- }
747
- return oldParse.call(this, argv, options);
748
- };
749
- const oldParseAsync = Command.prototype.parseAsync;
750
- Command.prototype.parseAsync = async function(argv, options) {
751
- if (argv) {
752
- argv = splitCombinedArgvShorts(argv.slice());
753
- this.builder.meta.rawArgs = argv.slice(options?.from === 'user' ? 0 : 2);
754
- } else {
755
- this.builder.meta.rawArgs = process.argv.slice(2);
756
- }
757
- return await oldParseAsync.call(this, argv, options);
758
- };
759
- Object.defineProperty(Command.prototype, 'builder', {
760
- get () {
761
- const ins = commanderBackRefs.get(this);
762
- if (!ins) throw new Error(`CommandBuilder not found for command ${this.name()}`);
763
- return ins;
764
- }
765
- });
766
-
767
- /**
768
- * Represents a selector for enabling or disabling command features.
769
- */ class CommandFeatureSelector {
770
- /**
771
- * Creates a new instance of the CommandFeatureSelector class.
772
- * @param cmd - The command builder instance.
773
- */ constructor(cmd){
774
- this.cmd = cmd;
775
- this./**
776
- * Indicates whether the app data feature is enabled.
777
- */ isAppDataEnabled = false;
778
- this./**
779
- * Indicates whether the config feature is enabled.
780
- */ isConfigEnabled = false;
781
- this./**
782
- * Indicates whether the presets feature is enabled.
783
- */ isPresetsEnabled = false;
784
- this./**
785
- * Indicates whether the auto assign missing option flags feature is enabled.
786
- */ isAutoAssignMissingOptionFlagsEnabled = false;
787
- this./**
788
- * Indicates whether the auto assign sub command aliases feature is enabled.
789
- */ isAutoAssignSubCommandAliasesEnabled = false;
790
- }
791
- /**
792
- * Inherits the feature settings from a parent CommandFeatureSelector instance.
793
- * @param parentFeatures - The parent CommandFeatureSelector instance to inherit from.
794
- */ inheritFrom(parentFeatures) {
795
- if (!parentFeatures) return;
796
- if (this.cmd.meta.isNative) this.isAutoAssignMissingOptionFlagsEnabled = true;
797
- else this.isAutoAssignMissingOptionFlagsEnabled = parentFeatures.isAutoAssignMissingOptionFlagsEnabled;
798
- this.isAutoAssignSubCommandAliasesEnabled = parentFeatures.isAutoAssignSubCommandAliasesEnabled;
799
- this.isPresetsEnabled = parentFeatures.isPresetsEnabled;
800
- }
801
- /**
802
- * Enables or disables the app data feature.
803
- * @param boolean - Indicates whether the app data feature should be enabled or disabled.
804
- * @returns The current CommandFeatureSelector instance.
805
- * @throws Error if the command is native and the app data feature is being configured.
806
- */ appData(boolean = true) {
807
- return this.setProperty(boolean, 'isAppDataEnabled', 'appData', true);
808
- }
809
- /**
810
- * Enables or disables the config feature.
811
- * @param boolean - Indicates whether the config feature should be enabled or disabled.
812
- * @returns The current CommandFeatureSelector instance.
813
- * @throws Error if the command is native and the config feature is being configured.
814
- */ config(boolean = true) {
815
- return this.setProperty(boolean, 'isConfigEnabled', 'config', true);
816
- }
817
- /**
818
- * Enables or disables the presets feature.
819
- * @param boolean - Indicates whether the presets feature should be enabled or disabled.
820
- * @returns The current CommandFeatureSelector instance.
821
- * @throws Error if the command is native and the presets feature is being configured.
822
- */ presets(boolean = true) {
823
- return this.setProperty(boolean, 'isPresetsEnabled', 'presets', true);
824
- }
825
- /**
826
- * Enables or disables the auto assign missing option flags feature.
827
- * @param boolean - Indicates whether the auto assign missing option flags feature should be enabled or disabled.
828
- * @returns The current CommandFeatureSelector instance.
829
- */ autoAssignMissingOptionFlags(boolean = true) {
830
- return this.setProperty(boolean, 'isAutoAssignMissingOptionFlagsEnabled', 'autoAssignMissingOptionFlags', false);
831
- }
832
- /**
833
- * Enables or disables the auto assign sub command aliases feature.
834
- * @param boolean - Indicates whether the auto assign sub command aliases feature should be enabled or disabled.
835
- * @returns The current CommandFeatureSelector instance.
836
- */ autoAssignSubCommandAliases(boolean = true) {
837
- return this.setProperty(boolean, 'isAutoAssignSubCommandAliasesEnabled', 'autoAssignSubCommandAliases', false);
838
- }
839
- /**
840
- * Helper method to enable or disable a feature.
841
- * @param boolean - Indicates whether the auto assign sub command aliases feature should be enabled or disabled.
842
- * @param prop - The property name to set.
843
- * @param method - The method name to output in the debug message.
844
- * @param throwIfNative - Indicates whether an error should be thrown if the command is native.
845
- * @returns The current CommandFeatureSelector instance.
846
- */ setProperty(boolean = true, prop, method, throwIfNative) {
847
- if (this[prop] === boolean) return this;
848
- if (throwIfNative && this.cmd.meta.isNative) throw new Error(`Cannot configure ${method} for native command.`);
849
- Object.defineProperty(this, prop, {
850
- value: boolean,
851
- configurable: true,
852
- writable: true,
853
- enumerable: true
854
- });
855
- this.cmd.outputDebugMessage('featureEnabled', ()=>({
856
- [method]: boolean
857
- }));
858
- return this;
859
- }
860
- }
861
-
862
- const DefaultHelpConfig = {
863
- helpWidth: undefined,
864
- showGlobalOptions: true,
865
- sortSubcommands: false,
866
- sortOptions: false,
867
- subcommandTerm,
868
- argumentTerm,
869
- commandUsage,
870
- visibleOptions,
871
- visibleGlobalOptions,
872
- subcommandDescription,
873
- optionDescription,
874
- argumentDescription,
875
- commandDescription,
876
- formatHelp
877
- };
878
- function formatHelp(cmd) {
879
- let result = Help.prototype.formatHelp.call(this, cmd, this);
880
- result = movePresetOptionsUnderOwnHeader(result);
881
- result = rearrangeSections(result);
882
- result = fixLinebreaks(result);
883
- result = addColors(result);
884
- return result;
885
- function movePresetOptionsUnderOwnHeader(result) {
886
- const lines = result.split('\n');
887
- const presetLines = lines.filter((line)=>line.includes('[Preset]:'));
888
- const firstPresetIndex = lines.findIndex((line)=>line.includes('[Preset]'));
889
- if (firstPresetIndex !== -1) {
890
- lines.splice(firstPresetIndex, presetLines.length);
891
- lines.push('', 'Preset Options:', ...presetLines);
892
- result = lines.join('\n');
893
- }
894
- return result;
895
- }
896
- function rearrangeSections(result) {
897
- const order = [
898
- 'Usage:',
899
- 'Version:',
900
- 'Description:',
901
- 'Commands:',
902
- 'Arguments:',
903
- 'Options:',
904
- 'Global Options:',
905
- 'Preset Options:'
906
- ];
907
- const blocks = {};
908
- let lastAddedBlock = 'Description:';
909
- result.split(/\n\n+/).forEach((block)=>{
910
- const title = block.split(':')[0].trim() + ':';
911
- if (/^[A-Z][\w ]+:/.test(title)) {
912
- blocks[title] = block;
913
- lastAddedBlock = title;
914
- if (!order.includes(title)) order.push(title);
915
- } else {
916
- if (!order.includes(lastAddedBlock)) order.push(lastAddedBlock);
917
- blocks[lastAddedBlock] = ((blocks[lastAddedBlock] || '') + '\n\n' + block).trim();
918
- }
919
- });
920
- result = order.map((title)=>blocks[title]).join('\n\n').trim();
921
- return result;
922
- }
923
- function fixLinebreaks(result) {
924
- result = '\n' + result.trim() + '\n\n';
925
- result = result.replace(/\n\n+/g, '\n\n');
926
- return result;
927
- }
928
- function addColors(result) {
929
- result = result.replace(/\|/g, colors.gray(colors.dim('|')));
930
- result = result.replace(/^[A-Z][\w ]+:/gm, (s)=>colors.yellow(s));
931
- return result;
932
- }
933
- }
934
- function subcommandTerm(cmd) {
935
- const args = cmd.registeredArguments.map((arg)=>this.argumentTerm(arg)).join(' ');
936
- const parent = cmd.parent || cmd;
937
- const hasAliases = !cmd.parent || parent.commands.some((c)=>!!c.alias());
938
- if (!hasAliases) return cmd.name() + (args ? ' ' + args : '');
939
- const padsize = Math.max(1, ...parent.commands.map((c)=>c.alias()?.length || 1));
940
- let alias = cmd.alias() || ' ';
941
- alias = alias.padEnd(padsize, ' ') + ' |';
942
- return alias + cmd.name() + (args ? ' ' + args : '');
943
- }
944
- function argumentTerm(arg) {
945
- let r = arg.name();
946
- const rest = arg.variadic ? '...' : '';
947
- if (arg.required) r = '<' + r + rest + '>';
948
- else r = '[' + r + rest + ']';
949
- return r;
950
- }
951
- function commandUsage(cmd) {
952
- const args = cmd.registeredArguments.map((arg)=>this.argumentTerm(arg)).join(' ');
953
- return [
954
- cmd.builder.getPrefixString() + ' ' + (args ? args : '[command]'),
955
- '[options]'
956
- ].join(' ');
957
- }
958
- function visibleOptions(cmd) {
959
- const builder = cmd.builder;
960
- const opts = cmd.options.filter((opt)=>!opt.hidden && !builder.meta.globalOptions.includes(opt));
961
- const presets = opts.filter((opt)=>opt.description.startsWith('[Preset]'));
962
- return opts.filter((opt)=>!presets.includes(opt)).concat(presets);
963
- }
964
- function visibleGlobalOptions(cmd) {
965
- const gopts = cmd.builder.getGlobalOptions();
966
- if (gopts.find((opt)=>opt.long === '--help')) return gopts;
967
- const help = cmd.options.find((opt)=>opt.long === '--help');
968
- if (help) gopts.push(help);
969
- return gopts;
970
- }
971
- function subcommandDescription(cmd) {
972
- return colors.gray(Help.prototype.subcommandDescription.call(this, cmd));
973
- }
974
- function optionDescription(opt) {
975
- return colors.gray(Help.prototype.optionDescription.call(this, opt));
976
- }
977
- function argumentDescription(arg) {
978
- return colors.gray(Help.prototype.argumentDescription.call(this, arg));
979
- }
980
- function commandDescription(cmd) {
981
- const v = cmd.builder.getVersion();
982
- const version = v ? colors.yellow('Version: ') + v + '\n\n' : '';
983
- const description = 'Description:\n' + Help.prototype.commandDescription.call(this, cmd);
984
- return version + description;
985
- }
986
-
987
- function formatTableForTerminal(rows, headers) {
988
- if (!rows.length || !rows[0].length) return '';
989
- const table = new Table();
990
- if (headers && headers.length) {
991
- table.push(headers.map((s)=>colors.bold(colors.yellow(s))));
992
- }
993
- for (const row of rows)table.push(row);
994
- return table.toString();
995
- }
996
-
997
- const isArray = Array.isArray;
998
-
999
- /**
1000
- * Checks if the provided value is an object (null, arrays and functions not included).
1001
- * @template T - The type of the value to check.
1002
- * @param value The value to check.
1003
- * @returns A boolean indicating whether the provided value is an object.
1004
- * @example ```ts
1005
- * isObject({});;
1006
- * //=> true
1007
- * isObject([1]);;
1008
- * //=> false
1009
- * isObject(123);;
1010
- * //=> false
1011
- * ```
1012
- */ function isObject(value) {
1013
- return value != null && typeof value === 'object' && !Array.isArray(value);
1014
- }
1015
-
1016
- /**
1017
- * Determine whether the input is a string array.
1018
- */ function isStringArray(value) {
1019
- return Array.isArray(value) && value.every((v)=>isString(v));
1020
- }
1021
-
1022
- function isStringWithNoSpacesOrDashes(value) {
1023
- return isString(value) && /^[^\s-]+$/i.test(value);
1024
- }
1025
-
1026
- /**
1027
- * Checks if the current platform is OSX.
1028
- * It checks the 'process' object and the 'platform' property to determine if the platform is 'darwin'.
1029
- * @returns A boolean indicating whether the current platform is OSX.
1030
- */ function isOSX() {
1031
- return process.platform === 'darwin';
1032
- }
1033
-
1034
- /**
1035
- * Returns whether Visual Studio Code is installed on the system.
1036
- * @example isVsCodeInstalled() //=> true
1037
- */ function isVsCodeInstalled() {
1038
- try {
1039
- const stdout = execSync('code --help').toString();
1040
- return stdout.startsWith('Visual Studio Code') && stdout.includes('-w --wait');
1041
- } catch (e) {
1042
- return false;
1043
- }
1044
- }
1045
-
1046
- /**
1047
- * Checks if the current platform is Windows.
1048
- * @remarks
1049
- * It checks the 'process' object and the 'platform' property to determine if the platform is 'win32'.
1050
- * It also checks the 'OSTYPE' environment variable to see if it matches 'msys' or 'cygwin'.
1051
- * @returns A boolean indicating whether the current platform is Windows.
1052
- */ function isWindows() {
1053
- return isWin;
1054
- }
1055
- const isWin = process && (process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env['OSTYPE'] || ''));
1056
-
1057
- /**
1058
- * Get the default command to open a file in in a text editor.
1059
- * If VSCode is installed, this is used. Otherwise, the default text editor of the OS is used.
1060
- */ function defaultOpenInEditorCommand() {
1061
- if (!COMMAND) COMMAND = isVsCodeInstalled() ? 'code -w' : isWindows() ? 'notepad' : isOSX() ? 'open vi' : 'xdg-open';
1062
- return COMMAND;
1063
- }
1064
- let COMMAND = '';
1065
-
1066
- /**
1067
- * Reads a file and returns the file's contents.
1068
- * Identical to fs.readFileSync, except that it uses utf8 encoding by default.
1069
- *
1070
- * @param filepath - The path to the file.
1071
- * @param encoding - The encoding to use when reading the file.
1072
- * @returns The file's contents.
1073
- */ function readFileSync(filepath, encoding = 'utf8') {
1074
- return fs.readFileSync(filepath, encoding);
1075
- }
1076
-
1077
- /**
1078
- * Ensures that a string starts with a specified substring. If the string already starts with the specified substring, it is returned as is. Otherwise, the substring is appended to the end of the string.
1079
- * @param string The string to be processed.
1080
- * @param startsWith The substring that the string should end with.
1081
- * @example ```ts
1082
- * strEnsureStartsWith('json', '.');
1083
- * //=> '.json'
1084
- * strEnsureStartsWith('.json', '.');
1085
- * //=> '.json'
1086
- * ```
1087
- */ function strEnsureStartsWith(string, startsWith) {
1088
- return string.startsWith(startsWith) ? string : startsWith + string;
1089
- }
1090
-
1091
- /**
1092
- * Returns a path to the os tmpdir location.
1093
- *
1094
- * @param paths - The paths to join to the os tmpdir location.
1095
- */ function getTempDataPath(...paths) {
1096
- return path.join(tempdir, ...paths);
1097
- }
1098
- const tempdir = fs.realpathSync(os.tmpdir());
1099
-
1100
- /**
1101
- * Syncrhonously creates a temporary file and deletes it after the callback has finished.
1102
- * @param fileExtension - The file extension to use for the temporary file.
1103
- * @param callback - The callback to execute with the temporary file path. The callback can return a promise and the temporary file will not be deleted until the promise has resolved or rejected.
1104
- */ function tempFileSync(fileExtension, callback) {
1105
- const fpath = getTempDataPath('temp', Date.now() + strEnsureStartsWith(fileExtension, '.'));
1106
- fs.ensureFileSync(fpath);
1107
- try {
1108
- const retval = callback(fpath);
1109
- fs.remove(fpath);
1110
- return retval;
1111
- } catch (error) {
1112
- fs.remove(fpath);
1113
- }
1114
- }
1115
-
1116
- /**
1117
- * Prompts the user to edit a string in the user's text editor.
1118
- *
1119
- * @example ```ts
1120
- * promptUserEditInTextEditor({ editor: 'notepad' })
1121
- * ```
1122
- */ function promptUserEditInTextEditorSync(options) {
1123
- const { editor, content, extension } = applyDefaults(options);
1124
- return tempFileSync(extension, (tempfile)=>{
1125
- writeFileSync(tempfile, content);
1126
- execSync(`${editor} ${tempfile}`, {
1127
- stdio: 'inherit'
1128
- });
1129
- return readFileSync(tempfile);
1130
- });
1131
- }
1132
- function applyDefaults(options = {}) {
1133
- const content = options.content ?? '';
1134
- const extension = strEnsureStartsWith(options.extension ?? '.txt', '.');
1135
- const editor = options.editor ?? defaultOpenInEditorCommand();
1136
- return {
1137
- content,
1138
- extension,
1139
- editor
1140
- };
1141
- }
1142
-
1143
- /**
1144
- * Edit a JSON-stringify-compatible value in the user's editor and return the (JSON.parse'd) result.
1145
- *
1146
- * @param value - The value to edit (NOT a json string). Defaults to an empty object.
1147
- * @param editor - Launch command to start your editor. Defaults to VSCode: 'code -w' (if installed).
1148
- * - Otherwise this logic: isWindows() ? 'notepad' : isOSX() ? 'open vi' : 'xdg-open'
1149
- *
1150
- * @example ```ts
1151
- * promptUserEditJsonInTextEditorSync([1, 2])
1152
- * ```
1153
- */ function promptUserEditJsonInTextEditorSync(value = {}, editor) {
1154
- const json = promptUserEditInTextEditorSync({
1155
- editor,
1156
- content: JSON.stringify(value, null, 2),
1157
- extension: '.json'
1158
- });
1159
- return JSON.parse(json);
1160
- }
1161
-
1162
- /**
1163
- * A class that represents a section of the JSON file used as a simple database.
1164
- */ class AbstractJsonFileSection {
1165
- /**
1166
- * Creates an instance of AbstractJsonFileSection.
1167
- * @param file - The parent JsonFile instance.
1168
- * @param name - The name of the section.
1169
- * @param keysAreFixed - Indicates whether the keys in the section are fixed.
1170
- */ constructor(file, name, keysAreFixed){
1171
- this.file = file;
1172
- this.name = name;
1173
- this.keysAreFixed = keysAreFixed;
1174
- this.isInitialized = false;
1175
- this.defaultValues = {};
1176
- this.prefixBaseString = file.cmd.getPrefixArray().join('_');
1177
- }
1178
- /**
1179
- * The JsonDB associated with the section.
1180
- */ get db() {
1181
- return this.file.db;
1182
- }
1183
- /**
1184
- * The CommandBuilder associated with the section.
1185
- */ get cmd() {
1186
- return this.file.cmd;
1187
- }
1188
- /**
1189
- * Saves the section.
1190
- * @returns A promise that resolves when the section is saved.
1191
- */ async save() {
1192
- return await this.db.save();
1193
- }
1194
- /**
1195
- * Gets the object path prefix as dot-separated keys for this section of the JSON file database.
1196
- * @param key - An optional key to append to the prefix path.
1197
- * @returns The object path prefix.
1198
- * @throws An error if the keys are fixed and the specified key does not exist in the default values.
1199
- */ prefix(key) {
1200
- if (this.keysAreFixed && key && !Object.hasOwn(this.defaultValues, key)) {
1201
- throw new Error(`No entry with key '${key}'`);
1202
- }
1203
- return this.prefixBaseString + '.' + this.name + (key ? '.' + key : '');
1204
- }
1205
- /**
1206
- * Gets the value associated with the specified key.
1207
- * @param key - The key to get the value for.
1208
- * @returns The value associated with the key.
1209
- */ get(key) {
1210
- this.initialize(false);
1211
- return this.db.getSafe(this.prefix(key)) ?? this.defaultValues[key];
1212
- }
1213
- /**
1214
- * Gets all the values in the section.
1215
- * @returns All the values in the section.
1216
- */ getAll() {
1217
- this.initialize(false);
1218
- return this.db.getSafe(this.prefix()) ?? JSON.parse(JSON.stringify(this.defaultValues));
1219
- }
1220
- /**
1221
- * Gets the keys in the section.
1222
- * @returns The keys in the section.
1223
- */ get keys() {
1224
- // if (this.keysAreFixed) return Object.keys(this.defaultValues)
1225
- return Object.keys(this.getAll());
1226
- }
1227
- /**
1228
- * Gets the number of keys in the section.
1229
- * @returns The number of keys in the section.
1230
- */ count() {
1231
- return this.keys.length;
1232
- }
1233
- /**
1234
- * Sets the value associated with the specified key.
1235
- * @param key - The key to set the value for.
1236
- * @param value - The value to set.
1237
- * @param save - Indicates whether to save the section after setting the value.
1238
- */ set(key, value, save = true) {
1239
- this.initialize();
1240
- this.assertValid(key, value);
1241
- this.db.set(this.prefix(key), value, save);
1242
- }
1243
- /**
1244
- * Sets all the values in the section.
1245
- * @param values - The values to set.
1246
- * @param save - Indicates whether to save the section after setting the values.
1247
- */ setAll(values, save = true) {
1248
- const original = this.getAll();
1249
- for (const [key, value] of Object.entries(values)){
1250
- if (value === original[key]) continue;
1251
- if (JSON.stringify(value) === JSON.stringify(original[key])) continue;
1252
- this.set(key, value, false);
1253
- }
1254
- if (!this.keysAreFixed) {
1255
- for (const name of Object.keys(original)){
1256
- if (Object.hasOwn(values, name)) continue;
1257
- this.delete(name, false);
1258
- }
1259
- }
1260
- if (save) this.save();
1261
- }
1262
- /**
1263
- * Updates the value associated with the specified key.
1264
- * @param key - The key to set the value for.
1265
- * @param callback - The callback function that returns the new value.
1266
- * @param save - Indicates whether to save the section after setting the value.
1267
- */ update(key, callback, save = true) {
1268
- this.set(key, callback(this.get(key), key), save);
1269
- }
1270
- /**
1271
- * Resets the value associated with the specified key to its default value.
1272
- * @param key - The key to reset.
1273
- * @param save - Indicates whether to save the section after resetting the value.
1274
- */ reset(key, save = true) {
1275
- this.set(key, this.defaultValues[key], save);
1276
- }
1277
- /**
1278
- * Resets all the values in the section to their default values.
1279
- * @param save - Indicates whether to save the section after resetting the values.
1280
- */ resetAll(save = true) {
1281
- this.setAll(this.defaultValues, save);
1282
- }
1283
- /**
1284
- * Deletes the value associated with the specified key.
1285
- * @param key - The key to delete.
1286
- * @param save - Indicates whether to save the section after deleting the value.
1287
- */ delete(key, save = true) {
1288
- this.initialize();
1289
- this.db.delete(this.prefix(key), save);
1290
- }
1291
- /**
1292
- * Deletes all the values in the section.
1293
- * @param save - Indicates whether to save the section after deleting the values.
1294
- */ deleteAll(save = true) {
1295
- for (const key of this.keys){
1296
- this.delete(key, false);
1297
- }
1298
- if (save) this.save();
1299
- }
1300
- /**
1301
- * Edits the values in the section using a text editor.
1302
- * @param editor - The text editor to use. If not specified, the default text editor command will be used.
1303
- */ edit(editor) {
1304
- const original = this.getAll();
1305
- const parsed = promptUserEditJsonInTextEditorSync(original, editor || defaultOpenInEditorCommand());
1306
- this.setAll(parsed);
1307
- }
1308
- }
1309
-
1310
- /**
1311
- * A class that represents the appdata section of the JSON file used as simple database.
1312
- */ class AppDataSection extends AbstractJsonFileSection {
1313
- /**
1314
- * Creates an instance of AppDataSection.
1315
- * @param file - The parent JsonFile instance.
1316
- * @param name - The name of the section.
1317
- */ constructor(file, name){
1318
- super(file, name, false);
1319
- }
1320
- /**
1321
- * Does nothing
1322
- */ assertValid() {
1323
- return;
1324
- }
1325
- /**
1326
- * Defines a property for the section.
1327
- * @param key - The key of the property.
1328
- */ defineProperty(key, value) {
1329
- if (typeof value === 'object') value = JSON.parse(JSON.stringify(value));
1330
- this.defaultValues[key] = value;
1331
- this.isInitialized = false;
1332
- }
1333
- /**
1334
- * Initializes the section.
1335
- * @param save - Indicates whether to save the section after initialization.
1336
- * @returns A string if an error occurred during initialization, otherwise void.
1337
- */ initialize(save = false) {
1338
- if (this.isInitialized) return;
1339
- const data = this.db.getSafe(this.prefix());
1340
- if (!data) this.db.set(this.prefix(), this.defaultValues, save);
1341
- this.isInitialized = true;
1342
- }
1343
- }
1344
-
1345
- /**
1346
- * Creates a function that merges objects based on a predicate function.
1347
- */ function createObjectMerger(predicate) {
1348
- return function objMerge(target, ...sources) {
1349
- for (const src of sources){
1350
- for (const [key, value] of Object.entries(src)){
1351
- if (predicate(value, key, src)) {
1352
- target[key] = value;
1353
- }
1354
- }
1355
- }
1356
- return target;
1357
- };
1358
- }
1359
-
1360
- const objAssign = createObjectMerger((value)=>value != null);
1361
-
1362
- /**
1363
- * A class that represents the user-config section of the JSON file used as simple database.
1364
- */ class ConfigSection extends AbstractJsonFileSection {
1365
- /**
1366
- * Creates an instance of AbstractJsonFileSection.
1367
- * @param file - The parent JsonFile instance.
1368
- * @param name - The name of the section.
1369
- */ constructor(file, name){
1370
- super(file, name, true);
1371
- /**
1372
- * String parsers for when editing config from command-line.
1373
- */ this.parsers = {};
1374
- /**
1375
- * Descriptions for each property key.
1376
- */ this.descriptions = {};
1377
- /**
1378
- * Validators for each property key.
1379
- */ this.validators = {};
1380
- }
1381
- /**
1382
- * Asserts that a key-value pair is valid.
1383
- * @param key - The key to assert.
1384
- * @param value - The value to assert.
1385
- */ assertValid(key, value) {
1386
- if (!this.validators[key]) return;
1387
- ensureThat(value, this.validators[key]);
1388
- }
1389
- /**
1390
- * Defines a property for the section.
1391
- * @param key - The key of the property.
1392
- * @param options - The options for the property.
1393
- */ defineProperty(key, options) {
1394
- const { description, defaultValue, parse, validate } = options;
1395
- this.descriptions[key] = description;
1396
- this.defaultValues[key] = typeof defaultValue === 'object' ? JSON.parse(JSON.stringify(defaultValue)) : defaultValue;
1397
- if (parse) this.parsers[key] = parse;
1398
- if (validate) this.validators[key] = validate;
1399
- this.assertValid(key, options.defaultValue);
1400
- }
1401
- /**
1402
- * Initializes the section.
1403
- * @param save - Indicates whether to save the section after initialization.
1404
- * @returns A string if an error occurred during initialization, otherwise void.
1405
- */ initialize(save = false) {
1406
- if (this.isInitialized) return;
1407
- const data = this.db.getSafe(this.prefix());
1408
- const result = objAssign({}, JSON.parse(JSON.stringify(this.defaultValues)), data || {});
1409
- this.db.set(this.prefix(), result, save);
1410
- this.isInitialized = true;
1411
- }
1412
- }
1413
-
1414
- /**
1415
- * Reads a JSON file and then parses it into an object.
1416
- * If an error occurs, it returns undefined.
1417
- *
1418
- * @param filepath - The path to the JSON file.
1419
- * @param options - Options for reading the JSON file.
1420
- */ function readJsonFileSafeSync(filepath, options) {
1421
- try {
1422
- return fs.readJsonSync(filepath, options);
1423
- } catch (error) {
1424
- return undefined;
1425
- }
1426
- }
1427
-
1428
- /**
1429
- * Represents a simple JSON file database.
1430
- */ class JsonDB {
1431
- /**
1432
- * Creates a new instance of the JsonDB class.
1433
- * @param filepath - The filepath where the data file is stored or to be stored.
1434
- */ constructor(filepath, indents = 0){
1435
- this.filepath = filepath;
1436
- this.indents = indents;
1437
- this.data = readJsonFileSafeSync(this.filepath) ?? {};
1438
- }
1439
- /**
1440
- * Saves the data to the JSON file.
1441
- */ async save(indents = this.indents) {
1442
- return await outputJson(this.filepath, this.data, {
1443
- spaces: indents
1444
- });
1445
- }
1446
- /**
1447
- * Sets the filepath of the JSON file.
1448
- * @param filepath - The new filepath.
1449
- */ setFilepath(filepath, save = true) {
1450
- if (this.filepath === filepath) return;
1451
- this.filepath = filepath;
1452
- if (save) this.save();
1453
- }
1454
- /**
1455
- * Sets a value in the JSON database.
1456
- * @param prefix - Object path prefix as dot-separated keys.
1457
- * @param value - The value to set.
1458
- * @param save - Whether to save the data to the JSON file.
1459
- */ set(prefix, value = {}, save = true) {
1460
- if (!prefix) {
1461
- this.data = ensureThat(value, isObject);
1462
- } else {
1463
- const keys = prefix.split('.');
1464
- const lastKey = keys.pop();
1465
- let node = this.data;
1466
- for (const key of keys){
1467
- if (!Object.hasOwn(node, key)) {
1468
- node[key] = {};
1469
- }
1470
- node = node[key];
1471
- }
1472
- node[lastKey] = this.cloneDeep(value);
1473
- }
1474
- if (save) this.save();
1475
- }
1476
- /**
1477
- * Gets a value from the JSON database.
1478
- * @param prefix - Object path prefix as dot-separated keys.
1479
- * @returns The value associated with the key.
1480
- * @throws An error if no entry is found at the specified key.
1481
- */ get(prefix) {
1482
- const value = this.getSafe(prefix);
1483
- if (value === undefined) throw new Error(`No entry at '${prefix}'`);
1484
- return this.cloneDeep(value);
1485
- }
1486
- /**
1487
- * Gets a value from the JSON database safely.
1488
- * @param prefix - Object path prefix as dot-separated keys.
1489
- * @returns The value associated with the key, or undefined if no entry is found.
1490
- */ getSafe(prefix) {
1491
- if (!prefix) return this.cloneDeep(this.data);
1492
- const keys = prefix.split('.');
1493
- let node = this.data;
1494
- for (const key of keys){
1495
- if (!Object.hasOwn(node, key)) {
1496
- return undefined;
1497
- }
1498
- node = node[key];
1499
- }
1500
- return this.cloneDeep(node);
1501
- }
1502
- /**
1503
- * Checks if a key exists in the JSON database.
1504
- * @param prefix - Object path prefix as dot-separated keys.
1505
- * @returns True if the key exists, false otherwise.
1506
- */ has(prefix) {
1507
- if (!prefix) return true;
1508
- return this.getSafe(prefix) !== undefined;
1509
- }
1510
- /**
1511
- * Deletes a value from the JSON database.
1512
- * @param prefix - Object path prefix as dot-separated keys.
1513
- * @param save - Whether to save the data to the JSON file.
1514
- */ delete(prefix, save = true) {
1515
- if (!prefix) {
1516
- this.data = {};
1517
- } else {
1518
- const keys = prefix.split('.');
1519
- const lastKey = keys.pop();
1520
- let node = this.data;
1521
- for (const key of keys){
1522
- if (!Object.hasOwn(node, key)) {
1523
- return;
1524
- }
1525
- node = node[key];
1526
- }
1527
- delete node[lastKey];
1528
- }
1529
- if (save) this.save();
1530
- }
1531
- /**
1532
- * Creates a deep clone of an object.
1533
- * @param obj - The object to clone.
1534
- * @returns The cloned object.
1535
- */ cloneDeep(obj) {
1536
- if (typeof obj !== 'object') return obj;
1537
- return JSON.parse(JSON.stringify(obj));
1538
- }
1539
- }
1540
-
1541
- /**
1542
- * A class that represents the user-presets section of the JSON file used as simple database.
1543
- */ class PresetsSection extends AbstractJsonFileSection {
1544
- /**
1545
- * Creates an instance of AppDataSection.
1546
- * @param file - The parent JsonFile instance.
1547
- * @param name - The name of the section.
1548
- */ constructor(file, name){
1549
- super(file, name, false);
1550
- this.defineProperty('defaults', {
1551
- description: 'All presets inherit from this preset',
1552
- presets: [],
1553
- args: this.cmd.arguments.map((arg)=>arg.defaultValue ?? null),
1554
- options: this.cmd.getOwnAndGlobalOptions().reduce((acc, opt)=>{
1555
- acc[opt.attributeName()] = opt.defaultValue ?? (opt.isBoolean() ? false : null);
1556
- return acc;
1557
- }, {})
1558
- });
1559
- }
1560
- /**
1561
- * Asserts that a key-value pair is valid.
1562
- * @param key - The key to assert.
1563
- * @param value - The preset options to validate.
1564
- */ assertValid(key, value) {
1565
- this.cmd.assertValidPreset(key, value);
1566
- }
1567
- /**
1568
- * Defines a property for the section.
1569
- * @param key - The key of the property.
1570
- * @param options - The options for the property.
1571
- */ defineProperty(key, options) {
1572
- if (this.defaultValues[key]) throw new Error(`Cannot redefine preset '${key}'.`);
1573
- this.defaultValues[key] = JSON.parse(JSON.stringify(options));
1574
- this.assertValid(key, options);
1575
- this.isInitialized = false;
1576
- }
1577
- /**
1578
- * Initializes the section.
1579
- * @param save - Indicates whether to save the section after initialization.
1580
- * @returns A string if an error occurred during initialization, otherwise void.
1581
- */ initialize(save = false) {
1582
- if (this.isInitialized) return;
1583
- const data = this.db.getSafe(this.prefix());
1584
- const presets = objAssign({}, this.defaultValues, data || {});
1585
- const presetNames = Object.keys(presets);
1586
- for (const preset of Object.values(presets)){
1587
- for (const pname of presetNames){
1588
- if (preset.options[pname]) {
1589
- preset.presets.push(pname);
1590
- delete preset.options[pname];
1591
- save = true;
1592
- }
1593
- }
1594
- }
1595
- this.db.set(this.prefix(), presets, save);
1596
- this.isInitialized = true;
1597
- }
1598
- /**
1599
- * Sets all the values in the section.
1600
- * @param values - The values to set.
1601
- * @param save - Indicates whether to save the section after setting the values.
1602
- */ async setAll(presets, save = true) {
1603
- if (!presets['defaults']) presets['defaults'] = JSON.parse(JSON.stringify(this.defaultValues['defaults']));
1604
- super.setAll(presets, save);
1605
- }
1606
- /**
1607
- * Deletes the value associated with the specified key.
1608
- * @param key - The key to delete.
1609
- * @param save - Indicates whether to save the section after deleting the value.
1610
- */ delete(name, save = true) {
1611
- if (Object.hasOwn(this.defaultValues, name)) throw new Error('Cannot delete the builtin presets.');
1612
- super.delete(name, save);
1613
- }
1614
- }
1615
-
1616
- /**
1617
- * A class that represents the JSON file used as a simple database.
1618
- */ class JsonFile {
1619
- /**
1620
- * @param cmd The parent CommandBuilder instance.
1621
- */ constructor(cmd){
1622
- this.cmd = cmd;
1623
- }
1624
- /**
1625
- * A lazy-loaded instance of the JsonDB instance containing the data.
1626
- * Upon first property access, it is stored as a property on the instance.
1627
- * If the command is a subcommand, the root command's JsonDB instance is returned.
1628
- */ get db() {
1629
- if (this.cmd.isRoot) {
1630
- return realizeLazyProperty(this, 'db', new JsonDB(this.cmd.dataFilepath, 2));
1631
- } else {
1632
- return this.cmd.root.db.db;
1633
- }
1634
- }
1635
- /**
1636
- * A lazy-loaded instance of the `config` section of the JSON file.
1637
- * Upon first property access, it is stored as a property on the instance.
1638
- */ get config() {
1639
- return realizeLazyProperty(this, 'config', new ConfigSection(this, 'config'));
1640
- }
1641
- /**
1642
- * A lazy-loaded instance of the `appData` section of the JSON file.
1643
- * Upon first property access, it is stored as a property on the instance.
1644
- */ get appData() {
1645
- return realizeLazyProperty(this, 'appData', new AppDataSection(this, 'appData'));
1646
- }
1647
- /**
1648
- * A lazy-loaded instance of the `presets` section of the JSON file.
1649
- */ get presets() {
1650
- return realizeLazyProperty(this, 'presets', new PresetsSection(this, 'presets'));
1651
- }
1652
- }
1653
-
1654
- class OptionArgumentParserSelector extends ParserSelector {
1655
- constructor(builder){
1656
- super(builder);
1657
- }
1658
- custom(parser) {
1659
- const name = this.builder.$.attributeName();
1660
- this.builder.cmd.meta.optParsers[name] = parser;
1661
- return this.builder;
1662
- }
1663
- }
1664
-
1665
- class OptionArgumentValidatorSelector extends ValidatorSelector {
1666
- constructor(builder){
1667
- super(builder);
1668
- }
1669
- custom(validator) {
1670
- const name = this.builder.$.attributeName();
1671
- const obj = this.builder.cmd.meta.optValidators;
1672
- if (!obj[name]) obj[name] = [];
1673
- obj[name].push(validator);
1674
- return this.builder;
1675
- }
1676
- }
1677
-
1678
- /**
1679
- * Extract the argument name from an option's 'flags' string.
1680
- */ function getArgumentName(opt) {
1681
- const result = arrLast(opt.flags.trim().split(' '));
1682
- if (/-/.test(result)) return undefined;
1683
- return result;
1684
- }
1685
- /**
1686
- * Check if an option has an argument.
1687
- */ function hasArgument(opt) {
1688
- return /[<>[\]]/.test(opt.flags);
1689
- }
1690
- /**
1691
- * Update an Option's 'flags' property from its 'short' and 'long' properties.
1692
- * The flags property is not automatically updated when 'short' or 'long' are changed.
1693
- */ function renderFlags(opt) {
1694
- const shortLong = [];
1695
- if (opt.short) shortLong.push(opt.short);
1696
- if (opt.long) shortLong.push(opt.long);
1697
- const argName = getArgumentName(opt);
1698
- return shortLong.join(', ') + (argName ? ' ' + argName : '');
1699
- }
1700
- /**
1701
- * Set an Option's 'long' name. The 'flags' property is updated accordingly.
1702
- * The '--' prefix is automatically added if not present.
1703
- */ function setLong(opt, long) {
1704
- opt.long = strEnsureStartsWith(long, '--').replace(/^-+/, '--');
1705
- opt.flags = renderFlags(opt);
1706
- }
1707
- /**
1708
- * Set an Option's 'short' name. The 'flags' property is updated accordingly.
1709
- * The '-' prefix is automatically added if not present.
1710
- */ function setShort(opt, short) {
1711
- opt.short = strEnsureStartsWith(short, '-').replace(/^-+/, '-');
1712
- opt.flags = renderFlags(opt);
1713
- }
1714
- const OptionHelpers = {
1715
- getArgumentName,
1716
- hasArgument,
1717
- renderFlags,
1718
- setLong,
1719
- setShort
1720
- };
1721
-
1722
- class OptionReader {
1723
- constructor(parent){
1724
- this.parent = parent;
1725
- }
1726
- get $() {
1727
- return this.parent.$;
1728
- }
1729
- get option() {
1730
- return this.parent.$;
1731
- }
1732
- get description() {
1733
- return this.$.description;
1734
- }
1735
- get optional() {
1736
- return this.$.optional;
1737
- }
1738
- get mandatory() {
1739
- return this.$.mandatory;
1740
- }
1741
- get hidden() {
1742
- return this.$.hidden;
1743
- }
1744
- get variadic() {
1745
- return this.$.variadic;
1746
- }
1747
- get short() {
1748
- return this.$.short;
1749
- }
1750
- get long() {
1751
- return this.$.long;
1752
- }
1753
- get preset() {
1754
- return this.$.presetArg;
1755
- }
1756
- get default() {
1757
- return this.$.defaultValue;
1758
- }
1759
- get choices() {
1760
- return this.$.argChoices;
1761
- }
1762
- get env() {
1763
- return this.$.envVar;
1764
- }
1765
- get flags() {
1766
- return this.$.flags;
1767
- }
1768
- get name() {
1769
- return this.$.name();
1770
- }
1771
- get attributeName() {
1772
- return this.$.attributeName();
1773
- }
1774
- get defaultValueDescription() {
1775
- return this.$.defaultValueDescription;
1776
- }
1777
- get hasArgument() {
1778
- return OptionHelpers.hasArgument(this.parent.$);
1779
- }
1780
- }
1781
-
1782
- /**
1783
- * Wrapper around the @see Option class, for more intuitive construction.
1784
- * @remarks Options are one of boolean, negated, required argument, or optional argument.
1785
- */ class OptionBuilder {
1786
- constructor(cmd, flags){
1787
- this.cmd = cmd;
1788
- this.$ = new Option(flags);
1789
- if (!OptionHelpers.hasArgument(this.$) && this.$.long?.startsWith('--no-')) {
1790
- this.$.default(true);
1791
- }
1792
- }
1793
- description(string) {
1794
- this.$.description = string;
1795
- return this;
1796
- }
1797
- mandatory(mandatory = true) {
1798
- this.$.makeOptionMandatory(mandatory);
1799
- return this;
1800
- }
1801
- hideHelp(hide = true) {
1802
- this.$.hideHelp(hide);
1803
- return this;
1804
- }
1805
- hidden(hidden = true) {
1806
- this.$.hidden = hidden;
1807
- return this;
1808
- }
1809
- preset(arg) {
1810
- this.$.preset(arg);
1811
- return this;
1812
- }
1813
- default(value, description) {
1814
- this.$.default(value, description);
1815
- return this;
1816
- }
1817
- choices(values) {
1818
- if (!OptionHelpers.hasArgument(this.$)) {
1819
- throw new Error('Cannot set choices on option with no argument: ' + this.$.name());
1820
- }
1821
- this.$.choices(values);
1822
- return this;
1823
- }
1824
- conflicts(names) {
1825
- this.$.conflicts(names);
1826
- return this;
1827
- }
1828
- implies(optionValues) {
1829
- this.$.implies(optionValues);
1830
- return this;
1831
- }
1832
- env(name) {
1833
- this.$.env(name);
1834
- return this;
1835
- }
1836
- short(short) {
1837
- OptionHelpers.setShort(this.$, short);
1838
- return this;
1839
- }
1840
- get parser() {
1841
- if (!OptionHelpers.hasArgument(this.$)) {
1842
- throw new Error('Cannot set parser on option with no argument: ' + this.$.attributeName());
1843
- }
1844
- return new OptionArgumentParserSelector(this);
1845
- }
1846
- get validator() {
1847
- if (!OptionHelpers.hasArgument(this.$)) {
1848
- throw new Error('Cannot set validator on option with no argument: ' + this.$.attributeName());
1849
- }
1850
- return new OptionArgumentValidatorSelector(this);
1851
- }
1852
- get get() {
1853
- return realizeLazyProperty(this, 'get', new OptionReader(this));
1854
- }
1855
- }
1856
-
1857
- /**
1858
- * Updates the property descriptors of the specified properties on the given object.
1859
- * @param object - The object whose property descriptors are to be updated.
1860
- * @param properties - An array of property names for which the descriptors are to be updated.
1861
- * @param update - A function that takes a property descriptor and a property name, and returns a new property descriptor.
1862
- * @throws Will throw an error if any of the specified properties do not exist on the object.
1863
- * @example ```ts
1864
- * const obj = { a: 1, b: 2 };
1865
- * objUpdatePropertyDescriptors(obj, ['a', 'b'], (descriptor, property) => {
1866
- * descriptor.writable = true;
1867
- * return obj;
1868
- * });
1869
- * ```
1870
- */ function objUpdatePropertyDescriptors(object, properties, update) {
1871
- for (const p of properties){
1872
- if (!Reflect.has(object, p)) {
1873
- throw new Error(`Property, '${p}' does not exist on object.`);
1874
- }
1875
- const descriptor = update(Object.getOwnPropertyDescriptor(object, p), p);
1876
- Object.defineProperty(object, p, descriptor);
1877
- }
1878
- }
1879
-
1880
- /**
1881
- * Sets the specified properties of an object as non-enumerable.
1882
- * @remarks This function modifies the original object by setting the specified properties as non-enumerable.
1883
- * If the object or any of the property names are not valid, it throws an error.
1884
- * @param object The object whose properties are to be set as non-enumerable.
1885
- * @param properties The names of the properties to be set as non-enumerable.
1886
- * @throws Will throw an error if any of the specified properties do not exist on the object.
1887
- * @example ```ts
1888
- * setNonEnumerable({ a: 1, b: 2, c: 3 }, 'a', 'b');
1889
- * Object.keys({ a: 1, b: 2, c: 3 });;
1890
- * //=> ['c']
1891
- * ```
1892
- */ function setNonEnumerable(object, ...properties) {
1893
- objUpdatePropertyDescriptors(object, properties, (descriptor)=>{
1894
- descriptor.enumerable = false;
1895
- return descriptor;
1896
- });
1897
- }
1898
-
1899
- /**
1900
- * Wrapper around the @see Command class, for more intuitive construction.
1901
- */ class CommandBuilder {
1902
- static{
1903
- this.dataDirectory = path.join(os.homedir(), 'config', 'cli');
1904
- }
1905
- get db() {
1906
- return realizeLazyProperty(this, 'db', new JsonFile(this));
1907
- }
1908
- constructor(name, callback, parent, isNative = false){
1909
- this.features = new CommandFeatureSelector(this);
1910
- this.parent = null;
1911
- this.meta = new CommandBuilderMetaData();
1912
- this.meta.isNative = isNative;
1913
- this.$ = new Command(name);
1914
- commanderBackRefs.set(this.$, this);
1915
- if (parent) {
1916
- this.parent = parent;
1917
- this.parent.meta.subcommands.push(this);
1918
- this.parent.$.addCommand(this.$);
1919
- }
1920
- this.initializeHelp();
1921
- this.initializeActionWrapper();
1922
- if (callback) callback.call(this, this);
1923
- if (this.parent) {
1924
- this.$.copyInheritedSettings(this.parent.$);
1925
- this.features.inheritFrom(this.parent.features);
1926
- this.inheritParentHiddenGlobals();
1927
- }
1928
- if (!this.meta.isNative) {
1929
- this.assertCommandNameNotReserved(this.name);
1930
- this.addUtilCommands();
1931
- }
1932
- if (this.features.isAutoAssignSubCommandAliasesEnabled) {
1933
- this.assignSubCommandAliases();
1934
- if (!this.meta.isNative) {
1935
- this.assertNoDuplicateCommandNames();
1936
- }
1937
- }
1938
- if (this.features.isAutoAssignMissingOptionFlagsEnabled) {
1939
- this.assignMissingOptionFlags();
1940
- if (!this.meta.isNative) {
1941
- this.assertNoDuplicateOptionNames();
1942
- }
1943
- }
1944
- this.meta.isInitialized = true;
1945
- }
1946
- setRecommended() {
1947
- this.enableBuiltinOptions({
1948
- debug: true,
1949
- disableStderr: true,
1950
- disableStdout: true
1951
- });
1952
- this.autoAssignMissingOptionFlags();
1953
- this.autoAssignSubCommandAliases();
1954
- this.presetsEnabled();
1955
- }
1956
- deleteDataFile() {
1957
- const filepath = this.dataFilepath;
1958
- if (fs.existsSync(filepath)) remove(filepath);
1959
- }
1960
- version(string) {
1961
- this.assertNotInitialized();
1962
- this.$.version(string);
1963
- const opt = this.options.find((o)=>o.attributeName() === 'version');
1964
- if (opt) this.meta.globalOptions.push(opt);
1965
- return this;
1966
- }
1967
- description(...lines) {
1968
- this.assertNotInitialized();
1969
- const description = lines.join('\n');
1970
- const summary = description.split(/(\. ?|\n|$)/)[0];
1971
- this.$.summary(summary + '.');
1972
- this.$.description(description);
1973
- return this;
1974
- }
1975
- alias(alias) {
1976
- this.assertNotInitialized();
1977
- this.assertCommandNameNotReserved(alias);
1978
- this.$.alias(alias);
1979
- return this;
1980
- }
1981
- aliases(...aliases) {
1982
- this.assertNotInitialized();
1983
- aliases.forEach((alias)=>this.assertCommandNameNotReserved(alias));
1984
- this.$.aliases(aliases);
1985
- return this;
1986
- }
1987
- enableBuiltinOptions(options) {
1988
- this.assertNotInitialized();
1989
- if (!options || options.debug) this.globalOption('-D, --debug', 'Output debugging information.');
1990
- if (!options || options.disableColor) this.globalOption('-C, --disable-color', 'Disable color in terminal output.');
1991
- if (!options || options.disableStderr) this.globalOption('-E, --disable-stderr', 'Mute all output to stderr.');
1992
- if (!options || options.disableStdout) this.globalOption('-O, --disable-stdout', 'Mute all output to stdout.');
1993
- return this;
1994
- }
1995
- argument(name, cb) {
1996
- this.assertNotInitialized();
1997
- const ins = new ArgumentBuilder(this, name);
1998
- this.$.addArgument(ins.$);
1999
- if (typeof cb === 'function') {
2000
- cb(ins, this);
2001
- } else if (typeof cb === 'string') {
2002
- ins.description(cb);
2003
- }
2004
- return this;
2005
- }
2006
- option(flags, cb) {
2007
- this.assertNotInitialized();
2008
- const ins = new OptionBuilder(this, flags);
2009
- if (this.hasIdenticalParentOption(ins.$)) return this;
2010
- this.$.addOption(ins.$);
2011
- if (typeof cb === 'function') {
2012
- cb(ins, this);
2013
- } else if (typeof cb === 'string') {
2014
- ins.description(cb);
2015
- }
2016
- return this;
2017
- }
2018
- globalOption(flags, cb) {
2019
- return this.option(flags, (ins)=>{
2020
- const opt = ins.$;
2021
- this.meta.globalOptions.push(opt);
2022
- if (typeof cb === 'function') {
2023
- cb(ins, this);
2024
- } else if (typeof cb === 'string') {
2025
- ins.description(cb);
2026
- }
2027
- if (opt.hidden) this.meta.hiddenGlobalOptions.add(opt);
2028
- });
2029
- }
2030
- command(name, cb) {
2031
- this.assertNotInitialized();
2032
- new CommandBuilder(name, cb, this);
2033
- return this;
2034
- }
2035
- nativeCommand(name, cb) {
2036
- this.assertNotInitialized();
2037
- new CommandBuilder(name, cb, this, true);
2038
- return this;
2039
- }
2040
- action(fn) {
2041
- this.assertNotInitialized();
2042
- Object.defineProperty(this.meta, 'actionHandler', {
2043
- value: fn,
2044
- configurable: true
2045
- });
2046
- return this;
2047
- }
2048
- errorHandler(fn) {
2049
- this.assertNotInitialized();
2050
- Object.defineProperty(this.meta, 'errorHandler', {
2051
- value: fn,
2052
- configurable: true
2053
- });
2054
- return this;
2055
- }
2056
- appData(key, value) {
2057
- this.assertNotInitialized();
2058
- this.features.appData(true);
2059
- this.db.appData.defineProperty(key, value);
2060
- return this;
2061
- }
2062
- config(key, entry) {
2063
- this.assertNotInitialized();
2064
- this.features.config(true);
2065
- this.db.config.defineProperty(key, entry);
2066
- return this;
2067
- }
2068
- preset(name, preset) {
2069
- this.assertNotInitialized();
2070
- this.features.presets();
2071
- this.meta.presetOptionKeys.push(name);
2072
- this.db.presets.defineProperty(name, {
2073
- description: preset.description,
2074
- presets: preset.presets ?? [],
2075
- args: preset.args ?? [],
2076
- options: preset.options ?? {}
2077
- });
2078
- return this;
2079
- }
2080
- presetsEnabled(boolean = true) {
2081
- this.assertNotInitialized();
2082
- this.features.presets(boolean);
2083
- return this;
2084
- }
2085
- autoAssignMissingOptionFlags(boolean = true) {
2086
- this.assertNotInitialized();
2087
- this.features.autoAssignMissingOptionFlags(boolean);
2088
- return this;
2089
- }
2090
- autoAssignSubCommandAliases(boolean = true) {
2091
- this.assertNotInitialized();
2092
- this.features.autoAssignSubCommandAliases(boolean);
2093
- return this;
2094
- }
2095
- allowExcessArguments(bool = true) {
2096
- this.assertNotInitialized();
2097
- this.$.allowExcessArguments(bool);
2098
- return this;
2099
- }
2100
- allowUnknownOption(bool = true) {
2101
- this.assertNotInitialized();
2102
- this.$.allowUnknownOption(bool);
2103
- return this;
2104
- }
2105
- /**
2106
- * Register callback to use as replacement for calling process.exit.
2107
- */ exitOverride(callback) {
2108
- this.assertNotInitialized();
2109
- this.$.exitOverride(callback);
2110
- return this;
2111
- }
2112
- throwInsteadOfProcessExit() {
2113
- this.assertNotInitialized();
2114
- const onErr = (err)=>{
2115
- throw err;
2116
- };
2117
- this.exitOverride(onErr);
2118
- this.errorHandler(onErr);
2119
- }
2120
- /**
2121
- * Add hook for life cycle event.
2122
- */ hook(event, listener) {
2123
- this.assertNotInitialized();
2124
- this.$.hook(event, listener);
2125
- return this;
2126
- }
2127
- /**
2128
- * You can customise the help by overriding Help properties using configureHelp(),
2129
- * or with a subclass of Help by overriding createHelp().
2130
- */ configureHelp(configuration) {
2131
- this.assertNotInitialized();
2132
- this.$.configureHelp(configuration);
2133
- return this;
2134
- }
2135
- /**
2136
- * Display the help or a custom message after an error occurs.
2137
- */ showHelpAfterError(displayHelp) {
2138
- this.assertNotInitialized();
2139
- this.$.showHelpAfterError(displayHelp);
2140
- return this;
2141
- }
2142
- /**
2143
- * Display suggestion of similar commands for unknown commands, or options for unknown options.
2144
- */ showSuggestionAfterError(displaySuggestion) {
2145
- this.assertNotInitialized();
2146
- this.$.showSuggestionAfterError(displaySuggestion);
2147
- return this;
2148
- }
2149
- /**
2150
- * Add additional text to be displayed with the built-in help.
2151
- *
2152
- * Position is 'before' or 'after' to affect just this command,
2153
- * and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
2154
- */ addHelpText(position, text) {
2155
- this.assertNotInitialized();
2156
- this.$.addHelpText(position, text);
2157
- return this;
2158
- }
2159
- throwCommanderError(message, exitCode = 1, type = 'error') {
2160
- throw new CommanderError(exitCode, type, message);
2161
- }
2162
- hideGlobalOptions(...names) {
2163
- this.assertNotInitialized();
2164
- const globals = this.getGlobalOptions();
2165
- names = names.length ? names : globals.map((opt)=>opt.attributeName());
2166
- for (const name of names){
2167
- if (!name) continue;
2168
- let found = false;
2169
- for (const opt of globals){
2170
- if (opt.attributeName() === name) {
2171
- this.meta.hiddenGlobalOptions.add(opt);
2172
- found = true;
2173
- break;
2174
- }
2175
- }
2176
- if (!found) this.throwCommanderError(`Unknown global option name: ${name} for command, ${this.name}`);
2177
- }
2178
- return this;
2179
- }
2180
- unhideGlobalOptions(...names) {
2181
- this.assertNotInitialized();
2182
- const globals = this.getGlobalOptions();
2183
- names = names.length ? names : globals.map((opt)=>opt.attributeName());
2184
- for (const name of names){
2185
- if (!name) continue;
2186
- let found = false;
2187
- for (const opt of globals){
2188
- if (opt.attributeName() === name) {
2189
- this.meta.hiddenGlobalOptions.delete(opt);
2190
- found = true;
2191
- break;
2192
- }
2193
- }
2194
- if (!found) this.throwCommanderError(`Unknown global option name: ${name} for command, ${this.name}`);
2195
- }
2196
- return this;
2197
- }
2198
- /**
2199
- * Set the directory for searching for executable subcommands of this command.
2200
- */ executableDir(path) {
2201
- this.assertNotInitialized();
2202
- this.$.executableDir(path);
2203
- return this;
2204
- }
2205
- /**
2206
- * Store option value.
2207
- */ setOptionValue(key, value) {
2208
- this.assertNotInitialized();
2209
- this.$.setOptionValue(key, value);
2210
- return this;
2211
- }
2212
- /**
2213
- * Store option value and where the value came from.
2214
- */ setOptionValueWithSource(key, value, source) {
2215
- this.assertNotInitialized();
2216
- this.$.setOptionValueWithSource(key, value, source);
2217
- return this;
2218
- }
2219
- setDataFilepath(filepath) {
2220
- this.assertNotInitialized();
2221
- Object.defineProperty(this, 'dataFilepath', {
2222
- value: filepath
2223
- });
2224
- if (Object.hasOwn(this, 'db') && Object.hasOwn(this.db, 'db')) {
2225
- this.db.db.setFilepath(filepath);
2226
- }
2227
- }
2228
- /**
2229
- * Display error message and exit (or call exitOverride).
2230
- */ outputError(message, options) {
2231
- this.$.error(message, options);
2232
- }
2233
- /**
2234
- * Output help information for this command.
2235
- */ outputHelp() {
2236
- console.log(this.getRenderedHelp());
2237
- }
2238
- /**
2239
- * Display error message and exit (or call exitOverride).
2240
- */ outputDebugMessage(event, getProps = ()=>({})) {
2241
- OutputManager.getInstance().outputDebug(()=>({
2242
- event,
2243
- cmd: this.getPrefixString(),
2244
- ...getProps()
2245
- }));
2246
- }
2247
- parseArguments(args) {
2248
- const last = this.arguments.length - 1;
2249
- return args.map((arg, i)=>{
2250
- if (!arg) return arg;
2251
- const parse = this.meta.argParsers[i > last ? last : i];
2252
- return parse ? Array.isArray(arg) ? arg.map(parse) : parse(arg) : arg;
2253
- });
2254
- }
2255
- /**
2256
- * Parses (and validates) options using the parsers defined in the command builder.
2257
- */ parseOptions(opts) {
2258
- for (const [key, value] of Object.entries(opts)){
2259
- const parse = this.meta.optParsers[key];
2260
- opts[key] = parse ? Array.isArray(value) ? value.map(parse) : parse(value) : value;
2261
- }
2262
- return opts;
2263
- }
2264
- /**
2265
- * Validate ALREADY PARSED args using the validators defined in the command builder.
2266
- */ assertValidArguments(parsedArgs) {
2267
- const last = this.arguments.length - 1;
2268
- parsedArgs.forEach((arg, i)=>{
2269
- if (arg == null) return;
2270
- const index = i > last ? last : i;
2271
- const validators = this.meta.argValidators[index];
2272
- if (!validators) return;
2273
- for (const isValid of validators){
2274
- ensureThat(arg, isValid, {
2275
- Err: InvalidArgumentError
2276
- });
2277
- }
2278
- });
2279
- return parsedArgs;
2280
- }
2281
- /**
2282
- * Validate ALREADY PARSED options using the validators defined in the command builder.
2283
- */ assertValidOptions(parsedOptions) {
2284
- for (const [key, value] of Object.entries(parsedOptions)){
2285
- if (!this.meta.optValidators[key]) continue;
2286
- if (value == null) continue;
2287
- for (const isValid of this.meta.optValidators[key]){
2288
- ensureThat(value, isValid);
2289
- }
2290
- }
2291
- return parsedOptions;
2292
- }
2293
- assertValidPreset(key, preset) {
2294
- const { description, presets, args, options } = preset;
2295
- ensureThat(key, isStringWithNoSpacesOrDashes);
2296
- ensureThat(description, isString);
2297
- ensureThat(presets, isStringArray);
2298
- ensureThat(args, isArray);
2299
- this.assertPresetArgsOptional(args);
2300
- this.assertValidArguments(args);
2301
- ensureThat(options, isObject);
2302
- this.assertValidOptions(options);
2303
- }
2304
- get name() {
2305
- return this.$.name();
2306
- }
2307
- /**
2308
- * Get the command at the root of the command tree.
2309
- */ get root() {
2310
- if (this.isRoot) return this;
2311
- return this.getAncestors().pop();
2312
- }
2313
- get isRoot() {
2314
- return !this.parent;
2315
- }
2316
- get arguments() {
2317
- return this.$.registeredArguments;
2318
- }
2319
- get options() {
2320
- return this.$.options;
2321
- }
2322
- get commander() {
2323
- return this.$;
2324
- }
2325
- get hasGrandChildren() {
2326
- return this.meta.subcommands.some((sub)=>!!sub.meta.subcommands.length);
2327
- }
2328
- /**
2329
- * Returns whether a command's last argument is variadic.
2330
- */ get isLastArgVariadic() {
2331
- if (!this.arguments.length) return false;
2332
- return arrLast(this.arguments).variadic;
2333
- }
2334
- get dataFilepath() {
2335
- return path.join(CommandBuilder.dataDirectory, this.root.name + '.json');
2336
- }
2337
- /**
2338
- * Get the executable search directory.
2339
- */ getExecutableDir() {
2340
- return this.$.executableDir();
2341
- }
2342
- /**
2343
- * Retrieve option value.
2344
- */ getOptionValue(key) {
2345
- return this.$.getOptionValue(key);
2346
- }
2347
- /**
2348
- * Get source of option value.
2349
- */ getOptionValueSource(key) {
2350
- return this.$.getOptionValueSource(key);
2351
- }
2352
- /**
2353
- * Get source of option value. See also .optsWithGlobals().
2354
- */ getOptionValueSourceWithGlobals(key) {
2355
- return this.$.getOptionValueSourceWithGlobals(key);
2356
- }
2357
- getActionHandler() {
2358
- return this.meta.actionHandler;
2359
- }
2360
- getDescription() {
2361
- return this.$.description();
2362
- }
2363
- getSummary() {
2364
- return this.$.summary();
2365
- }
2366
- getVersion() {
2367
- return this.$.version();
2368
- }
2369
- getAlias() {
2370
- return this.$.alias();
2371
- }
2372
- getAliases() {
2373
- return this.$.aliases();
2374
- }
2375
- /**
2376
- * Get a commands prefix array based on all its parent/ancestor commands.
2377
- */ getPrefixArray() {
2378
- return this.getAncestors({
2379
- includeSelf: true
2380
- }).reverse().map((node)=>node.name);
2381
- }
2382
- /**
2383
- * Get a commands prefix string based on all its parent/ancestor commands.
2384
- */ getPrefixString() {
2385
- return this.getPrefixArray().join(' ');
2386
- }
2387
- getGlobalOptions() {
2388
- const result = [];
2389
- for (const anc of this.getAncestors({
2390
- includeSelf: true
2391
- }).reverse()){
2392
- for (const gopt of anc.meta.globalOptions){
2393
- if (!this.meta.hiddenGlobalOptions.has(gopt)) {
2394
- result.push(gopt);
2395
- }
2396
- }
2397
- }
2398
- return result;
2399
- }
2400
- getOwnAndGlobalOptions() {
2401
- return this.options.concat(this.getGlobalOptions());
2402
- }
2403
- *getChildrenIterator(options) {
2404
- if (options?.includeSelf) yield this;
2405
- for (const sub of this.meta.subcommands){
2406
- yield sub;
2407
- yield* sub.getChildrenIterator();
2408
- }
2409
- }
2410
- getChildren(options) {
2411
- return [
2412
- ...this.getChildrenIterator(options)
2413
- ];
2414
- }
2415
- *getAncestorsIterator(options) {
2416
- if (options?.includeSelf) yield this;
2417
- let node = this.parent;
2418
- while(node){
2419
- yield node;
2420
- node = node.parent;
2421
- }
2422
- }
2423
- /**
2424
- * Get a command's ancestors, optionally starting from the command itself.
2425
- */ getAncestors(options) {
2426
- return [
2427
- ...this.getAncestorsIterator(options)
2428
- ];
2429
- }
2430
- *getSiblingsIterator() {
2431
- if (!this.parent) return;
2432
- for (const sub of this.parent.meta.subcommands){
2433
- if (sub === this) continue;
2434
- yield sub;
2435
- }
2436
- }
2437
- /**
2438
- * Returns an array of sibling CommandBuilder objects.
2439
- */ getSiblings() {
2440
- return [
2441
- ...this.getSiblingsIterator()
2442
- ];
2443
- }
2444
- getClosestNonNativeParent() {
2445
- for (const anc of this.getAncestorsIterator({
2446
- includeSelf: true
2447
- })){
2448
- if (!anc.meta.isNative) return anc;
2449
- }
2450
- this.throwCommanderError('No non-native parent found');
2451
- }
2452
- getRenderedHelp() {
2453
- return this.$.helpInformation();
2454
- }
2455
- getOptsWithGlobalsParsed() {
2456
- return this.parseOptions(this.$.optsWithGlobals());
2457
- }
2458
- getParsedValidArgsOptsWithPresets() {
2459
- const [presetArgs, presetOpts, presetOrder] = this.getPresetArgsAndOpts();
2460
- const args = this.getParsedValidArgsWithPresets(presetArgs);
2461
- const opts = this.getParsedValidOptsWithPresets(presetOpts);
2462
- this.debugLogArgsOpts(args, opts, presetArgs, presetOpts, presetOrder);
2463
- return [
2464
- args,
2465
- opts
2466
- ];
2467
- }
2468
- getParsedValidArgsWithPresets(presetArgs) {
2469
- const result = arrAssign([], ...presetArgs, this.parseArguments(this.$.args));
2470
- this.combineVariadicArgs(result);
2471
- this.assertValidArguments(result);
2472
- return this.padArgsWithUndefinedUntilExpectedLength(result);
2473
- }
2474
- getParsedValidOptsWithPresets(presetOpts) {
2475
- const parsed = this.getOptsWithGlobalsParsed();
2476
- const opts = presetOpts.length ? objAssign({}, ...presetOpts, parsed) : parsed;
2477
- this.deleteOptionsWithDefaultOrNoValue(opts);
2478
- this.assertValidOptions(opts);
2479
- return opts;
2480
- }
2481
- getPresetArgsAndOpts() {
2482
- if (!this.features.isPresetsEnabled) return [
2483
- [],
2484
- [],
2485
- []
2486
- ];
2487
- const presets = this.db.presets.getAll();
2488
- const opts = this.$.optsWithGlobals();
2489
- const selectedPresets = Object.keys(presets).filter((name)=>opts[name] === true);
2490
- const presetOrder = Object.keys(opts).filter((key)=>selectedPresets.includes(key));
2491
- const presetArgs = presetOrder.map((name)=>presets[name].args);
2492
- const presetOpts = presetOrder.map((name)=>presets[name].options);
2493
- return [
2494
- presetArgs,
2495
- presetOpts,
2496
- presetOrder
2497
- ];
2498
- }
2499
- combineVariadicArgs(result) {
2500
- if (this.isLastArgVariadic && result.length && !Array.isArray(arrLast(result))) {
2501
- const rest = result.splice(this.arguments.length - 1);
2502
- result.push(rest.filter((arg)=>arg != null));
2503
- }
2504
- return result;
2505
- }
2506
- debugLogArgsOpts(args, opts, presetArgs, presetOpts, presetOrder) {
2507
- if (opts['debug']) {
2508
- if (this.features.isPresetsEnabled) {
2509
- this.outputDebugMessage('parsePresets', ()=>({
2510
- presetOrder,
2511
- presetArgs,
2512
- presetOpts
2513
- }));
2514
- }
2515
- this.outputDebugMessage('parseArgsOpts', ()=>{
2516
- return {
2517
- args,
2518
- opts,
2519
- command: [
2520
- this.root.name,
2521
- ...this.meta.rawArgs
2522
- ].join(' ')
2523
- };
2524
- });
2525
- }
2526
- }
2527
- deleteOptionsWithDefaultOrNoValue(opts) {
2528
- const names = new Set(this.getOwnAndGlobalOptions().map((o)=>o.attributeName()));
2529
- for (const [key, value] of Object.entries(opts)){
2530
- if (!names.has(key) || value === false || value == null) {
2531
- setNonEnumerable(opts, key);
2532
- }
2533
- }
2534
- for (const key of this.meta.presetOptionKeys){
2535
- if (Object.hasOwn(opts, key)) {
2536
- setNonEnumerable(opts, key);
2537
- }
2538
- }
2539
- return opts;
2540
- }
2541
- handleOutputOptions() {
2542
- const opts = this.$.optsWithGlobals();
2543
- const om = OutputManager.getInstance().reset();
2544
- if (opts['disableColor']) om.colors.enabled = false;
2545
- if (opts['disableStderr']) om.stderr.disable();
2546
- if (opts['disableStdout']) om.stdout.disable();
2547
- if (opts['debug']) {
2548
- om.debug.enable();
2549
- om.drainDebugMessageQueue();
2550
- }
2551
- }
2552
- padArgsWithUndefinedUntilExpectedLength(args) {
2553
- while(args.length < this.arguments.length)args.push(undefined);
2554
- return args;
2555
- }
2556
- assertPresetArgsOptional(args) {
2557
- args.forEach((arg, i)=>{
2558
- if (arg != null && i < this.arguments.length && this.arguments[i].required) {
2559
- this.throwCommanderError(`Cannot preset required arguments.`);
2560
- }
2561
- });
2562
- }
2563
- addUtilCommands() {
2564
- if (!this.hasGrandChildren && !this.features.isConfigEnabled && !this.features.isPresetsEnabled && !this.features.isAppDataEnabled) {
2565
- return;
2566
- }
2567
- this.nativeCommand('util', (u)=>{
2568
- const cmd = u.getClosestNonNativeParent();
2569
- u.alias('u');
2570
- u.description('Utility commands.');
2571
- if (cmd.features.isConfigEnabled) {
2572
- u.nativeCommand('config', createConfigCommand);
2573
- }
2574
- if (cmd.features.isPresetsEnabled && cmd.meta.hasCustomActionHandler) {
2575
- u.nativeCommand('presets', createPresetsCommand);
2576
- }
2577
- if (cmd.hasGrandChildren) {
2578
- u.nativeCommand('list', createUtilListCommand);
2579
- }
2580
- if (cmd.features.isConfigEnabled || cmd.features.isPresetsEnabled || cmd.features.isAppDataEnabled) {
2581
- u.nativeCommand('filepath', createUtilFilepathCommand);
2582
- }
2583
- function createUtilFilepathCommand(f) {
2584
- f.alias('f');
2585
- f.description('Print filepath to JSON file containing user data, eg. config and presets.');
2586
- f.action(async ()=>console.log(cmd.dataFilepath));
2587
- }
2588
- function createUtilListCommand(l) {
2589
- l.alias('l');
2590
- l.description('List nested subcommands.');
2591
- l.option('--all', 'Include utility commands.');
2592
- l.action(async (opts)=>{
2593
- const filter = opts.all ? undefined : (prefix)=>{
2594
- return !/ (config|presets|util)( .+)?$/gi.test(prefix);
2595
- };
2596
- const table = [];
2597
- for (const c of cmd.getChildrenIterator({
2598
- includeSelf: true
2599
- })){
2600
- const prefix = c.getPrefixString();
2601
- if (filter && !filter(prefix)) continue;
2602
- table.push([
2603
- prefix,
2604
- c.getSummary()
2605
- ]);
2606
- }
2607
- const ansi = table.map((row)=>{
2608
- const arr = row[0].split(' ');
2609
- const last = arr.pop();
2610
- let col = colors.magenta;
2611
- if (row[1].startsWith('[Preset]')) {
2612
- col = colors.green;
2613
- } else if (/ (util|config|presets) /.test(row[0])) {
2614
- col = colors.gray;
2615
- } else if (/ (util|config|presets)/.test(row[0])) {
2616
- col = colors.dim;
2617
- }
2618
- row[0] = arr.map(colors.dim).concat(col(last)).join(' ');
2619
- return row;
2620
- });
2621
- console.log(formatTableForTerminal(ansi, [
2622
- 'Command',
2623
- 'Summary'
2624
- ]));
2625
- });
2626
- }
2627
- function createPresetsCommand(p) {
2628
- const db = cmd.db.presets;
2629
- p.alias('p');
2630
- 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.');
2631
- p.nativeCommand('edit', (e)=>{
2632
- e.alias('e');
2633
- e.description('Edit as JSON in a text editor.');
2634
- e.option('--editor [cmd]', 'The command to launch your preferred text editor.');
2635
- e.action(async (opts)=>{
2636
- db.edit(opts.editor);
2637
- console.info(db.getAll());
2638
- });
2639
- });
2640
- p.nativeCommand('list', (l)=>{
2641
- l.alias('l');
2642
- l.description('List all presets.');
2643
- l.action(async ()=>console.dir(db.getAll(), {
2644
- depth: null
2645
- }));
2646
- });
2647
- for (const [key, preset] of Object.entries(db.getAll())){
2648
- if (key === 'defaults') continue;
2649
- cmd.option(`--${key}`, (o)=>{
2650
- o.description('[Preset]: ' + preset.description);
2651
- const implied = {
2652
- defaults: true
2653
- };
2654
- const recurse = (preset)=>{
2655
- if (implied[preset]) return;
2656
- implied[preset] = true;
2657
- db.get(preset).presets.forEach((k)=>recurse(k));
2658
- };
2659
- recurse(key);
2660
- o.implies(implied);
2661
- });
2662
- }
2663
- }
2664
- function createConfigCommand(c) {
2665
- const db = cmd.db.config;
2666
- c.alias('c');
2667
- c.description('Manage configuration file.');
2668
- c.nativeCommand('edit', (e)=>{
2669
- e.alias('e');
2670
- e.description('Edit as JSON in a text editor.');
2671
- e.option('--editor [cmd]', 'The command to launch your preferred text editor.');
2672
- e.action(async (opts)=>{
2673
- db.edit(opts.editor);
2674
- console.info(db.getAll());
2675
- });
2676
- });
2677
- c.nativeCommand('list', (l)=>{
2678
- l.alias('l');
2679
- l.description('Print entire config with details.');
2680
- l.action(async ()=>{
2681
- const result = db.keys.map((key)=>({
2682
- key,
2683
- description: db.descriptions[key],
2684
- value: db.get(key),
2685
- defaultValue: db.defaultValues
2686
- }));
2687
- console.dir(result, {
2688
- depth: null
2689
- });
2690
- });
2691
- });
2692
- c.nativeCommand('get', (g)=>{
2693
- g.alias('g');
2694
- g.description('Print value(s) from the config.');
2695
- g.argument('[key]', 'The key to print the value of. Omit to print all values.');
2696
- g.action(async (key)=>console.log(key ? db.get(key) : db.getAll()));
2697
- });
2698
- c.nativeCommand('set', (s)=>{
2699
- s.alias('s');
2700
- s.description('Set a value in the config.');
2701
- s.argument('<key>', 'The key to set the value of.');
2702
- s.argument('<value>', 'The new value.');
2703
- s.action(async (key, val)=>{
2704
- const parse = db.parsers[key];
2705
- const value = typeof parse === 'function' ? parse(val) : val;
2706
- db.set(key, value);
2707
- console.info({
2708
- [key]: value
2709
- });
2710
- });
2711
- });
2712
- c.nativeCommand('reset', (r)=>{
2713
- r.alias('r');
2714
- r.description('Reset to defaults.');
2715
- r.argument('[key]', 'The key for which to reset the value. Omit to reset entire config.');
2716
- r.action(async (key)=>{
2717
- if (key) db.reset(key);
2718
- else db.resetAll();
2719
- console.info(db.getAll());
2720
- });
2721
- });
2722
- /*
2723
- config.option('--editor [cmd]', (o) => {
2724
- o.description('The command to launch your preferred text editor.')
2725
- })
2726
- config.argument('[action]', (a) => {
2727
- a.description('The action to perform.')
2728
- a.choices(['edit', 'list', 'get', 'set', 'reset'])
2729
- a.default('edit')
2730
- })
2731
- config.argument('[key]', (a) => {
2732
- a.description('Property key (if applicable)')
2733
- })
2734
- config.argument('[value]', (a) => {
2735
- a.description('Value to set (if applicable)')
2736
- })
2737
- config.action(
2738
- async (action: string, key: string, value: string, opts: { editor: string }, config: CommandBuilder) => {
2739
- const cmd = config.getClosestNonNativeParent()
2740
- const cfg = cmd.db.config
2741
- if (!action || action === 'edit') {
2742
- cfg.edit(opts.editor)
2743
- return console.info(cfg.getAll())
2744
- } else if (action === 'list') {
2745
- return console.dir(
2746
- cfg.keys.map((key: string) => {
2747
- return {
2748
- key,
2749
- description: cfg.descriptions[key],
2750
- value: cfg.get(key),
2751
- defaultValue: cfg.defaultValues,
2752
- }
2753
- })
2754
- )
2755
- } else if (action === 'get') {
2756
- if (key) return console.log(cfg.get(key))
2757
- else return console.log(cfg.getAll())
2758
- } else if (action === 'set') {
2759
- const from = cfg.get(key)
2760
- const parse = cfg.parsers[key]
2761
- const to = typeof parse === 'function' ? cfg.parsers[key](value) : value
2762
- cfg.set(key, to)
2763
- return console.info({ changed: key, from, to })
2764
- } else if (action === 'reset') {
2765
- if (key) cfg.reset(key)
2766
- else cfg.resetAll()
2767
- return console.info(cfg.getAll())
2768
- }
2769
- }
2770
- )*/ }
2771
- });
2772
- }
2773
- /**
2774
- * Makes aliases for the command.
2775
- * The idea is to be able to navigate the command tree by only typing the first letter(s) of the command names.
2776
- *
2777
- * Example: A command 'cola' would get these aliases: ['c', 'co', 'col'].
2778
- * However, if there are namespace clashes with sibling subcommands that start with the same letter,
2779
- * eg. like 'cola' and 'coal' where the first two letters clash, cola's aliases are reduced to only ['col'] and similarly for 'coal'.
2780
- *
2781
- * This method creates the aliases, ensuring there are no clashes with sublings, why it is important that the
2782
- * entire command tree is built before invoking this method.
2783
- */ assignSubCommandAliases() {
2784
- if (this.getAlias() || this.name.length <= 1) return this;
2785
- const sibAliases = this.getSiblings().map((sib)=>sib.getAliases()).flat();
2786
- for(let i = 0; i < this.name.length - 1; i++){
2787
- let cmdAlias = this.name.substring(0, i + 1);
2788
- let isClash = arrSome(sibAliases, (sibAlias)=>{
2789
- return cmdAlias === sibAlias;
2790
- });
2791
- if (isClash && i === 0) {
2792
- cmdAlias = cmdAlias.charAt(0).toUpperCase();
2793
- isClash = arrSome(sibAliases, (sibAlias)=>{
2794
- return cmdAlias === sibAlias;
2795
- });
2796
- }
2797
- if (isClash) continue;
2798
- this.alias(cmdAlias);
2799
- return this;
2800
- }
2801
- return this;
2802
- }
2803
- /**
2804
- * Automatically set 'short' and 'long' names to options that don't have one assigned yet.
2805
- *
2806
- * First, it tries to assign a short name based on the first letter of the option's attribute name
2807
- * Both lower and upper case are tried. If these is not available, the next letter of the option name is tried.
2808
- *
2809
- * If none of the letters of the option name are available, the option is skipped until all other
2810
- * options have had letters from their names attempted assigned.
2811
- * Those that remain are assigned the first available letter of the alphabet + 0-9.
2812
- * If there are 64 options for the command and no more alphanumeric characters are available,
2813
- * the option is not assigned a short name.
2814
- */ assignMissingOptionFlags() {
2815
- const taken = new Set();
2816
- for (const anc of this.getAncestorsIterator({
2817
- includeSelf: true
2818
- })){
2819
- anc.options.forEach((opt)=>{
2820
- if (!opt.short) return;
2821
- taken.add(opt.short.replace(/^-/g, ''));
2822
- });
2823
- }
2824
- const failed = new Set();
2825
- // assign letter from option name
2826
- this.options.forEach((opt)=>{
2827
- if (opt.short) return;
2828
- const name = opt.attributeName();
2829
- for(let c = 0; c < name.length; c++){
2830
- let char = name.charAt(c).toLowerCase();
2831
- if (taken.has(char)) {
2832
- char = char.toUpperCase();
2833
- if (taken.has(char)) continue;
2834
- }
2835
- OptionHelpers.setShort(opt, char);
2836
- taken.add(char);
2837
- return;
2838
- }
2839
- failed.add(opt);
2840
- });
2841
- // assign random alphanumeric character.
2842
- const name = 'abcdefghijklmnopqrstuvwxyz1234567890';
2843
- failed.forEach((opt)=>{
2844
- for(let c = 0; c < name.length; c++){
2845
- let char = name.charAt(c);
2846
- if (taken.has(char)) {
2847
- char = char.toUpperCase();
2848
- if (taken.has(char)) continue;
2849
- }
2850
- OptionHelpers.setShort(opt, char);
2851
- taken.add(char);
2852
- return;
2853
- }
2854
- });
2855
- }
2856
- assertNoDuplicateCommandNames() {
2857
- const names = this.$.commands.map((sub)=>sub.aliases().concat(sub.name())).flat();
2858
- if (names.length !== new Set(names).size) {
2859
- this.throwCommanderError(`Duplicate subcommand names/aliases found for command, ${this.name}: ${names.join(', ')}`);
2860
- }
2861
- }
2862
- hasIdenticalParentOption(option) {
2863
- const flags = option.flags;
2864
- for (const anc of this.getAncestorsIterator({
2865
- includeSelf: true
2866
- })){
2867
- for (const opt of anc.$.options){
2868
- if (flags === opt.flags) {
2869
- return true;
2870
- }
2871
- }
2872
- }
2873
- return false;
2874
- }
2875
- assertNoDuplicateOptionNames() {
2876
- const throwErr = (cmd, opt, anc)=>{
2877
- this.throwCommanderError(`Duplicate option names > cmd: ${cmd.name}, ${anc ? `anc: ${anc.name}, ` : ''}opt: ${opt}`);
2878
- };
2879
- const set = new Set();
2880
- for (const opt of this.options){
2881
- if (opt.name() === 'help') continue;
2882
- if (opt.short) {
2883
- if (set.has(opt.short)) throwErr(this, opt.short);
2884
- set.add(opt.short);
2885
- }
2886
- if (opt.long) {
2887
- if (set.has(opt.long)) throwErr(this, opt.long);
2888
- set.add(opt.long);
2889
- }
2890
- if (opt.attributeName()) {
2891
- if (set.has(opt.attributeName())) throwErr(this, opt.attributeName());
2892
- set.add(opt.attributeName());
2893
- }
2894
- }
2895
- for (const anc of this.getAncestorsIterator()){
2896
- for (const opt of anc.$.options){
2897
- if (opt.short && set.has(opt.short)) {
2898
- if (opt.short !== 'V') continue;
2899
- throwErr(this, opt.short, anc);
2900
- }
2901
- if (opt.long && set.has(opt.long)) {
2902
- throwErr(this, opt.long, anc);
2903
- }
2904
- if (opt.attributeName() && set.has(opt.attributeName())) {
2905
- throwErr(this, opt.attributeName(), anc);
2906
- }
2907
- }
2908
- }
2909
- }
2910
- initializeActionWrapper() {
2911
- this.$.action(()=>{
2912
- const isAsync = isAsyncFunction(this.meta.actionHandler) || /^\(.+\) ?=> ?tslib_1\.__awaiter\(/.test(this.meta.actionHandler.toString().trim());
2913
- if (isAsync) {
2914
- try {
2915
- this.handleOutputOptions();
2916
- const [args, opts] = this.getParsedValidArgsOptsWithPresets();
2917
- if (opts['help']) return Promise.resolve(this.outputHelp());
2918
- return Promise.resolve(this.meta.actionHandler.call(this, ...args, opts, this));
2919
- } catch (error) {
2920
- this.meta.errorHandler.call(this, error, this);
2921
- return Promise.reject(error);
2922
- }
2923
- } else {
2924
- try {
2925
- this.handleOutputOptions();
2926
- const [args, opts] = this.getParsedValidArgsOptsWithPresets();
2927
- if (opts['help']) return this.outputHelp();
2928
- this.meta.actionHandler.call(this, ...args, opts, this);
2929
- } catch (error) {
2930
- this.meta.errorHandler.call(this, error, this);
2931
- }
2932
- }
2933
- });
2934
- }
2935
- initializeHelp() {
2936
- if (this.isRoot) this.globalOption('-h, --help', 'show help');
2937
- this.$.addHelpCommand('?', 'show help');
2938
- this.$.configureHelp(DefaultHelpConfig);
2939
- }
2940
- inheritParentHiddenGlobals() {
2941
- if (!this.parent) return;
2942
- for (const opt of this.parent.meta.hiddenGlobalOptions){
2943
- this.meta.hiddenGlobalOptions.add(opt);
2944
- }
2945
- }
2946
- assertCommandNameNotReserved(name) {
2947
- if (this.isRoot) return;
2948
- if (this.meta.isNative) return;
2949
- if (name === 'u' || name === 'util') {
2950
- this.throwCommanderError(`Name '${name}' is reserved and is not available as name or alias.`);
2951
- }
2952
- }
2953
- assertNotInitialized() {
2954
- if (this.meta.isInitialized) this.throwCommanderError('Command already initialized: ' + this.name);
2955
- }
2956
- }
2957
- process.argv = splitCombinedArgvShorts(process.argv.slice());
2958
-
2959
- function CLI(name, callback) {
2960
- return ()=>new CommandBuilder(name, callback).commander;
2961
- }
2962
-
2963
- /**
2964
- * Reads a file and returns the file's contents.
2965
- *
2966
- * Identical to fs.readFileSync, except that:
2967
- * - it uses utf8 encoding by default
2968
- * - if operation fails, returns undefined instead of throwing
2969
- *
2970
- * @param filepath - The path to the file.
2971
- * @param encoding - The encoding to use when reading the file.
2972
- * @returns The file's contents or undefined if the file does not exist.
2973
- */ function readFileSafeSync(filepath, encoding = 'utf8') {
2974
- try {
2975
- return fs.readFileSync(filepath, encoding);
2976
- } catch (error) {
2977
- return undefined;
2978
- }
2979
- }
2980
-
2981
- function execInherit(command) {
2982
- return new Promise((resolve, reject)=>{
2983
- try {
2984
- const buffer = execSync(command, {
2985
- stdio: 'inherit'
2986
- });
2987
- const string = buffer && buffer.toString ? buffer.toString().trim() : '';
2988
- resolve(string);
2989
- } catch (error) {
2990
- const oError = error instanceof Error ? error : new Error(String(error));
2991
- reject(oError);
2992
- }
2993
- });
2994
- }
2995
-
2996
- /**
2997
- * Checks if the given string is in lower case.
2998
- * @param input The string to be checked.
2999
- * @example ```ts
3000
- * strIsLowerCase('hello');
3001
- * //=> true
3002
- * strIsLowerCase('Hello');
3003
- * //=> false
3004
- * ```
3005
- */ function strIsLowerCase(input) {
3006
- return input === input.toLowerCase();
3007
- }
3008
-
3009
- /**
3010
- * Checks if the given string is in upper case.
3011
- * @param input The string to be checked.
3012
- * @example ```ts
3013
- * strIsUpperCase('HELLO');;
3014
- * //=> true
3015
- * strIsUpperCase('HEllo');;
3016
- * //=> false
3017
- * ```
3018
- */ function strIsUpperCase(input) {
3019
- return input === input.toUpperCase();
3020
- }
3021
-
3022
- /**
3023
- * Returns an array of words in the string
3024
- * @param word The camel case word to split.
3025
- * @throws Throws an error if the input is not a string.
3026
- * @param input input string
3027
- * @example ```ts
3028
- * strSplitCamelCase('someCamel10Case')
3029
- * //=> ['some', 'Camel10', 'Case']
3030
- * ```
3031
- */ function strSplitCamelCase(word) {
3032
- if (!word) return [];
3033
- if (word.length <= 2) return [
3034
- word
3035
- ];
3036
- const result = [];
3037
- const lastCharIndex = word.length - 1;
3038
- let lastSplitIndex = 0;
3039
- let foundCamelCase = false;
3040
- for(let i = 1; i < word.length; i++){
3041
- if (isWordSplitIndex(word, i)) {
3042
- const sub = word.substring(lastSplitIndex, i);
3043
- if (sub) {
3044
- result.push(sub);
3045
- lastSplitIndex = i;
3046
- foundCamelCase = true;
3047
- }
3048
- }
3049
- if (foundCamelCase && i === lastCharIndex) {
3050
- const sub = word.substring(lastSplitIndex);
3051
- if (sub) result.push(sub);
3052
- }
3053
- }
3054
- if (!foundCamelCase) result.push(word);
3055
- return result;
3056
- }
3057
- const regInteger = /\d+/g;
3058
- const regSpecial = /[^\w]+/g;
3059
- function isWordSplitIndex(word, index) {
3060
- return strIsLowerCase(word[index - 1]) && strIsUpperCase(word[index]) && !regInteger.test(word[index - 1]) && !regInteger.test(word[index]) && !regSpecial.test(word[index - 1]) && !regSpecial.test(word[index]);
3061
- }
3062
-
3063
- /**
3064
- * Creates a parser function that parses a string into a boolean.
3065
- *
3066
- * @param trueValues - An array of strings that are considered true. Defaults to ['TRUE', 'T', 'YES', 'Y', '1'].
3067
- * @param falseValues - An array of strings that are considered false. Defaults to ['', 'FALSE', 'F', 'NO', 'N', '0'].
3068
- */ function createBooleanParser(trueValues = [
3069
- 'TRUE',
3070
- 'T',
3071
- 'YES',
3072
- 'Y',
3073
- '1'
3074
- ], falseValues = [
3075
- '',
3076
- 'FALSE',
3077
- 'F',
3078
- 'NO',
3079
- 'N',
3080
- '0'
3081
- ]) {
3082
- return function parseBoolean(string) {
3083
- string = string.toUpperCase();
3084
- if (falseValues.includes(string)) return false;
3085
- if (trueValues.includes(string)) return true;
3086
- throw new TypeError(`The value ${string} is not a valid boolean value. Accepted values are: ${[
3087
- ...trueValues,
3088
- ...falseValues
3089
- ].join(', ')}`);
3090
- };
3091
- }
3092
-
3093
- /**
3094
- * Parses a string into a boolean.
3095
- *
3096
- * Accepted values (case insensitive):
3097
- * - true: 'TRUE', 'T', 'YES', 'Y', '1'
3098
- * - false: 'FALSE', 'F', 'NO', 'N', '0'
3099
- *
3100
- * @throws Will throw an error if the input string is not a valid input.
3101
- */ const parseBoolean = createBooleanParser([
3102
- 'TRUE',
3103
- 'T',
3104
- 'YES',
3105
- 'Y',
3106
- '1'
3107
- ], [
3108
- 'FALSE',
3109
- 'F',
3110
- 'NO',
3111
- 'N',
3112
- '0'
3113
- ]);
3114
-
3115
- function isBoolean(value) {
3116
- return typeof value === 'boolean';
3117
- }
3118
-
3119
- export { AbstractJsonFileSection, AppDataSection, ArgumentBuilder, ArgumentParserSelector, ArgumentReader, ArgumentValidatorSelector, CLI, CommandBuilder, CommandBuilderMetaData, CommandFeatureSelector, ConfigSection, DefaultHelpConfig, ErrorParser, JsonDB, JsonFile, MethodDisabler, OptionArgumentParserSelector, OptionArgumentValidatorSelector, OptionBuilder, OptionHelpers, OptionReader, OutputManager, ParserSelector, PresetsSection, ValidatorSelector, arrAssign, arrLast, arrSome, commanderBackRefs, createArrayMerger, createBooleanParser, createObjectMerger, createTypedArrayValidator, createTypedListParser, defaultOpenInEditorCommand, ensureThat, errParseStack, errPrettyStack, errToObject, execInherit, formatTableForTerminal, funSetName, getTempDataPath, isArray, isBoolean, isFunction, isInteger, isNamedFunction, isNamedFunctionArray, isOSX, isObject, isPlainObject, isPrimitive, isString, isStringArray, isStringWithNoSpacesOrDashes, isValidNumber, isVsCodeInstalled, isWindows, objAssign, objUpdatePropertyDescriptors, parseBoolean, parseInteger, parseNumber, parseString, promptUserEditInTextEditorSync, promptUserEditJsonInTextEditorSync, readFileSafeSync, readFileSync, readJsonFileSafeSync, realizeLazyProperty, regexEscapeString, setNonEnumerable, splitCombinedArgvShorts, strEnsureStartsWith, strFirstCharToUpperCase, strIsLowerCase, strIsUpperCase, strSplitCamelCase, tempFileSync };