@emulsify/cli 1.6.0 → 1.7.1

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 (277) hide show
  1. package/README.md +89 -1
  2. package/dist/handlers/componentInstall.js +1 -1
  3. package/dist/handlers/componentList.js +1 -1
  4. package/dist/handlers/systemInstall.js +24 -9
  5. package/dist/index.js +12 -21
  6. package/dist/node_modules/.package-lock.json +24 -24
  7. package/dist/node_modules/@types/node/LICENSE +0 -0
  8. package/dist/node_modules/@types/node/README.md +1 -1
  9. package/dist/node_modules/@types/node/assert.d.ts +33 -31
  10. package/dist/node_modules/@types/node/async_hooks.d.ts +28 -20
  11. package/dist/node_modules/@types/node/buffer.d.ts +4 -4
  12. package/dist/node_modules/@types/node/child_process.d.ts +230 -62
  13. package/dist/node_modules/@types/node/cluster.d.ts +62 -27
  14. package/dist/node_modules/@types/node/console.d.ts +6 -6
  15. package/dist/node_modules/@types/node/constants.d.ts +12 -11
  16. package/dist/node_modules/@types/node/crypto.d.ts +311 -237
  17. package/dist/node_modules/@types/node/dgram.d.ts +50 -14
  18. package/dist/node_modules/@types/node/dns.d.ts +183 -54
  19. package/dist/node_modules/@types/node/domain.d.ts +4 -4
  20. package/dist/node_modules/@types/node/events.d.ts +4 -4
  21. package/dist/node_modules/@types/node/fs/promises.d.ts +105 -39
  22. package/dist/node_modules/@types/node/fs.d.ts +440 -126
  23. package/dist/node_modules/@types/node/globals.d.ts +41 -22
  24. package/dist/node_modules/@types/node/globals.global.d.ts +0 -0
  25. package/dist/node_modules/@types/node/http.d.ts +306 -217
  26. package/dist/node_modules/@types/node/http2.d.ts +341 -95
  27. package/dist/node_modules/@types/node/https.d.ts +250 -118
  28. package/dist/node_modules/@types/node/index.d.ts +1 -1
  29. package/dist/node_modules/@types/node/inspector.d.ts +1 -2
  30. package/dist/node_modules/@types/node/module.d.ts +4 -4
  31. package/dist/node_modules/@types/node/net.d.ts +28 -12
  32. package/dist/node_modules/@types/node/os.d.ts +5 -4
  33. package/dist/node_modules/@types/node/package.json +10 -3
  34. package/dist/node_modules/@types/node/path.d.ts +35 -24
  35. package/dist/node_modules/@types/node/perf_hooks.d.ts +5 -5
  36. package/dist/node_modules/@types/node/process.d.ts +61 -22
  37. package/dist/node_modules/@types/node/punycode.d.ts +3 -3
  38. package/dist/node_modules/@types/node/querystring.d.ts +15 -5
  39. package/dist/node_modules/@types/node/readline.d.ts +16 -6
  40. package/dist/node_modules/@types/node/repl.d.ts +13 -7
  41. package/dist/node_modules/@types/node/stream.d.ts +182 -23
  42. package/dist/node_modules/@types/node/string_decoder.d.ts +3 -3
  43. package/dist/node_modules/@types/node/timers.d.ts +5 -5
  44. package/dist/node_modules/@types/node/tls.d.ts +112 -30
  45. package/dist/node_modules/@types/node/trace_events.d.ts +3 -3
  46. package/dist/node_modules/@types/node/ts4.8/assert.d.ts +130 -0
  47. package/dist/node_modules/@types/node/ts4.8/async_hooks.d.ts +237 -0
  48. package/dist/node_modules/@types/node/ts4.8/buffer.d.ts +89 -0
  49. package/dist/node_modules/@types/node/ts4.8/child_process.d.ts +682 -0
  50. package/dist/node_modules/@types/node/ts4.8/cluster.d.ts +300 -0
  51. package/dist/node_modules/@types/node/ts4.8/console.d.ts +142 -0
  52. package/dist/node_modules/@types/node/ts4.8/constants.d.ts +19 -0
  53. package/dist/node_modules/@types/node/ts4.8/crypto.d.ts +1287 -0
  54. package/dist/node_modules/@types/node/ts4.8/dgram.d.ts +180 -0
  55. package/dist/node_modules/@types/node/ts4.8/dns.d.ts +516 -0
  56. package/dist/node_modules/@types/node/ts4.8/domain.d.ts +27 -0
  57. package/dist/node_modules/@types/node/ts4.8/events.d.ts +82 -0
  58. package/dist/node_modules/@types/node/ts4.8/fs/promises.d.ts +634 -0
  59. package/dist/node_modules/@types/node/ts4.8/fs.d.ts +2587 -0
  60. package/dist/node_modules/@types/node/ts4.8/globals.d.ts +763 -0
  61. package/dist/node_modules/@types/node/ts4.8/globals.global.d.ts +1 -0
  62. package/dist/node_modules/@types/node/ts4.8/http.d.ts +580 -0
  63. package/dist/node_modules/@types/node/ts4.8/http2.d.ts +1208 -0
  64. package/dist/node_modules/@types/node/ts4.8/https.d.ts +274 -0
  65. package/dist/node_modules/@types/node/ts4.8/index.d.ts +53 -0
  66. package/dist/node_modules/@types/node/ts4.8/inspector.d.ts +3050 -0
  67. package/dist/node_modules/@types/node/ts4.8/module.d.ts +56 -0
  68. package/dist/node_modules/@types/node/ts4.8/net.d.ts +324 -0
  69. package/dist/node_modules/@types/node/ts4.8/os.d.ts +243 -0
  70. package/dist/node_modules/@types/node/ts4.8/path.d.ts +168 -0
  71. package/dist/node_modules/@types/node/ts4.8/perf_hooks.d.ts +274 -0
  72. package/dist/node_modules/@types/node/ts4.8/process.d.ts +452 -0
  73. package/dist/node_modules/@types/node/ts4.8/punycode.d.ts +78 -0
  74. package/dist/node_modules/@types/node/ts4.8/querystring.d.ts +41 -0
  75. package/dist/node_modules/@types/node/ts4.8/readline.d.ts +184 -0
  76. package/dist/node_modules/@types/node/ts4.8/repl.d.ts +404 -0
  77. package/dist/node_modules/@types/node/ts4.8/stream.d.ts +518 -0
  78. package/dist/node_modules/@types/node/ts4.8/string_decoder.d.ts +10 -0
  79. package/dist/node_modules/@types/node/ts4.8/timers.d.ts +19 -0
  80. package/dist/node_modules/@types/node/ts4.8/tls.d.ts +866 -0
  81. package/dist/node_modules/@types/node/ts4.8/trace_events.d.ts +64 -0
  82. package/dist/node_modules/@types/node/ts4.8/tty.d.ts +69 -0
  83. package/dist/node_modules/@types/node/ts4.8/url.d.ts +187 -0
  84. package/dist/node_modules/@types/node/ts4.8/util.d.ts +278 -0
  85. package/dist/node_modules/@types/node/ts4.8/v8.d.ts +189 -0
  86. package/dist/node_modules/@types/node/ts4.8/vm.d.ts +155 -0
  87. package/dist/node_modules/@types/node/ts4.8/wasi.d.ts +88 -0
  88. package/dist/node_modules/@types/node/ts4.8/worker_threads.d.ts +241 -0
  89. package/dist/node_modules/@types/node/ts4.8/zlib.d.ts +364 -0
  90. package/dist/node_modules/@types/node/tty.d.ts +4 -4
  91. package/dist/node_modules/@types/node/url.d.ts +49 -11
  92. package/dist/node_modules/@types/node/util.d.ts +103 -41
  93. package/dist/node_modules/@types/node/v8.d.ts +4 -5
  94. package/dist/node_modules/@types/node/vm.d.ts +7 -7
  95. package/dist/node_modules/@types/node/wasi.d.ts +3 -4
  96. package/dist/node_modules/@types/node/worker_threads.d.ts +8 -8
  97. package/dist/node_modules/@types/node/zlib.d.ts +13 -13
  98. package/dist/node_modules/@types/progress/LICENSE +0 -0
  99. package/dist/node_modules/@types/progress/README.md +2 -3
  100. package/dist/node_modules/@types/progress/index.d.ts +0 -5
  101. package/dist/node_modules/@types/progress/package.json +6 -6
  102. package/dist/node_modules/ajv-formats/node_modules/ajv/README.md +19 -5
  103. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/2019.d.ts +3 -1
  104. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/2019.js +7 -1
  105. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/2019.js.map +1 -1
  106. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/2020.d.ts +3 -1
  107. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/2020.js +7 -1
  108. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/2020.js.map +1 -1
  109. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/ajv.d.ts +3 -1
  110. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/ajv.js +7 -1
  111. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/ajv.js.map +1 -1
  112. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/codegen/code.d.ts +5 -5
  113. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/codegen/code.js.map +1 -1
  114. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/codegen/index.d.ts +2 -2
  115. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/codegen/index.js.map +1 -1
  116. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/codegen/scope.d.ts +5 -5
  117. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/codegen/scope.js +1 -1
  118. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/codegen/scope.js.map +1 -1
  119. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/errors.js +1 -1
  120. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/errors.js.map +1 -1
  121. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/index.d.ts +1 -1
  122. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/index.js +1 -1
  123. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/index.js.map +1 -1
  124. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/jtd/parse.js.map +1 -1
  125. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/jtd/serialize.js +18 -7
  126. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/jtd/serialize.js.map +1 -1
  127. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/jtd/types.d.ts +2 -2
  128. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/names.js +6 -6
  129. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/names.js.map +1 -1
  130. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/resolve.d.ts +1 -1
  131. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/resolve.js +4 -4
  132. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/resolve.js.map +1 -1
  133. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/rules.d.ts +2 -2
  134. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/util.d.ts +2 -2
  135. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/util.js +1 -1
  136. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/util.js.map +1 -1
  137. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/validate/boolSchema.js.map +1 -1
  138. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/validate/dataType.d.ts +1 -1
  139. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/validate/dataType.js +2 -1
  140. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/validate/dataType.js.map +1 -1
  141. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/validate/defaults.js.map +1 -1
  142. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/validate/index.js +11 -1
  143. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/validate/index.js.map +1 -1
  144. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/validate/keyword.js.map +1 -1
  145. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/validate/subschema.d.ts +1 -1
  146. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/validate/subschema.js.map +1 -1
  147. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/core.d.ts +3 -3
  148. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/core.js +2 -1
  149. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/core.js.map +1 -1
  150. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/jtd.d.ts +4 -2
  151. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/jtd.js +7 -1
  152. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/jtd.js.map +1 -1
  153. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/runtime/equal.d.ts +1 -1
  154. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/runtime/parseJson.js +2 -1
  155. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/runtime/parseJson.js.map +1 -1
  156. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/runtime/re2.d.ts +1 -1
  157. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/runtime/ucs2length.js.map +1 -1
  158. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/runtime/uri.d.ts +1 -1
  159. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/standalone/index.js.map +1 -1
  160. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/types/index.d.ts +19 -19
  161. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/types/json-schema.d.ts +15 -14
  162. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/types/jtd-schema.d.ts +30 -25
  163. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/additionalItems.d.ts +1 -1
  164. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js.map +1 -1
  165. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.d.ts +1 -1
  166. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js.map +1 -1
  167. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/anyOf.d.ts +1 -1
  168. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/contains.d.ts +1 -1
  169. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/contains.js.map +1 -1
  170. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/dependencies.d.ts +2 -2
  171. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/dependencies.js.map +1 -1
  172. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/if.d.ts +1 -1
  173. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/if.js.map +1 -1
  174. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/index.d.ts +1 -1
  175. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/items.js.map +1 -1
  176. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/items2020.d.ts +1 -1
  177. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/not.d.ts +1 -1
  178. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/not.js.map +1 -1
  179. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/oneOf.d.ts +1 -1
  180. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/oneOf.js.map +1 -1
  181. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js.map +1 -1
  182. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/properties.js.map +1 -1
  183. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/propertyNames.d.ts +1 -1
  184. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/code.js.map +1 -1
  185. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/core/ref.js.map +1 -1
  186. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/discriminator/index.d.ts +1 -1
  187. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/discriminator/index.js.map +1 -1
  188. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/discriminator/types.d.ts +1 -1
  189. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/discriminator/types.js +1 -1
  190. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/discriminator/types.js.map +1 -1
  191. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/dynamic/dynamicRef.js.map +1 -1
  192. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/errors.d.ts +1 -1
  193. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/format/format.d.ts +1 -1
  194. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/format/format.js.map +1 -1
  195. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/jtd/discriminator.d.ts +1 -1
  196. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/jtd/discriminator.js.map +1 -1
  197. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/jtd/elements.d.ts +1 -1
  198. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/jtd/enum.d.ts +1 -1
  199. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/jtd/enum.js.map +1 -1
  200. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/jtd/error.d.ts +1 -1
  201. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/jtd/index.d.ts +1 -1
  202. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/jtd/metadata.js.map +1 -1
  203. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/jtd/nullable.js.map +1 -1
  204. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/jtd/properties.d.ts +3 -3
  205. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/jtd/properties.js +8 -5
  206. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/jtd/properties.js.map +1 -1
  207. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/jtd/ref.js.map +1 -1
  208. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/jtd/type.d.ts +3 -3
  209. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/jtd/type.js.map +1 -1
  210. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/jtd/values.d.ts +1 -1
  211. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/jtd/values.js +10 -7
  212. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/jtd/values.js.map +1 -1
  213. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedItems.d.ts +1 -1
  214. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedItems.js.map +1 -1
  215. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedProperties.d.ts +1 -1
  216. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedProperties.js.map +1 -1
  217. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/validation/const.d.ts +1 -1
  218. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/validation/const.js.map +1 -1
  219. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/validation/dependentRequired.d.ts +1 -1
  220. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/validation/enum.d.ts +1 -1
  221. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/validation/enum.js.map +1 -1
  222. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/validation/index.d.ts +2 -2
  223. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/validation/limitContains.js.map +1 -1
  224. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/validation/limitNumber.d.ts +3 -3
  225. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/validation/multipleOf.d.ts +1 -1
  226. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/validation/pattern.d.ts +1 -1
  227. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/validation/required.d.ts +1 -1
  228. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/validation/required.js.map +1 -1
  229. package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/validation/uniqueItems.d.ts +1 -1
  230. package/dist/node_modules/ajv-formats/node_modules/ajv/lib/2019.ts +4 -1
  231. package/dist/node_modules/ajv-formats/node_modules/ajv/lib/2020.ts +4 -1
  232. package/dist/node_modules/ajv-formats/node_modules/ajv/lib/ajv.ts +4 -1
  233. package/dist/node_modules/ajv-formats/node_modules/ajv/lib/compile/codegen/index.ts +25 -5
  234. package/dist/node_modules/ajv-formats/node_modules/ajv/lib/compile/jtd/serialize.ts +20 -14
  235. package/dist/node_modules/ajv-formats/node_modules/ajv/lib/compile/jtd/types.ts +1 -1
  236. package/dist/node_modules/ajv-formats/node_modules/ajv/lib/compile/resolve.ts +4 -4
  237. package/dist/node_modules/ajv-formats/node_modules/ajv/lib/compile/rules.ts +1 -1
  238. package/dist/node_modules/ajv-formats/node_modules/ajv/lib/compile/validate/dataType.ts +1 -0
  239. package/dist/node_modules/ajv-formats/node_modules/ajv/lib/compile/validate/index.ts +10 -1
  240. package/dist/node_modules/ajv-formats/node_modules/ajv/lib/core.ts +4 -0
  241. package/dist/node_modules/ajv-formats/node_modules/ajv/lib/jtd.ts +4 -1
  242. package/dist/node_modules/ajv-formats/node_modules/ajv/lib/runtime/parseJson.ts +2 -1
  243. package/dist/node_modules/ajv-formats/node_modules/ajv/lib/types/index.ts +7 -3
  244. package/dist/node_modules/ajv-formats/node_modules/ajv/lib/types/json-schema.ts +1 -0
  245. package/dist/node_modules/ajv-formats/node_modules/ajv/lib/types/jtd-schema.ts +21 -11
  246. package/dist/node_modules/ajv-formats/node_modules/ajv/lib/vocabularies/jtd/properties.ts +13 -6
  247. package/dist/node_modules/ajv-formats/node_modules/ajv/lib/vocabularies/jtd/values.ts +10 -7
  248. package/dist/node_modules/ajv-formats/node_modules/ajv/package.json +40 -40
  249. package/dist/node_modules/commander/Readme.md +407 -169
  250. package/dist/node_modules/commander/esm.mjs +13 -1
  251. package/dist/node_modules/commander/index.js +13 -2206
  252. package/dist/node_modules/commander/lib/argument.js +145 -0
  253. package/dist/node_modules/commander/lib/command.js +2299 -0
  254. package/dist/node_modules/commander/lib/error.js +43 -0
  255. package/dist/node_modules/commander/lib/help.js +457 -0
  256. package/dist/node_modules/commander/lib/option.js +327 -0
  257. package/dist/node_modules/commander/lib/suggestSimilar.js +100 -0
  258. package/dist/node_modules/commander/package.json +46 -34
  259. package/dist/node_modules/commander/typings/esm.d.mts +3 -0
  260. package/dist/node_modules/commander/typings/index.d.ts +889 -617
  261. package/dist/node_modules/graceful-fs/package.json +6 -3
  262. package/dist/node_modules/graceful-fs/polyfills.js +1 -1
  263. package/dist/node_modules/punycode/README.md +29 -3
  264. package/dist/node_modules/punycode/package.json +7 -7
  265. package/dist/node_modules/punycode/punycode.es6.js +25 -22
  266. package/dist/node_modules/punycode/punycode.js +25 -22
  267. package/dist/node_modules/universalify/README.md +1 -1
  268. package/dist/node_modules/universalify/index.js +6 -6
  269. package/dist/node_modules/universalify/package.json +2 -2
  270. package/dist/package.json +1 -2
  271. package/dist/util/cache/cloneIntoCache.js +1 -1
  272. package/dist/util/cache/getCachedItemPath.js +4 -2
  273. package/dist/util/cache/getJsonFromCachedFile.js +2 -2
  274. package/dist/util/getGitRepoNameFromUrl.js +1 -1
  275. package/dist/util/getRepositoryLatestTag.js +16 -0
  276. package/package.json +2 -3
  277. package/dist/node_modules/commander/CHANGELOG.md +0 -440
@@ -0,0 +1,2299 @@
1
+ const EventEmitter = require('events').EventEmitter;
2
+ const childProcess = require('child_process');
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+ const process = require('process');
6
+
7
+ const { Argument, humanReadableArgName } = require('./argument.js');
8
+ const { CommanderError } = require('./error.js');
9
+ const { Help } = require('./help.js');
10
+ const { Option, DualOptions } = require('./option.js');
11
+ const { suggestSimilar } = require('./suggestSimilar');
12
+
13
+ class Command extends EventEmitter {
14
+ /**
15
+ * Initialize a new `Command`.
16
+ *
17
+ * @param {string} [name]
18
+ */
19
+
20
+ constructor(name) {
21
+ super();
22
+ /** @type {Command[]} */
23
+ this.commands = [];
24
+ /** @type {Option[]} */
25
+ this.options = [];
26
+ this.parent = null;
27
+ this._allowUnknownOption = false;
28
+ this._allowExcessArguments = true;
29
+ /** @type {Argument[]} */
30
+ this.registeredArguments = [];
31
+ this._args = this.registeredArguments; // deprecated old name
32
+ /** @type {string[]} */
33
+ this.args = []; // cli args with options removed
34
+ this.rawArgs = [];
35
+ this.processedArgs = []; // like .args but after custom processing and collecting variadic
36
+ this._scriptPath = null;
37
+ this._name = name || '';
38
+ this._optionValues = {};
39
+ this._optionValueSources = {}; // default, env, cli etc
40
+ this._storeOptionsAsProperties = false;
41
+ this._actionHandler = null;
42
+ this._executableHandler = false;
43
+ this._executableFile = null; // custom name for executable
44
+ this._executableDir = null; // custom search directory for subcommands
45
+ this._defaultCommandName = null;
46
+ this._exitCallback = null;
47
+ this._aliases = [];
48
+ this._combineFlagAndOptionalValue = true;
49
+ this._description = '';
50
+ this._summary = '';
51
+ this._argsDescription = undefined; // legacy
52
+ this._enablePositionalOptions = false;
53
+ this._passThroughOptions = false;
54
+ this._lifeCycleHooks = {}; // a hash of arrays
55
+ /** @type {(boolean | string)} */
56
+ this._showHelpAfterError = false;
57
+ this._showSuggestionAfterError = true;
58
+
59
+ // see .configureOutput() for docs
60
+ this._outputConfiguration = {
61
+ writeOut: (str) => process.stdout.write(str),
62
+ writeErr: (str) => process.stderr.write(str),
63
+ getOutHelpWidth: () => process.stdout.isTTY ? process.stdout.columns : undefined,
64
+ getErrHelpWidth: () => process.stderr.isTTY ? process.stderr.columns : undefined,
65
+ outputError: (str, write) => write(str)
66
+ };
67
+
68
+ this._hidden = false;
69
+ /** @type {(Option | null | undefined)} */
70
+ this._helpOption = undefined; // Lazy created on demand. May be null if help option is disabled.
71
+ this._addImplicitHelpCommand = undefined; // undecided whether true or false yet, not inherited
72
+ /** @type {Command} */
73
+ this._helpCommand = undefined; // lazy initialised, inherited
74
+ this._helpConfiguration = {};
75
+ }
76
+
77
+ /**
78
+ * Copy settings that are useful to have in common across root command and subcommands.
79
+ *
80
+ * (Used internally when adding a command using `.command()` so subcommands inherit parent settings.)
81
+ *
82
+ * @param {Command} sourceCommand
83
+ * @return {Command} `this` command for chaining
84
+ */
85
+ copyInheritedSettings(sourceCommand) {
86
+ this._outputConfiguration = sourceCommand._outputConfiguration;
87
+ this._helpOption = sourceCommand._helpOption;
88
+ this._helpCommand = sourceCommand._helpCommand;
89
+ this._helpConfiguration = sourceCommand._helpConfiguration;
90
+ this._exitCallback = sourceCommand._exitCallback;
91
+ this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
92
+ this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
93
+ this._allowExcessArguments = sourceCommand._allowExcessArguments;
94
+ this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
95
+ this._showHelpAfterError = sourceCommand._showHelpAfterError;
96
+ this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
97
+
98
+ return this;
99
+ }
100
+
101
+ /**
102
+ * @returns {Command[]}
103
+ * @private
104
+ */
105
+
106
+ _getCommandAndAncestors() {
107
+ const result = [];
108
+ for (let command = this; command; command = command.parent) {
109
+ result.push(command);
110
+ }
111
+ return result;
112
+ }
113
+
114
+ /**
115
+ * Define a command.
116
+ *
117
+ * There are two styles of command: pay attention to where to put the description.
118
+ *
119
+ * @example
120
+ * // Command implemented using action handler (description is supplied separately to `.command`)
121
+ * program
122
+ * .command('clone <source> [destination]')
123
+ * .description('clone a repository into a newly created directory')
124
+ * .action((source, destination) => {
125
+ * console.log('clone command called');
126
+ * });
127
+ *
128
+ * // Command implemented using separate executable file (description is second parameter to `.command`)
129
+ * program
130
+ * .command('start <service>', 'start named service')
131
+ * .command('stop [service]', 'stop named service, or all if no name supplied');
132
+ *
133
+ * @param {string} nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
134
+ * @param {(Object|string)} [actionOptsOrExecDesc] - configuration options (for action), or description (for executable)
135
+ * @param {Object} [execOpts] - configuration options (for executable)
136
+ * @return {Command} returns new command for action handler, or `this` for executable command
137
+ */
138
+
139
+ command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
140
+ let desc = actionOptsOrExecDesc;
141
+ let opts = execOpts;
142
+ if (typeof desc === 'object' && desc !== null) {
143
+ opts = desc;
144
+ desc = null;
145
+ }
146
+ opts = opts || {};
147
+ const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
148
+
149
+ const cmd = this.createCommand(name);
150
+ if (desc) {
151
+ cmd.description(desc);
152
+ cmd._executableHandler = true;
153
+ }
154
+ if (opts.isDefault) this._defaultCommandName = cmd._name;
155
+ cmd._hidden = !!(opts.noHelp || opts.hidden); // noHelp is deprecated old name for hidden
156
+ cmd._executableFile = opts.executableFile || null; // Custom name for executable file, set missing to null to match constructor
157
+ if (args) cmd.arguments(args);
158
+ this._registerCommand(cmd);
159
+ cmd.parent = this;
160
+ cmd.copyInheritedSettings(this);
161
+
162
+ if (desc) return this;
163
+ return cmd;
164
+ }
165
+
166
+ /**
167
+ * Factory routine to create a new unattached command.
168
+ *
169
+ * See .command() for creating an attached subcommand, which uses this routine to
170
+ * create the command. You can override createCommand to customise subcommands.
171
+ *
172
+ * @param {string} [name]
173
+ * @return {Command} new command
174
+ */
175
+
176
+ createCommand(name) {
177
+ return new Command(name);
178
+ }
179
+
180
+ /**
181
+ * You can customise the help with a subclass of Help by overriding createHelp,
182
+ * or by overriding Help properties using configureHelp().
183
+ *
184
+ * @return {Help}
185
+ */
186
+
187
+ createHelp() {
188
+ return Object.assign(new Help(), this.configureHelp());
189
+ }
190
+
191
+ /**
192
+ * You can customise the help by overriding Help properties using configureHelp(),
193
+ * or with a subclass of Help by overriding createHelp().
194
+ *
195
+ * @param {Object} [configuration] - configuration options
196
+ * @return {(Command|Object)} `this` command for chaining, or stored configuration
197
+ */
198
+
199
+ configureHelp(configuration) {
200
+ if (configuration === undefined) return this._helpConfiguration;
201
+
202
+ this._helpConfiguration = configuration;
203
+ return this;
204
+ }
205
+
206
+ /**
207
+ * The default output goes to stdout and stderr. You can customise this for special
208
+ * applications. You can also customise the display of errors by overriding outputError.
209
+ *
210
+ * The configuration properties are all functions:
211
+ *
212
+ * // functions to change where being written, stdout and stderr
213
+ * writeOut(str)
214
+ * writeErr(str)
215
+ * // matching functions to specify width for wrapping help
216
+ * getOutHelpWidth()
217
+ * getErrHelpWidth()
218
+ * // functions based on what is being written out
219
+ * outputError(str, write) // used for displaying errors, and not used for displaying help
220
+ *
221
+ * @param {Object} [configuration] - configuration options
222
+ * @return {(Command|Object)} `this` command for chaining, or stored configuration
223
+ */
224
+
225
+ configureOutput(configuration) {
226
+ if (configuration === undefined) return this._outputConfiguration;
227
+
228
+ Object.assign(this._outputConfiguration, configuration);
229
+ return this;
230
+ }
231
+
232
+ /**
233
+ * Display the help or a custom message after an error occurs.
234
+ *
235
+ * @param {(boolean|string)} [displayHelp]
236
+ * @return {Command} `this` command for chaining
237
+ */
238
+ showHelpAfterError(displayHelp = true) {
239
+ if (typeof displayHelp !== 'string') displayHelp = !!displayHelp;
240
+ this._showHelpAfterError = displayHelp;
241
+ return this;
242
+ }
243
+
244
+ /**
245
+ * Display suggestion of similar commands for unknown commands, or options for unknown options.
246
+ *
247
+ * @param {boolean} [displaySuggestion]
248
+ * @return {Command} `this` command for chaining
249
+ */
250
+ showSuggestionAfterError(displaySuggestion = true) {
251
+ this._showSuggestionAfterError = !!displaySuggestion;
252
+ return this;
253
+ }
254
+
255
+ /**
256
+ * Add a prepared subcommand.
257
+ *
258
+ * See .command() for creating an attached subcommand which inherits settings from its parent.
259
+ *
260
+ * @param {Command} cmd - new subcommand
261
+ * @param {Object} [opts] - configuration options
262
+ * @return {Command} `this` command for chaining
263
+ */
264
+
265
+ addCommand(cmd, opts) {
266
+ if (!cmd._name) {
267
+ throw new Error(`Command passed to .addCommand() must have a name
268
+ - specify the name in Command constructor or using .name()`);
269
+ }
270
+
271
+ opts = opts || {};
272
+ if (opts.isDefault) this._defaultCommandName = cmd._name;
273
+ if (opts.noHelp || opts.hidden) cmd._hidden = true; // modifying passed command due to existing implementation
274
+
275
+ this._registerCommand(cmd);
276
+ cmd.parent = this;
277
+ cmd._checkForBrokenPassThrough();
278
+
279
+ return this;
280
+ }
281
+
282
+ /**
283
+ * Factory routine to create a new unattached argument.
284
+ *
285
+ * See .argument() for creating an attached argument, which uses this routine to
286
+ * create the argument. You can override createArgument to return a custom argument.
287
+ *
288
+ * @param {string} name
289
+ * @param {string} [description]
290
+ * @return {Argument} new argument
291
+ */
292
+
293
+ createArgument(name, description) {
294
+ return new Argument(name, description);
295
+ }
296
+
297
+ /**
298
+ * Define argument syntax for command.
299
+ *
300
+ * The default is that the argument is required, and you can explicitly
301
+ * indicate this with <> around the name. Put [] around the name for an optional argument.
302
+ *
303
+ * @example
304
+ * program.argument('<input-file>');
305
+ * program.argument('[output-file]');
306
+ *
307
+ * @param {string} name
308
+ * @param {string} [description]
309
+ * @param {(Function|*)} [fn] - custom argument processing function
310
+ * @param {*} [defaultValue]
311
+ * @return {Command} `this` command for chaining
312
+ */
313
+ argument(name, description, fn, defaultValue) {
314
+ const argument = this.createArgument(name, description);
315
+ if (typeof fn === 'function') {
316
+ argument.default(defaultValue).argParser(fn);
317
+ } else {
318
+ argument.default(fn);
319
+ }
320
+ this.addArgument(argument);
321
+ return this;
322
+ }
323
+
324
+ /**
325
+ * Define argument syntax for command, adding multiple at once (without descriptions).
326
+ *
327
+ * See also .argument().
328
+ *
329
+ * @example
330
+ * program.arguments('<cmd> [env]');
331
+ *
332
+ * @param {string} names
333
+ * @return {Command} `this` command for chaining
334
+ */
335
+
336
+ arguments(names) {
337
+ names.trim().split(/ +/).forEach((detail) => {
338
+ this.argument(detail);
339
+ });
340
+ return this;
341
+ }
342
+
343
+ /**
344
+ * Define argument syntax for command, adding a prepared argument.
345
+ *
346
+ * @param {Argument} argument
347
+ * @return {Command} `this` command for chaining
348
+ */
349
+ addArgument(argument) {
350
+ const previousArgument = this.registeredArguments.slice(-1)[0];
351
+ if (previousArgument && previousArgument.variadic) {
352
+ throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
353
+ }
354
+ if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
355
+ throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
356
+ }
357
+ this.registeredArguments.push(argument);
358
+ return this;
359
+ }
360
+
361
+ /**
362
+ * Customise or override default help command. By default a help command is automatically added if your command has subcommands.
363
+ *
364
+ * program.helpCommand('help [cmd]');
365
+ * program.helpCommand('help [cmd]', 'show help');
366
+ * program.helpCommand(false); // suppress default help command
367
+ * program.helpCommand(true); // add help command even if no subcommands
368
+ *
369
+ * @param {string|boolean} enableOrNameAndArgs - enable with custom name and/or arguments, or boolean to override whether added
370
+ * @param {string} [description] - custom description
371
+ * @return {Command} `this` command for chaining
372
+ */
373
+
374
+ helpCommand(enableOrNameAndArgs, description) {
375
+ if (typeof enableOrNameAndArgs === 'boolean') {
376
+ this._addImplicitHelpCommand = enableOrNameAndArgs;
377
+ return this;
378
+ }
379
+
380
+ enableOrNameAndArgs = enableOrNameAndArgs ?? 'help [command]';
381
+ const [, helpName, helpArgs] = enableOrNameAndArgs.match(/([^ ]+) *(.*)/);
382
+ const helpDescription = description ?? 'display help for command';
383
+
384
+ const helpCommand = this.createCommand(helpName);
385
+ helpCommand.helpOption(false);
386
+ if (helpArgs) helpCommand.arguments(helpArgs);
387
+ if (helpDescription) helpCommand.description(helpDescription);
388
+
389
+ this._addImplicitHelpCommand = true;
390
+ this._helpCommand = helpCommand;
391
+
392
+ return this;
393
+ }
394
+
395
+ /**
396
+ * Add prepared custom help command.
397
+ *
398
+ * @param {(Command|string|boolean)} helpCommand - custom help command, or deprecated enableOrNameAndArgs as for `.helpCommand()`
399
+ * @param {string} [deprecatedDescription] - deprecated custom description used with custom name only
400
+ * @return {Command} `this` command for chaining
401
+ */
402
+ addHelpCommand(helpCommand, deprecatedDescription) {
403
+ // If not passed an object, call through to helpCommand for backwards compatibility,
404
+ // as addHelpCommand was originally used like helpCommand is now.
405
+ if (typeof helpCommand !== 'object') {
406
+ this.helpCommand(helpCommand, deprecatedDescription);
407
+ return this;
408
+ }
409
+
410
+ this._addImplicitHelpCommand = true;
411
+ this._helpCommand = helpCommand;
412
+ return this;
413
+ }
414
+
415
+ /**
416
+ * Lazy create help command.
417
+ *
418
+ * @return {(Command|null)}
419
+ * @package
420
+ */
421
+ _getHelpCommand() {
422
+ const hasImplicitHelpCommand = this._addImplicitHelpCommand ??
423
+ (this.commands.length && !this._actionHandler && !this._findCommand('help'));
424
+
425
+ if (hasImplicitHelpCommand) {
426
+ if (this._helpCommand === undefined) {
427
+ this.helpCommand(undefined, undefined); // use default name and description
428
+ }
429
+ return this._helpCommand;
430
+ }
431
+ return null;
432
+ }
433
+
434
+ /**
435
+ * Add hook for life cycle event.
436
+ *
437
+ * @param {string} event
438
+ * @param {Function} listener
439
+ * @return {Command} `this` command for chaining
440
+ */
441
+
442
+ hook(event, listener) {
443
+ const allowedValues = ['preSubcommand', 'preAction', 'postAction'];
444
+ if (!allowedValues.includes(event)) {
445
+ throw new Error(`Unexpected value for event passed to hook : '${event}'.
446
+ Expecting one of '${allowedValues.join("', '")}'`);
447
+ }
448
+ if (this._lifeCycleHooks[event]) {
449
+ this._lifeCycleHooks[event].push(listener);
450
+ } else {
451
+ this._lifeCycleHooks[event] = [listener];
452
+ }
453
+ return this;
454
+ }
455
+
456
+ /**
457
+ * Register callback to use as replacement for calling process.exit.
458
+ *
459
+ * @param {Function} [fn] optional callback which will be passed a CommanderError, defaults to throwing
460
+ * @return {Command} `this` command for chaining
461
+ */
462
+
463
+ exitOverride(fn) {
464
+ if (fn) {
465
+ this._exitCallback = fn;
466
+ } else {
467
+ this._exitCallback = (err) => {
468
+ if (err.code !== 'commander.executeSubCommandAsync') {
469
+ throw err;
470
+ } else {
471
+ // Async callback from spawn events, not useful to throw.
472
+ }
473
+ };
474
+ }
475
+ return this;
476
+ }
477
+
478
+ /**
479
+ * Call process.exit, and _exitCallback if defined.
480
+ *
481
+ * @param {number} exitCode exit code for using with process.exit
482
+ * @param {string} code an id string representing the error
483
+ * @param {string} message human-readable description of the error
484
+ * @return never
485
+ * @private
486
+ */
487
+
488
+ _exit(exitCode, code, message) {
489
+ if (this._exitCallback) {
490
+ this._exitCallback(new CommanderError(exitCode, code, message));
491
+ // Expecting this line is not reached.
492
+ }
493
+ process.exit(exitCode);
494
+ }
495
+
496
+ /**
497
+ * Register callback `fn` for the command.
498
+ *
499
+ * @example
500
+ * program
501
+ * .command('serve')
502
+ * .description('start service')
503
+ * .action(function() {
504
+ * // do work here
505
+ * });
506
+ *
507
+ * @param {Function} fn
508
+ * @return {Command} `this` command for chaining
509
+ */
510
+
511
+ action(fn) {
512
+ const listener = (args) => {
513
+ // The .action callback takes an extra parameter which is the command or options.
514
+ const expectedArgsCount = this.registeredArguments.length;
515
+ const actionArgs = args.slice(0, expectedArgsCount);
516
+ if (this._storeOptionsAsProperties) {
517
+ actionArgs[expectedArgsCount] = this; // backwards compatible "options"
518
+ } else {
519
+ actionArgs[expectedArgsCount] = this.opts();
520
+ }
521
+ actionArgs.push(this);
522
+
523
+ return fn.apply(this, actionArgs);
524
+ };
525
+ this._actionHandler = listener;
526
+ return this;
527
+ }
528
+
529
+ /**
530
+ * Factory routine to create a new unattached option.
531
+ *
532
+ * See .option() for creating an attached option, which uses this routine to
533
+ * create the option. You can override createOption to return a custom option.
534
+ *
535
+ * @param {string} flags
536
+ * @param {string} [description]
537
+ * @return {Option} new option
538
+ */
539
+
540
+ createOption(flags, description) {
541
+ return new Option(flags, description);
542
+ }
543
+
544
+ /**
545
+ * Wrap parseArgs to catch 'commander.invalidArgument'.
546
+ *
547
+ * @param {(Option | Argument)} target
548
+ * @param {string} value
549
+ * @param {*} previous
550
+ * @param {string} invalidArgumentMessage
551
+ * @private
552
+ */
553
+
554
+ _callParseArg(target, value, previous, invalidArgumentMessage) {
555
+ try {
556
+ return target.parseArg(value, previous);
557
+ } catch (err) {
558
+ if (err.code === 'commander.invalidArgument') {
559
+ const message = `${invalidArgumentMessage} ${err.message}`;
560
+ this.error(message, { exitCode: err.exitCode, code: err.code });
561
+ }
562
+ throw err;
563
+ }
564
+ }
565
+
566
+ /**
567
+ * Check for option flag conflicts.
568
+ * Register option if no conflicts found, or throw on conflict.
569
+ *
570
+ * @param {Option} option
571
+ * @api private
572
+ */
573
+
574
+ _registerOption(option) {
575
+ const matchingOption = (option.short && this._findOption(option.short)) ||
576
+ (option.long && this._findOption(option.long));
577
+ if (matchingOption) {
578
+ const matchingFlag = (option.long && this._findOption(option.long)) ? option.long : option.short;
579
+ throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
580
+ - already used by option '${matchingOption.flags}'`);
581
+ }
582
+
583
+ this.options.push(option);
584
+ }
585
+
586
+ /**
587
+ * Check for command name and alias conflicts with existing commands.
588
+ * Register command if no conflicts found, or throw on conflict.
589
+ *
590
+ * @param {Command} command
591
+ * @api private
592
+ */
593
+
594
+ _registerCommand(command) {
595
+ const knownBy = (cmd) => {
596
+ return [cmd.name()].concat(cmd.aliases());
597
+ };
598
+
599
+ const alreadyUsed = knownBy(command).find((name) => this._findCommand(name));
600
+ if (alreadyUsed) {
601
+ const existingCmd = knownBy(this._findCommand(alreadyUsed)).join('|');
602
+ const newCmd = knownBy(command).join('|');
603
+ throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
604
+ }
605
+
606
+ this.commands.push(command);
607
+ }
608
+
609
+ /**
610
+ * Add an option.
611
+ *
612
+ * @param {Option} option
613
+ * @return {Command} `this` command for chaining
614
+ */
615
+ addOption(option) {
616
+ this._registerOption(option);
617
+
618
+ const oname = option.name();
619
+ const name = option.attributeName();
620
+
621
+ // store default value
622
+ if (option.negate) {
623
+ // --no-foo is special and defaults foo to true, unless a --foo option is already defined
624
+ const positiveLongFlag = option.long.replace(/^--no-/, '--');
625
+ if (!this._findOption(positiveLongFlag)) {
626
+ this.setOptionValueWithSource(name, option.defaultValue === undefined ? true : option.defaultValue, 'default');
627
+ }
628
+ } else if (option.defaultValue !== undefined) {
629
+ this.setOptionValueWithSource(name, option.defaultValue, 'default');
630
+ }
631
+
632
+ // handler for cli and env supplied values
633
+ const handleOptionValue = (val, invalidValueMessage, valueSource) => {
634
+ // val is null for optional option used without an optional-argument.
635
+ // val is undefined for boolean and negated option.
636
+ if (val == null && option.presetArg !== undefined) {
637
+ val = option.presetArg;
638
+ }
639
+
640
+ // custom processing
641
+ const oldValue = this.getOptionValue(name);
642
+ if (val !== null && option.parseArg) {
643
+ val = this._callParseArg(option, val, oldValue, invalidValueMessage);
644
+ } else if (val !== null && option.variadic) {
645
+ val = option._concatValue(val, oldValue);
646
+ }
647
+
648
+ // Fill-in appropriate missing values. Long winded but easy to follow.
649
+ if (val == null) {
650
+ if (option.negate) {
651
+ val = false;
652
+ } else if (option.isBoolean() || option.optional) {
653
+ val = true;
654
+ } else {
655
+ val = ''; // not normal, parseArg might have failed or be a mock function for testing
656
+ }
657
+ }
658
+ this.setOptionValueWithSource(name, val, valueSource);
659
+ };
660
+
661
+ this.on('option:' + oname, (val) => {
662
+ const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
663
+ handleOptionValue(val, invalidValueMessage, 'cli');
664
+ });
665
+
666
+ if (option.envVar) {
667
+ this.on('optionEnv:' + oname, (val) => {
668
+ const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
669
+ handleOptionValue(val, invalidValueMessage, 'env');
670
+ });
671
+ }
672
+
673
+ return this;
674
+ }
675
+
676
+ /**
677
+ * Internal implementation shared by .option() and .requiredOption()
678
+ *
679
+ * @private
680
+ */
681
+ _optionEx(config, flags, description, fn, defaultValue) {
682
+ if (typeof flags === 'object' && flags instanceof Option) {
683
+ throw new Error('To add an Option object use addOption() instead of option() or requiredOption()');
684
+ }
685
+ const option = this.createOption(flags, description);
686
+ option.makeOptionMandatory(!!config.mandatory);
687
+ if (typeof fn === 'function') {
688
+ option.default(defaultValue).argParser(fn);
689
+ } else if (fn instanceof RegExp) {
690
+ // deprecated
691
+ const regex = fn;
692
+ fn = (val, def) => {
693
+ const m = regex.exec(val);
694
+ return m ? m[0] : def;
695
+ };
696
+ option.default(defaultValue).argParser(fn);
697
+ } else {
698
+ option.default(fn);
699
+ }
700
+
701
+ return this.addOption(option);
702
+ }
703
+
704
+ /**
705
+ * Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.
706
+ *
707
+ * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space. A required
708
+ * option-argument is indicated by `<>` and an optional option-argument by `[]`.
709
+ *
710
+ * See the README for more details, and see also addOption() and requiredOption().
711
+ *
712
+ * @example
713
+ * program
714
+ * .option('-p, --pepper', 'add pepper')
715
+ * .option('-p, --pizza-type <TYPE>', 'type of pizza') // required option-argument
716
+ * .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
717
+ * .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
718
+ *
719
+ * @param {string} flags
720
+ * @param {string} [description]
721
+ * @param {(Function|*)} [parseArg] - custom option processing function or default value
722
+ * @param {*} [defaultValue]
723
+ * @return {Command} `this` command for chaining
724
+ */
725
+
726
+ option(flags, description, parseArg, defaultValue) {
727
+ return this._optionEx({}, flags, description, parseArg, defaultValue);
728
+ }
729
+
730
+ /**
731
+ * Add a required option which must have a value after parsing. This usually means
732
+ * the option must be specified on the command line. (Otherwise the same as .option().)
733
+ *
734
+ * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
735
+ *
736
+ * @param {string} flags
737
+ * @param {string} [description]
738
+ * @param {(Function|*)} [parseArg] - custom option processing function or default value
739
+ * @param {*} [defaultValue]
740
+ * @return {Command} `this` command for chaining
741
+ */
742
+
743
+ requiredOption(flags, description, parseArg, defaultValue) {
744
+ return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
745
+ }
746
+
747
+ /**
748
+ * Alter parsing of short flags with optional values.
749
+ *
750
+ * @example
751
+ * // for `.option('-f,--flag [value]'):
752
+ * program.combineFlagAndOptionalValue(true); // `-f80` is treated like `--flag=80`, this is the default behaviour
753
+ * program.combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
754
+ *
755
+ * @param {boolean} [combine=true] - if `true` or omitted, an optional value can be specified directly after the flag.
756
+ */
757
+ combineFlagAndOptionalValue(combine = true) {
758
+ this._combineFlagAndOptionalValue = !!combine;
759
+ return this;
760
+ }
761
+
762
+ /**
763
+ * Allow unknown options on the command line.
764
+ *
765
+ * @param {boolean} [allowUnknown=true] - if `true` or omitted, no error will be thrown
766
+ * for unknown options.
767
+ */
768
+ allowUnknownOption(allowUnknown = true) {
769
+ this._allowUnknownOption = !!allowUnknown;
770
+ return this;
771
+ }
772
+
773
+ /**
774
+ * Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
775
+ *
776
+ * @param {boolean} [allowExcess=true] - if `true` or omitted, no error will be thrown
777
+ * for excess arguments.
778
+ */
779
+ allowExcessArguments(allowExcess = true) {
780
+ this._allowExcessArguments = !!allowExcess;
781
+ return this;
782
+ }
783
+
784
+ /**
785
+ * Enable positional options. Positional means global options are specified before subcommands which lets
786
+ * subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
787
+ * The default behaviour is non-positional and global options may appear anywhere on the command line.
788
+ *
789
+ * @param {boolean} [positional=true]
790
+ */
791
+ enablePositionalOptions(positional = true) {
792
+ this._enablePositionalOptions = !!positional;
793
+ return this;
794
+ }
795
+
796
+ /**
797
+ * Pass through options that come after command-arguments rather than treat them as command-options,
798
+ * so actual command-options come before command-arguments. Turning this on for a subcommand requires
799
+ * positional options to have been enabled on the program (parent commands).
800
+ * The default behaviour is non-positional and options may appear before or after command-arguments.
801
+ *
802
+ * @param {boolean} [passThrough=true]
803
+ * for unknown options.
804
+ */
805
+ passThroughOptions(passThrough = true) {
806
+ this._passThroughOptions = !!passThrough;
807
+ this._checkForBrokenPassThrough();
808
+ return this;
809
+ }
810
+
811
+ /**
812
+ * @private
813
+ */
814
+
815
+ _checkForBrokenPassThrough() {
816
+ if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
817
+ throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
818
+ }
819
+ }
820
+
821
+ /**
822
+ * Whether to store option values as properties on command object,
823
+ * or store separately (specify false). In both cases the option values can be accessed using .opts().
824
+ *
825
+ * @param {boolean} [storeAsProperties=true]
826
+ * @return {Command} `this` command for chaining
827
+ */
828
+
829
+ storeOptionsAsProperties(storeAsProperties = true) {
830
+ if (this.options.length) {
831
+ throw new Error('call .storeOptionsAsProperties() before adding options');
832
+ }
833
+ if (Object.keys(this._optionValues).length) {
834
+ throw new Error('call .storeOptionsAsProperties() before setting option values');
835
+ }
836
+ this._storeOptionsAsProperties = !!storeAsProperties;
837
+ return this;
838
+ }
839
+
840
+ /**
841
+ * Retrieve option value.
842
+ *
843
+ * @param {string} key
844
+ * @return {Object} value
845
+ */
846
+
847
+ getOptionValue(key) {
848
+ if (this._storeOptionsAsProperties) {
849
+ return this[key];
850
+ }
851
+ return this._optionValues[key];
852
+ }
853
+
854
+ /**
855
+ * Store option value.
856
+ *
857
+ * @param {string} key
858
+ * @param {Object} value
859
+ * @return {Command} `this` command for chaining
860
+ */
861
+
862
+ setOptionValue(key, value) {
863
+ return this.setOptionValueWithSource(key, value, undefined);
864
+ }
865
+
866
+ /**
867
+ * Store option value and where the value came from.
868
+ *
869
+ * @param {string} key
870
+ * @param {Object} value
871
+ * @param {string} source - expected values are default/config/env/cli/implied
872
+ * @return {Command} `this` command for chaining
873
+ */
874
+
875
+ setOptionValueWithSource(key, value, source) {
876
+ if (this._storeOptionsAsProperties) {
877
+ this[key] = value;
878
+ } else {
879
+ this._optionValues[key] = value;
880
+ }
881
+ this._optionValueSources[key] = source;
882
+ return this;
883
+ }
884
+
885
+ /**
886
+ * Get source of option value.
887
+ * Expected values are default | config | env | cli | implied
888
+ *
889
+ * @param {string} key
890
+ * @return {string}
891
+ */
892
+
893
+ getOptionValueSource(key) {
894
+ return this._optionValueSources[key];
895
+ }
896
+
897
+ /**
898
+ * Get source of option value. See also .optsWithGlobals().
899
+ * Expected values are default | config | env | cli | implied
900
+ *
901
+ * @param {string} key
902
+ * @return {string}
903
+ */
904
+
905
+ getOptionValueSourceWithGlobals(key) {
906
+ // global overwrites local, like optsWithGlobals
907
+ let source;
908
+ this._getCommandAndAncestors().forEach((cmd) => {
909
+ if (cmd.getOptionValueSource(key) !== undefined) {
910
+ source = cmd.getOptionValueSource(key);
911
+ }
912
+ });
913
+ return source;
914
+ }
915
+
916
+ /**
917
+ * Get user arguments from implied or explicit arguments.
918
+ * Side-effects: set _scriptPath if args included script. Used for default program name, and subcommand searches.
919
+ *
920
+ * @private
921
+ */
922
+
923
+ _prepareUserArgs(argv, parseOptions) {
924
+ if (argv !== undefined && !Array.isArray(argv)) {
925
+ throw new Error('first parameter to parse must be array or undefined');
926
+ }
927
+ parseOptions = parseOptions || {};
928
+
929
+ // Default to using process.argv
930
+ if (argv === undefined) {
931
+ argv = process.argv;
932
+ // @ts-ignore: unknown property
933
+ if (process.versions && process.versions.electron) {
934
+ parseOptions.from = 'electron';
935
+ }
936
+ }
937
+ this.rawArgs = argv.slice();
938
+
939
+ // make it a little easier for callers by supporting various argv conventions
940
+ let userArgs;
941
+ switch (parseOptions.from) {
942
+ case undefined:
943
+ case 'node':
944
+ this._scriptPath = argv[1];
945
+ userArgs = argv.slice(2);
946
+ break;
947
+ case 'electron':
948
+ // @ts-ignore: unknown property
949
+ if (process.defaultApp) {
950
+ this._scriptPath = argv[1];
951
+ userArgs = argv.slice(2);
952
+ } else {
953
+ userArgs = argv.slice(1);
954
+ }
955
+ break;
956
+ case 'user':
957
+ userArgs = argv.slice(0);
958
+ break;
959
+ default:
960
+ throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
961
+ }
962
+
963
+ // Find default name for program from arguments.
964
+ if (!this._name && this._scriptPath) this.nameFromFilename(this._scriptPath);
965
+ this._name = this._name || 'program';
966
+
967
+ return userArgs;
968
+ }
969
+
970
+ /**
971
+ * Parse `argv`, setting options and invoking commands when defined.
972
+ *
973
+ * The default expectation is that the arguments are from node and have the application as argv[0]
974
+ * and the script being run in argv[1], with user parameters after that.
975
+ *
976
+ * @example
977
+ * program.parse(process.argv);
978
+ * program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions
979
+ * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
980
+ *
981
+ * @param {string[]} [argv] - optional, defaults to process.argv
982
+ * @param {Object} [parseOptions] - optionally specify style of options with from: node/user/electron
983
+ * @param {string} [parseOptions.from] - where the args are from: 'node', 'user', 'electron'
984
+ * @return {Command} `this` command for chaining
985
+ */
986
+
987
+ parse(argv, parseOptions) {
988
+ const userArgs = this._prepareUserArgs(argv, parseOptions);
989
+ this._parseCommand([], userArgs);
990
+
991
+ return this;
992
+ }
993
+
994
+ /**
995
+ * Parse `argv`, setting options and invoking commands when defined.
996
+ *
997
+ * Use parseAsync instead of parse if any of your action handlers are async. Returns a Promise.
998
+ *
999
+ * The default expectation is that the arguments are from node and have the application as argv[0]
1000
+ * and the script being run in argv[1], with user parameters after that.
1001
+ *
1002
+ * @example
1003
+ * await program.parseAsync(process.argv);
1004
+ * await program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions
1005
+ * await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
1006
+ *
1007
+ * @param {string[]} [argv]
1008
+ * @param {Object} [parseOptions]
1009
+ * @param {string} parseOptions.from - where the args are from: 'node', 'user', 'electron'
1010
+ * @return {Promise}
1011
+ */
1012
+
1013
+ async parseAsync(argv, parseOptions) {
1014
+ const userArgs = this._prepareUserArgs(argv, parseOptions);
1015
+ await this._parseCommand([], userArgs);
1016
+
1017
+ return this;
1018
+ }
1019
+
1020
+ /**
1021
+ * Execute a sub-command executable.
1022
+ *
1023
+ * @private
1024
+ */
1025
+
1026
+ _executeSubCommand(subcommand, args) {
1027
+ args = args.slice();
1028
+ let launchWithNode = false; // Use node for source targets so do not need to get permissions correct, and on Windows.
1029
+ const sourceExt = ['.js', '.ts', '.tsx', '.mjs', '.cjs'];
1030
+
1031
+ function findFile(baseDir, baseName) {
1032
+ // Look for specified file
1033
+ const localBin = path.resolve(baseDir, baseName);
1034
+ if (fs.existsSync(localBin)) return localBin;
1035
+
1036
+ // Stop looking if candidate already has an expected extension.
1037
+ if (sourceExt.includes(path.extname(baseName))) return undefined;
1038
+
1039
+ // Try all the extensions.
1040
+ const foundExt = sourceExt.find(ext => fs.existsSync(`${localBin}${ext}`));
1041
+ if (foundExt) return `${localBin}${foundExt}`;
1042
+
1043
+ return undefined;
1044
+ }
1045
+
1046
+ // Not checking for help first. Unlikely to have mandatory and executable, and can't robustly test for help flags in external command.
1047
+ this._checkForMissingMandatoryOptions();
1048
+ this._checkForConflictingOptions();
1049
+
1050
+ // executableFile and executableDir might be full path, or just a name
1051
+ let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
1052
+ let executableDir = this._executableDir || '';
1053
+ if (this._scriptPath) {
1054
+ let resolvedScriptPath; // resolve possible symlink for installed npm binary
1055
+ try {
1056
+ resolvedScriptPath = fs.realpathSync(this._scriptPath);
1057
+ } catch (err) {
1058
+ resolvedScriptPath = this._scriptPath;
1059
+ }
1060
+ executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
1061
+ }
1062
+
1063
+ // Look for a local file in preference to a command in PATH.
1064
+ if (executableDir) {
1065
+ let localFile = findFile(executableDir, executableFile);
1066
+
1067
+ // Legacy search using prefix of script name instead of command name
1068
+ if (!localFile && !subcommand._executableFile && this._scriptPath) {
1069
+ const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
1070
+ if (legacyName !== this._name) {
1071
+ localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
1072
+ }
1073
+ }
1074
+ executableFile = localFile || executableFile;
1075
+ }
1076
+
1077
+ launchWithNode = sourceExt.includes(path.extname(executableFile));
1078
+
1079
+ let proc;
1080
+ if (process.platform !== 'win32') {
1081
+ if (launchWithNode) {
1082
+ args.unshift(executableFile);
1083
+ // add executable arguments to spawn
1084
+ args = incrementNodeInspectorPort(process.execArgv).concat(args);
1085
+
1086
+ proc = childProcess.spawn(process.argv[0], args, { stdio: 'inherit' });
1087
+ } else {
1088
+ proc = childProcess.spawn(executableFile, args, { stdio: 'inherit' });
1089
+ }
1090
+ } else {
1091
+ args.unshift(executableFile);
1092
+ // add executable arguments to spawn
1093
+ args = incrementNodeInspectorPort(process.execArgv).concat(args);
1094
+ proc = childProcess.spawn(process.execPath, args, { stdio: 'inherit' });
1095
+ }
1096
+
1097
+ if (!proc.killed) { // testing mainly to avoid leak warnings during unit tests with mocked spawn
1098
+ const signals = ['SIGUSR1', 'SIGUSR2', 'SIGTERM', 'SIGINT', 'SIGHUP'];
1099
+ signals.forEach((signal) => {
1100
+ // @ts-ignore
1101
+ process.on(signal, () => {
1102
+ if (proc.killed === false && proc.exitCode === null) {
1103
+ proc.kill(signal);
1104
+ }
1105
+ });
1106
+ });
1107
+ }
1108
+
1109
+ // By default terminate process when spawned process terminates.
1110
+ const exitCallback = this._exitCallback;
1111
+ proc.on('close', (code, _signal) => {
1112
+ code = code ?? 1; // code is null if spawned process terminated due to a signal
1113
+ if (!exitCallback) {
1114
+ process.exit(code);
1115
+ } else {
1116
+ exitCallback(new CommanderError(code, 'commander.executeSubCommandAsync', '(close)'));
1117
+ }
1118
+ });
1119
+ proc.on('error', (err) => {
1120
+ // @ts-ignore
1121
+ if (err.code === 'ENOENT') {
1122
+ const executableDirMessage = executableDir
1123
+ ? `searched for local subcommand relative to directory '${executableDir}'`
1124
+ : 'no directory for search for local subcommand, use .executableDir() to supply a custom directory';
1125
+ const executableMissing = `'${executableFile}' does not exist
1126
+ - if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
1127
+ - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
1128
+ - ${executableDirMessage}`;
1129
+ throw new Error(executableMissing);
1130
+ // @ts-ignore
1131
+ } else if (err.code === 'EACCES') {
1132
+ throw new Error(`'${executableFile}' not executable`);
1133
+ }
1134
+ if (!exitCallback) {
1135
+ process.exit(1);
1136
+ } else {
1137
+ const wrappedError = new CommanderError(1, 'commander.executeSubCommandAsync', '(error)');
1138
+ wrappedError.nestedError = err;
1139
+ exitCallback(wrappedError);
1140
+ }
1141
+ });
1142
+
1143
+ // Store the reference to the child process
1144
+ this.runningCommand = proc;
1145
+ }
1146
+
1147
+ /**
1148
+ * @private
1149
+ */
1150
+
1151
+ _dispatchSubcommand(commandName, operands, unknown) {
1152
+ const subCommand = this._findCommand(commandName);
1153
+ if (!subCommand) this.help({ error: true });
1154
+
1155
+ let promiseChain;
1156
+ promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, 'preSubcommand');
1157
+ promiseChain = this._chainOrCall(promiseChain, () => {
1158
+ if (subCommand._executableHandler) {
1159
+ this._executeSubCommand(subCommand, operands.concat(unknown));
1160
+ } else {
1161
+ return subCommand._parseCommand(operands, unknown);
1162
+ }
1163
+ });
1164
+ return promiseChain;
1165
+ }
1166
+
1167
+ /**
1168
+ * Invoke help directly if possible, or dispatch if necessary.
1169
+ * e.g. help foo
1170
+ *
1171
+ * @private
1172
+ */
1173
+
1174
+ _dispatchHelpCommand(subcommandName) {
1175
+ if (!subcommandName) {
1176
+ this.help();
1177
+ }
1178
+ const subCommand = this._findCommand(subcommandName);
1179
+ if (subCommand && !subCommand._executableHandler) {
1180
+ subCommand.help();
1181
+ }
1182
+
1183
+ // Fallback to parsing the help flag to invoke the help.
1184
+ return this._dispatchSubcommand(subcommandName, [], [
1185
+ this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? '--help'
1186
+ ]);
1187
+ }
1188
+
1189
+ /**
1190
+ * Check this.args against expected this.registeredArguments.
1191
+ *
1192
+ * @private
1193
+ */
1194
+
1195
+ _checkNumberOfArguments() {
1196
+ // too few
1197
+ this.registeredArguments.forEach((arg, i) => {
1198
+ if (arg.required && this.args[i] == null) {
1199
+ this.missingArgument(arg.name());
1200
+ }
1201
+ });
1202
+ // too many
1203
+ if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
1204
+ return;
1205
+ }
1206
+ if (this.args.length > this.registeredArguments.length) {
1207
+ this._excessArguments(this.args);
1208
+ }
1209
+ }
1210
+
1211
+ /**
1212
+ * Process this.args using this.registeredArguments and save as this.processedArgs!
1213
+ *
1214
+ * @private
1215
+ */
1216
+
1217
+ _processArguments() {
1218
+ const myParseArg = (argument, value, previous) => {
1219
+ // Extra processing for nice error message on parsing failure.
1220
+ let parsedValue = value;
1221
+ if (value !== null && argument.parseArg) {
1222
+ const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
1223
+ parsedValue = this._callParseArg(argument, value, previous, invalidValueMessage);
1224
+ }
1225
+ return parsedValue;
1226
+ };
1227
+
1228
+ this._checkNumberOfArguments();
1229
+
1230
+ const processedArgs = [];
1231
+ this.registeredArguments.forEach((declaredArg, index) => {
1232
+ let value = declaredArg.defaultValue;
1233
+ if (declaredArg.variadic) {
1234
+ // Collect together remaining arguments for passing together as an array.
1235
+ if (index < this.args.length) {
1236
+ value = this.args.slice(index);
1237
+ if (declaredArg.parseArg) {
1238
+ value = value.reduce((processed, v) => {
1239
+ return myParseArg(declaredArg, v, processed);
1240
+ }, declaredArg.defaultValue);
1241
+ }
1242
+ } else if (value === undefined) {
1243
+ value = [];
1244
+ }
1245
+ } else if (index < this.args.length) {
1246
+ value = this.args[index];
1247
+ if (declaredArg.parseArg) {
1248
+ value = myParseArg(declaredArg, value, declaredArg.defaultValue);
1249
+ }
1250
+ }
1251
+ processedArgs[index] = value;
1252
+ });
1253
+ this.processedArgs = processedArgs;
1254
+ }
1255
+
1256
+ /**
1257
+ * Once we have a promise we chain, but call synchronously until then.
1258
+ *
1259
+ * @param {(Promise|undefined)} promise
1260
+ * @param {Function} fn
1261
+ * @return {(Promise|undefined)}
1262
+ * @private
1263
+ */
1264
+
1265
+ _chainOrCall(promise, fn) {
1266
+ // thenable
1267
+ if (promise && promise.then && typeof promise.then === 'function') {
1268
+ // already have a promise, chain callback
1269
+ return promise.then(() => fn());
1270
+ }
1271
+ // callback might return a promise
1272
+ return fn();
1273
+ }
1274
+
1275
+ /**
1276
+ *
1277
+ * @param {(Promise|undefined)} promise
1278
+ * @param {string} event
1279
+ * @return {(Promise|undefined)}
1280
+ * @private
1281
+ */
1282
+
1283
+ _chainOrCallHooks(promise, event) {
1284
+ let result = promise;
1285
+ const hooks = [];
1286
+ this._getCommandAndAncestors()
1287
+ .reverse()
1288
+ .filter(cmd => cmd._lifeCycleHooks[event] !== undefined)
1289
+ .forEach(hookedCommand => {
1290
+ hookedCommand._lifeCycleHooks[event].forEach((callback) => {
1291
+ hooks.push({ hookedCommand, callback });
1292
+ });
1293
+ });
1294
+ if (event === 'postAction') {
1295
+ hooks.reverse();
1296
+ }
1297
+
1298
+ hooks.forEach((hookDetail) => {
1299
+ result = this._chainOrCall(result, () => {
1300
+ return hookDetail.callback(hookDetail.hookedCommand, this);
1301
+ });
1302
+ });
1303
+ return result;
1304
+ }
1305
+
1306
+ /**
1307
+ *
1308
+ * @param {(Promise|undefined)} promise
1309
+ * @param {Command} subCommand
1310
+ * @param {string} event
1311
+ * @return {(Promise|undefined)}
1312
+ * @private
1313
+ */
1314
+
1315
+ _chainOrCallSubCommandHook(promise, subCommand, event) {
1316
+ let result = promise;
1317
+ if (this._lifeCycleHooks[event] !== undefined) {
1318
+ this._lifeCycleHooks[event].forEach((hook) => {
1319
+ result = this._chainOrCall(result, () => {
1320
+ return hook(this, subCommand);
1321
+ });
1322
+ });
1323
+ }
1324
+ return result;
1325
+ }
1326
+
1327
+ /**
1328
+ * Process arguments in context of this command.
1329
+ * Returns action result, in case it is a promise.
1330
+ *
1331
+ * @private
1332
+ */
1333
+
1334
+ _parseCommand(operands, unknown) {
1335
+ const parsed = this.parseOptions(unknown);
1336
+ this._parseOptionsEnv(); // after cli, so parseArg not called on both cli and env
1337
+ this._parseOptionsImplied();
1338
+ operands = operands.concat(parsed.operands);
1339
+ unknown = parsed.unknown;
1340
+ this.args = operands.concat(unknown);
1341
+
1342
+ if (operands && this._findCommand(operands[0])) {
1343
+ return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
1344
+ }
1345
+ if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
1346
+ return this._dispatchHelpCommand(operands[1]);
1347
+ }
1348
+ if (this._defaultCommandName) {
1349
+ this._outputHelpIfRequested(unknown); // Run the help for default command from parent rather than passing to default command
1350
+ return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
1351
+ }
1352
+ if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
1353
+ // probably missing subcommand and no handler, user needs help (and exit)
1354
+ this.help({ error: true });
1355
+ }
1356
+
1357
+ this._outputHelpIfRequested(parsed.unknown);
1358
+ this._checkForMissingMandatoryOptions();
1359
+ this._checkForConflictingOptions();
1360
+
1361
+ // We do not always call this check to avoid masking a "better" error, like unknown command.
1362
+ const checkForUnknownOptions = () => {
1363
+ if (parsed.unknown.length > 0) {
1364
+ this.unknownOption(parsed.unknown[0]);
1365
+ }
1366
+ };
1367
+
1368
+ const commandEvent = `command:${this.name()}`;
1369
+ if (this._actionHandler) {
1370
+ checkForUnknownOptions();
1371
+ this._processArguments();
1372
+
1373
+ let promiseChain;
1374
+ promiseChain = this._chainOrCallHooks(promiseChain, 'preAction');
1375
+ promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
1376
+ if (this.parent) {
1377
+ promiseChain = this._chainOrCall(promiseChain, () => {
1378
+ this.parent.emit(commandEvent, operands, unknown); // legacy
1379
+ });
1380
+ }
1381
+ promiseChain = this._chainOrCallHooks(promiseChain, 'postAction');
1382
+ return promiseChain;
1383
+ }
1384
+ if (this.parent && this.parent.listenerCount(commandEvent)) {
1385
+ checkForUnknownOptions();
1386
+ this._processArguments();
1387
+ this.parent.emit(commandEvent, operands, unknown); // legacy
1388
+ } else if (operands.length) {
1389
+ if (this._findCommand('*')) { // legacy default command
1390
+ return this._dispatchSubcommand('*', operands, unknown);
1391
+ }
1392
+ if (this.listenerCount('command:*')) {
1393
+ // skip option check, emit event for possible misspelling suggestion
1394
+ this.emit('command:*', operands, unknown);
1395
+ } else if (this.commands.length) {
1396
+ this.unknownCommand();
1397
+ } else {
1398
+ checkForUnknownOptions();
1399
+ this._processArguments();
1400
+ }
1401
+ } else if (this.commands.length) {
1402
+ checkForUnknownOptions();
1403
+ // This command has subcommands and nothing hooked up at this level, so display help (and exit).
1404
+ this.help({ error: true });
1405
+ } else {
1406
+ checkForUnknownOptions();
1407
+ this._processArguments();
1408
+ // fall through for caller to handle after calling .parse()
1409
+ }
1410
+ }
1411
+
1412
+ /**
1413
+ * Find matching command.
1414
+ *
1415
+ * @private
1416
+ */
1417
+ _findCommand(name) {
1418
+ if (!name) return undefined;
1419
+ return this.commands.find(cmd => cmd._name === name || cmd._aliases.includes(name));
1420
+ }
1421
+
1422
+ /**
1423
+ * Return an option matching `arg` if any.
1424
+ *
1425
+ * @param {string} arg
1426
+ * @return {Option}
1427
+ * @package internal use only
1428
+ */
1429
+
1430
+ _findOption(arg) {
1431
+ return this.options.find(option => option.is(arg));
1432
+ }
1433
+
1434
+ /**
1435
+ * Display an error message if a mandatory option does not have a value.
1436
+ * Called after checking for help flags in leaf subcommand.
1437
+ *
1438
+ * @private
1439
+ */
1440
+
1441
+ _checkForMissingMandatoryOptions() {
1442
+ // Walk up hierarchy so can call in subcommand after checking for displaying help.
1443
+ this._getCommandAndAncestors().forEach((cmd) => {
1444
+ cmd.options.forEach((anOption) => {
1445
+ if (anOption.mandatory && (cmd.getOptionValue(anOption.attributeName()) === undefined)) {
1446
+ cmd.missingMandatoryOptionValue(anOption);
1447
+ }
1448
+ });
1449
+ });
1450
+ }
1451
+
1452
+ /**
1453
+ * Display an error message if conflicting options are used together in this.
1454
+ *
1455
+ * @private
1456
+ */
1457
+ _checkForConflictingLocalOptions() {
1458
+ const definedNonDefaultOptions = this.options.filter(
1459
+ (option) => {
1460
+ const optionKey = option.attributeName();
1461
+ if (this.getOptionValue(optionKey) === undefined) {
1462
+ return false;
1463
+ }
1464
+ return this.getOptionValueSource(optionKey) !== 'default';
1465
+ }
1466
+ );
1467
+
1468
+ const optionsWithConflicting = definedNonDefaultOptions.filter(
1469
+ (option) => option.conflictsWith.length > 0
1470
+ );
1471
+
1472
+ optionsWithConflicting.forEach((option) => {
1473
+ const conflictingAndDefined = definedNonDefaultOptions.find((defined) =>
1474
+ option.conflictsWith.includes(defined.attributeName())
1475
+ );
1476
+ if (conflictingAndDefined) {
1477
+ this._conflictingOption(option, conflictingAndDefined);
1478
+ }
1479
+ });
1480
+ }
1481
+
1482
+ /**
1483
+ * Display an error message if conflicting options are used together.
1484
+ * Called after checking for help flags in leaf subcommand.
1485
+ *
1486
+ * @private
1487
+ */
1488
+ _checkForConflictingOptions() {
1489
+ // Walk up hierarchy so can call in subcommand after checking for displaying help.
1490
+ this._getCommandAndAncestors().forEach((cmd) => {
1491
+ cmd._checkForConflictingLocalOptions();
1492
+ });
1493
+ }
1494
+
1495
+ /**
1496
+ * Parse options from `argv` removing known options,
1497
+ * and return argv split into operands and unknown arguments.
1498
+ *
1499
+ * Examples:
1500
+ *
1501
+ * argv => operands, unknown
1502
+ * --known kkk op => [op], []
1503
+ * op --known kkk => [op], []
1504
+ * sub --unknown uuu op => [sub], [--unknown uuu op]
1505
+ * sub -- --unknown uuu op => [sub --unknown uuu op], []
1506
+ *
1507
+ * @param {string[]} argv
1508
+ * @return {{operands: string[], unknown: string[]}}
1509
+ */
1510
+
1511
+ parseOptions(argv) {
1512
+ const operands = []; // operands, not options or values
1513
+ const unknown = []; // first unknown option and remaining unknown args
1514
+ let dest = operands;
1515
+ const args = argv.slice();
1516
+
1517
+ function maybeOption(arg) {
1518
+ return arg.length > 1 && arg[0] === '-';
1519
+ }
1520
+
1521
+ // parse options
1522
+ let activeVariadicOption = null;
1523
+ while (args.length) {
1524
+ const arg = args.shift();
1525
+
1526
+ // literal
1527
+ if (arg === '--') {
1528
+ if (dest === unknown) dest.push(arg);
1529
+ dest.push(...args);
1530
+ break;
1531
+ }
1532
+
1533
+ if (activeVariadicOption && !maybeOption(arg)) {
1534
+ this.emit(`option:${activeVariadicOption.name()}`, arg);
1535
+ continue;
1536
+ }
1537
+ activeVariadicOption = null;
1538
+
1539
+ if (maybeOption(arg)) {
1540
+ const option = this._findOption(arg);
1541
+ // recognised option, call listener to assign value with possible custom processing
1542
+ if (option) {
1543
+ if (option.required) {
1544
+ const value = args.shift();
1545
+ if (value === undefined) this.optionMissingArgument(option);
1546
+ this.emit(`option:${option.name()}`, value);
1547
+ } else if (option.optional) {
1548
+ let value = null;
1549
+ // historical behaviour is optional value is following arg unless an option
1550
+ if (args.length > 0 && !maybeOption(args[0])) {
1551
+ value = args.shift();
1552
+ }
1553
+ this.emit(`option:${option.name()}`, value);
1554
+ } else { // boolean flag
1555
+ this.emit(`option:${option.name()}`);
1556
+ }
1557
+ activeVariadicOption = option.variadic ? option : null;
1558
+ continue;
1559
+ }
1560
+ }
1561
+
1562
+ // Look for combo options following single dash, eat first one if known.
1563
+ if (arg.length > 2 && arg[0] === '-' && arg[1] !== '-') {
1564
+ const option = this._findOption(`-${arg[1]}`);
1565
+ if (option) {
1566
+ if (option.required || (option.optional && this._combineFlagAndOptionalValue)) {
1567
+ // option with value following in same argument
1568
+ this.emit(`option:${option.name()}`, arg.slice(2));
1569
+ } else {
1570
+ // boolean option, emit and put back remainder of arg for further processing
1571
+ this.emit(`option:${option.name()}`);
1572
+ args.unshift(`-${arg.slice(2)}`);
1573
+ }
1574
+ continue;
1575
+ }
1576
+ }
1577
+
1578
+ // Look for known long flag with value, like --foo=bar
1579
+ if (/^--[^=]+=/.test(arg)) {
1580
+ const index = arg.indexOf('=');
1581
+ const option = this._findOption(arg.slice(0, index));
1582
+ if (option && (option.required || option.optional)) {
1583
+ this.emit(`option:${option.name()}`, arg.slice(index + 1));
1584
+ continue;
1585
+ }
1586
+ }
1587
+
1588
+ // Not a recognised option by this command.
1589
+ // Might be a command-argument, or subcommand option, or unknown option, or help command or option.
1590
+
1591
+ // An unknown option means further arguments also classified as unknown so can be reprocessed by subcommands.
1592
+ if (maybeOption(arg)) {
1593
+ dest = unknown;
1594
+ }
1595
+
1596
+ // If using positionalOptions, stop processing our options at subcommand.
1597
+ if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
1598
+ if (this._findCommand(arg)) {
1599
+ operands.push(arg);
1600
+ if (args.length > 0) unknown.push(...args);
1601
+ break;
1602
+ } else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
1603
+ operands.push(arg);
1604
+ if (args.length > 0) operands.push(...args);
1605
+ break;
1606
+ } else if (this._defaultCommandName) {
1607
+ unknown.push(arg);
1608
+ if (args.length > 0) unknown.push(...args);
1609
+ break;
1610
+ }
1611
+ }
1612
+
1613
+ // If using passThroughOptions, stop processing options at first command-argument.
1614
+ if (this._passThroughOptions) {
1615
+ dest.push(arg);
1616
+ if (args.length > 0) dest.push(...args);
1617
+ break;
1618
+ }
1619
+
1620
+ // add arg
1621
+ dest.push(arg);
1622
+ }
1623
+
1624
+ return { operands, unknown };
1625
+ }
1626
+
1627
+ /**
1628
+ * Return an object containing local option values as key-value pairs.
1629
+ *
1630
+ * @return {Object}
1631
+ */
1632
+ opts() {
1633
+ if (this._storeOptionsAsProperties) {
1634
+ // Preserve original behaviour so backwards compatible when still using properties
1635
+ const result = {};
1636
+ const len = this.options.length;
1637
+
1638
+ for (let i = 0; i < len; i++) {
1639
+ const key = this.options[i].attributeName();
1640
+ result[key] = key === this._versionOptionName ? this._version : this[key];
1641
+ }
1642
+ return result;
1643
+ }
1644
+
1645
+ return this._optionValues;
1646
+ }
1647
+
1648
+ /**
1649
+ * Return an object containing merged local and global option values as key-value pairs.
1650
+ *
1651
+ * @return {Object}
1652
+ */
1653
+ optsWithGlobals() {
1654
+ // globals overwrite locals
1655
+ return this._getCommandAndAncestors().reduce(
1656
+ (combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()),
1657
+ {}
1658
+ );
1659
+ }
1660
+
1661
+ /**
1662
+ * Display error message and exit (or call exitOverride).
1663
+ *
1664
+ * @param {string} message
1665
+ * @param {Object} [errorOptions]
1666
+ * @param {string} [errorOptions.code] - an id string representing the error
1667
+ * @param {number} [errorOptions.exitCode] - used with process.exit
1668
+ */
1669
+ error(message, errorOptions) {
1670
+ // output handling
1671
+ this._outputConfiguration.outputError(`${message}\n`, this._outputConfiguration.writeErr);
1672
+ if (typeof this._showHelpAfterError === 'string') {
1673
+ this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`);
1674
+ } else if (this._showHelpAfterError) {
1675
+ this._outputConfiguration.writeErr('\n');
1676
+ this.outputHelp({ error: true });
1677
+ }
1678
+
1679
+ // exit handling
1680
+ const config = errorOptions || {};
1681
+ const exitCode = config.exitCode || 1;
1682
+ const code = config.code || 'commander.error';
1683
+ this._exit(exitCode, code, message);
1684
+ }
1685
+
1686
+ /**
1687
+ * Apply any option related environment variables, if option does
1688
+ * not have a value from cli or client code.
1689
+ *
1690
+ * @private
1691
+ */
1692
+ _parseOptionsEnv() {
1693
+ this.options.forEach((option) => {
1694
+ if (option.envVar && option.envVar in process.env) {
1695
+ const optionKey = option.attributeName();
1696
+ // Priority check. Do not overwrite cli or options from unknown source (client-code).
1697
+ if (this.getOptionValue(optionKey) === undefined || ['default', 'config', 'env'].includes(this.getOptionValueSource(optionKey))) {
1698
+ if (option.required || option.optional) { // option can take a value
1699
+ // keep very simple, optional always takes value
1700
+ this.emit(`optionEnv:${option.name()}`, process.env[option.envVar]);
1701
+ } else { // boolean
1702
+ // keep very simple, only care that envVar defined and not the value
1703
+ this.emit(`optionEnv:${option.name()}`);
1704
+ }
1705
+ }
1706
+ }
1707
+ });
1708
+ }
1709
+
1710
+ /**
1711
+ * Apply any implied option values, if option is undefined or default value.
1712
+ *
1713
+ * @private
1714
+ */
1715
+ _parseOptionsImplied() {
1716
+ const dualHelper = new DualOptions(this.options);
1717
+ const hasCustomOptionValue = (optionKey) => {
1718
+ return this.getOptionValue(optionKey) !== undefined && !['default', 'implied'].includes(this.getOptionValueSource(optionKey));
1719
+ };
1720
+ this.options
1721
+ .filter(option => (option.implied !== undefined) &&
1722
+ hasCustomOptionValue(option.attributeName()) &&
1723
+ dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option))
1724
+ .forEach((option) => {
1725
+ Object.keys(option.implied)
1726
+ .filter(impliedKey => !hasCustomOptionValue(impliedKey))
1727
+ .forEach(impliedKey => {
1728
+ this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], 'implied');
1729
+ });
1730
+ });
1731
+ }
1732
+
1733
+ /**
1734
+ * Argument `name` is missing.
1735
+ *
1736
+ * @param {string} name
1737
+ * @private
1738
+ */
1739
+
1740
+ missingArgument(name) {
1741
+ const message = `error: missing required argument '${name}'`;
1742
+ this.error(message, { code: 'commander.missingArgument' });
1743
+ }
1744
+
1745
+ /**
1746
+ * `Option` is missing an argument.
1747
+ *
1748
+ * @param {Option} option
1749
+ * @private
1750
+ */
1751
+
1752
+ optionMissingArgument(option) {
1753
+ const message = `error: option '${option.flags}' argument missing`;
1754
+ this.error(message, { code: 'commander.optionMissingArgument' });
1755
+ }
1756
+
1757
+ /**
1758
+ * `Option` does not have a value, and is a mandatory option.
1759
+ *
1760
+ * @param {Option} option
1761
+ * @private
1762
+ */
1763
+
1764
+ missingMandatoryOptionValue(option) {
1765
+ const message = `error: required option '${option.flags}' not specified`;
1766
+ this.error(message, { code: 'commander.missingMandatoryOptionValue' });
1767
+ }
1768
+
1769
+ /**
1770
+ * `Option` conflicts with another option.
1771
+ *
1772
+ * @param {Option} option
1773
+ * @param {Option} conflictingOption
1774
+ * @private
1775
+ */
1776
+ _conflictingOption(option, conflictingOption) {
1777
+ // The calling code does not know whether a negated option is the source of the
1778
+ // value, so do some work to take an educated guess.
1779
+ const findBestOptionFromValue = (option) => {
1780
+ const optionKey = option.attributeName();
1781
+ const optionValue = this.getOptionValue(optionKey);
1782
+ const negativeOption = this.options.find(target => target.negate && optionKey === target.attributeName());
1783
+ const positiveOption = this.options.find(target => !target.negate && optionKey === target.attributeName());
1784
+ if (negativeOption && (
1785
+ (negativeOption.presetArg === undefined && optionValue === false) ||
1786
+ (negativeOption.presetArg !== undefined && optionValue === negativeOption.presetArg)
1787
+ )) {
1788
+ return negativeOption;
1789
+ }
1790
+ return positiveOption || option;
1791
+ };
1792
+
1793
+ const getErrorMessage = (option) => {
1794
+ const bestOption = findBestOptionFromValue(option);
1795
+ const optionKey = bestOption.attributeName();
1796
+ const source = this.getOptionValueSource(optionKey);
1797
+ if (source === 'env') {
1798
+ return `environment variable '${bestOption.envVar}'`;
1799
+ }
1800
+ return `option '${bestOption.flags}'`;
1801
+ };
1802
+
1803
+ const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
1804
+ this.error(message, { code: 'commander.conflictingOption' });
1805
+ }
1806
+
1807
+ /**
1808
+ * Unknown option `flag`.
1809
+ *
1810
+ * @param {string} flag
1811
+ * @private
1812
+ */
1813
+
1814
+ unknownOption(flag) {
1815
+ if (this._allowUnknownOption) return;
1816
+ let suggestion = '';
1817
+
1818
+ if (flag.startsWith('--') && this._showSuggestionAfterError) {
1819
+ // Looping to pick up the global options too
1820
+ let candidateFlags = [];
1821
+ let command = this;
1822
+ do {
1823
+ const moreFlags = command.createHelp().visibleOptions(command)
1824
+ .filter(option => option.long)
1825
+ .map(option => option.long);
1826
+ candidateFlags = candidateFlags.concat(moreFlags);
1827
+ command = command.parent;
1828
+ } while (command && !command._enablePositionalOptions);
1829
+ suggestion = suggestSimilar(flag, candidateFlags);
1830
+ }
1831
+
1832
+ const message = `error: unknown option '${flag}'${suggestion}`;
1833
+ this.error(message, { code: 'commander.unknownOption' });
1834
+ }
1835
+
1836
+ /**
1837
+ * Excess arguments, more than expected.
1838
+ *
1839
+ * @param {string[]} receivedArgs
1840
+ * @private
1841
+ */
1842
+
1843
+ _excessArguments(receivedArgs) {
1844
+ if (this._allowExcessArguments) return;
1845
+
1846
+ const expected = this.registeredArguments.length;
1847
+ const s = (expected === 1) ? '' : 's';
1848
+ const forSubcommand = this.parent ? ` for '${this.name()}'` : '';
1849
+ const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
1850
+ this.error(message, { code: 'commander.excessArguments' });
1851
+ }
1852
+
1853
+ /**
1854
+ * Unknown command.
1855
+ *
1856
+ * @private
1857
+ */
1858
+
1859
+ unknownCommand() {
1860
+ const unknownName = this.args[0];
1861
+ let suggestion = '';
1862
+
1863
+ if (this._showSuggestionAfterError) {
1864
+ const candidateNames = [];
1865
+ this.createHelp().visibleCommands(this).forEach((command) => {
1866
+ candidateNames.push(command.name());
1867
+ // just visible alias
1868
+ if (command.alias()) candidateNames.push(command.alias());
1869
+ });
1870
+ suggestion = suggestSimilar(unknownName, candidateNames);
1871
+ }
1872
+
1873
+ const message = `error: unknown command '${unknownName}'${suggestion}`;
1874
+ this.error(message, { code: 'commander.unknownCommand' });
1875
+ }
1876
+
1877
+ /**
1878
+ * Get or set the program version.
1879
+ *
1880
+ * This method auto-registers the "-V, --version" option which will print the version number.
1881
+ *
1882
+ * You can optionally supply the flags and description to override the defaults.
1883
+ *
1884
+ * @param {string} [str]
1885
+ * @param {string} [flags]
1886
+ * @param {string} [description]
1887
+ * @return {(this | string | undefined)} `this` command for chaining, or version string if no arguments
1888
+ */
1889
+
1890
+ version(str, flags, description) {
1891
+ if (str === undefined) return this._version;
1892
+ this._version = str;
1893
+ flags = flags || '-V, --version';
1894
+ description = description || 'output the version number';
1895
+ const versionOption = this.createOption(flags, description);
1896
+ this._versionOptionName = versionOption.attributeName();
1897
+ this._registerOption(versionOption);
1898
+
1899
+ this.on('option:' + versionOption.name(), () => {
1900
+ this._outputConfiguration.writeOut(`${str}\n`);
1901
+ this._exit(0, 'commander.version', str);
1902
+ });
1903
+ return this;
1904
+ }
1905
+
1906
+ /**
1907
+ * Set the description.
1908
+ *
1909
+ * @param {string} [str]
1910
+ * @param {Object} [argsDescription]
1911
+ * @return {(string|Command)}
1912
+ */
1913
+ description(str, argsDescription) {
1914
+ if (str === undefined && argsDescription === undefined) return this._description;
1915
+ this._description = str;
1916
+ if (argsDescription) {
1917
+ this._argsDescription = argsDescription;
1918
+ }
1919
+ return this;
1920
+ }
1921
+
1922
+ /**
1923
+ * Set the summary. Used when listed as subcommand of parent.
1924
+ *
1925
+ * @param {string} [str]
1926
+ * @return {(string|Command)}
1927
+ */
1928
+ summary(str) {
1929
+ if (str === undefined) return this._summary;
1930
+ this._summary = str;
1931
+ return this;
1932
+ }
1933
+
1934
+ /**
1935
+ * Set an alias for the command.
1936
+ *
1937
+ * You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
1938
+ *
1939
+ * @param {string} [alias]
1940
+ * @return {(string|Command)}
1941
+ */
1942
+
1943
+ alias(alias) {
1944
+ if (alias === undefined) return this._aliases[0]; // just return first, for backwards compatibility
1945
+
1946
+ /** @type {Command} */
1947
+ let command = this;
1948
+ if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
1949
+ // assume adding alias for last added executable subcommand, rather than this
1950
+ command = this.commands[this.commands.length - 1];
1951
+ }
1952
+
1953
+ if (alias === command._name) throw new Error('Command alias can\'t be the same as its name');
1954
+ const matchingCommand = this.parent?._findCommand(alias);
1955
+ if (matchingCommand) {
1956
+ // c.f. _registerCommand
1957
+ const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join('|');
1958
+ throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
1959
+ }
1960
+
1961
+ command._aliases.push(alias);
1962
+ return this;
1963
+ }
1964
+
1965
+ /**
1966
+ * Set aliases for the command.
1967
+ *
1968
+ * Only the first alias is shown in the auto-generated help.
1969
+ *
1970
+ * @param {string[]} [aliases]
1971
+ * @return {(string[]|Command)}
1972
+ */
1973
+
1974
+ aliases(aliases) {
1975
+ // Getter for the array of aliases is the main reason for having aliases() in addition to alias().
1976
+ if (aliases === undefined) return this._aliases;
1977
+
1978
+ aliases.forEach((alias) => this.alias(alias));
1979
+ return this;
1980
+ }
1981
+
1982
+ /**
1983
+ * Set / get the command usage `str`.
1984
+ *
1985
+ * @param {string} [str]
1986
+ * @return {(string|Command)}
1987
+ */
1988
+
1989
+ usage(str) {
1990
+ if (str === undefined) {
1991
+ if (this._usage) return this._usage;
1992
+
1993
+ const args = this.registeredArguments.map((arg) => {
1994
+ return humanReadableArgName(arg);
1995
+ });
1996
+ return [].concat(
1997
+ (this.options.length || (this._helpOption !== null) ? '[options]' : []),
1998
+ (this.commands.length ? '[command]' : []),
1999
+ (this.registeredArguments.length ? args : [])
2000
+ ).join(' ');
2001
+ }
2002
+
2003
+ this._usage = str;
2004
+ return this;
2005
+ }
2006
+
2007
+ /**
2008
+ * Get or set the name of the command.
2009
+ *
2010
+ * @param {string} [str]
2011
+ * @return {(string|Command)}
2012
+ */
2013
+
2014
+ name(str) {
2015
+ if (str === undefined) return this._name;
2016
+ this._name = str;
2017
+ return this;
2018
+ }
2019
+
2020
+ /**
2021
+ * Set the name of the command from script filename, such as process.argv[1],
2022
+ * or require.main.filename, or __filename.
2023
+ *
2024
+ * (Used internally and public although not documented in README.)
2025
+ *
2026
+ * @example
2027
+ * program.nameFromFilename(require.main.filename);
2028
+ *
2029
+ * @param {string} filename
2030
+ * @return {Command}
2031
+ */
2032
+
2033
+ nameFromFilename(filename) {
2034
+ this._name = path.basename(filename, path.extname(filename));
2035
+
2036
+ return this;
2037
+ }
2038
+
2039
+ /**
2040
+ * Get or set the directory for searching for executable subcommands of this command.
2041
+ *
2042
+ * @example
2043
+ * program.executableDir(__dirname);
2044
+ * // or
2045
+ * program.executableDir('subcommands');
2046
+ *
2047
+ * @param {string} [path]
2048
+ * @return {(string|null|Command)}
2049
+ */
2050
+
2051
+ executableDir(path) {
2052
+ if (path === undefined) return this._executableDir;
2053
+ this._executableDir = path;
2054
+ return this;
2055
+ }
2056
+
2057
+ /**
2058
+ * Return program help documentation.
2059
+ *
2060
+ * @param {{ error: boolean }} [contextOptions] - pass {error:true} to wrap for stderr instead of stdout
2061
+ * @return {string}
2062
+ */
2063
+
2064
+ helpInformation(contextOptions) {
2065
+ const helper = this.createHelp();
2066
+ if (helper.helpWidth === undefined) {
2067
+ helper.helpWidth = (contextOptions && contextOptions.error) ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.getOutHelpWidth();
2068
+ }
2069
+ return helper.formatHelp(this, helper);
2070
+ }
2071
+
2072
+ /**
2073
+ * @private
2074
+ */
2075
+
2076
+ _getHelpContext(contextOptions) {
2077
+ contextOptions = contextOptions || {};
2078
+ const context = { error: !!contextOptions.error };
2079
+ let write;
2080
+ if (context.error) {
2081
+ write = (arg) => this._outputConfiguration.writeErr(arg);
2082
+ } else {
2083
+ write = (arg) => this._outputConfiguration.writeOut(arg);
2084
+ }
2085
+ context.write = contextOptions.write || write;
2086
+ context.command = this;
2087
+ return context;
2088
+ }
2089
+
2090
+ /**
2091
+ * Output help information for this command.
2092
+ *
2093
+ * Outputs built-in help, and custom text added using `.addHelpText()`.
2094
+ *
2095
+ * @param {{ error: boolean } | Function} [contextOptions] - pass {error:true} to write to stderr instead of stdout
2096
+ */
2097
+
2098
+ outputHelp(contextOptions) {
2099
+ let deprecatedCallback;
2100
+ if (typeof contextOptions === 'function') {
2101
+ deprecatedCallback = contextOptions;
2102
+ contextOptions = undefined;
2103
+ }
2104
+ const context = this._getHelpContext(contextOptions);
2105
+
2106
+ this._getCommandAndAncestors().reverse().forEach(command => command.emit('beforeAllHelp', context));
2107
+ this.emit('beforeHelp', context);
2108
+
2109
+ let helpInformation = this.helpInformation(context);
2110
+ if (deprecatedCallback) {
2111
+ helpInformation = deprecatedCallback(helpInformation);
2112
+ if (typeof helpInformation !== 'string' && !Buffer.isBuffer(helpInformation)) {
2113
+ throw new Error('outputHelp callback must return a string or a Buffer');
2114
+ }
2115
+ }
2116
+ context.write(helpInformation);
2117
+
2118
+ if (this._getHelpOption()?.long) {
2119
+ this.emit(this._getHelpOption().long); // deprecated
2120
+ }
2121
+ this.emit('afterHelp', context);
2122
+ this._getCommandAndAncestors().forEach(command => command.emit('afterAllHelp', context));
2123
+ }
2124
+
2125
+ /**
2126
+ * You can pass in flags and a description to customise the built-in help option.
2127
+ * Pass in false to disable the built-in help option.
2128
+ *
2129
+ * @example
2130
+ * program.helpOption('-?, --help' 'show help'); // customise
2131
+ * program.helpOption(false); // disable
2132
+ *
2133
+ * @param {(string | boolean)} flags
2134
+ * @param {string} [description]
2135
+ * @return {Command} `this` command for chaining
2136
+ */
2137
+
2138
+ helpOption(flags, description) {
2139
+ // Support disabling built-in help option.
2140
+ if (typeof flags === 'boolean') {
2141
+ if (flags) {
2142
+ this._helpOption = this._helpOption ?? undefined; // preserve existing option
2143
+ } else {
2144
+ this._helpOption = null; // disable
2145
+ }
2146
+ return this;
2147
+ }
2148
+
2149
+ // Customise flags and description.
2150
+ flags = flags ?? '-h, --help';
2151
+ description = description ?? 'display help for command';
2152
+ this._helpOption = this.createOption(flags, description);
2153
+
2154
+ return this;
2155
+ }
2156
+
2157
+ /**
2158
+ * Lazy create help option.
2159
+ * Returns null if has been disabled with .helpOption(false).
2160
+ *
2161
+ * @returns {(Option | null)} the help option
2162
+ * @package internal use only
2163
+ */
2164
+ _getHelpOption() {
2165
+ // Lazy create help option on demand.
2166
+ if (this._helpOption === undefined) {
2167
+ this.helpOption(undefined, undefined);
2168
+ }
2169
+ return this._helpOption;
2170
+ }
2171
+
2172
+ /**
2173
+ * Supply your own option to use for the built-in help option.
2174
+ * This is an alternative to using helpOption() to customise the flags and description etc.
2175
+ *
2176
+ * @param {Option} option
2177
+ * @return {Command} `this` command for chaining
2178
+ */
2179
+ addHelpOption(option) {
2180
+ this._helpOption = option;
2181
+ return this;
2182
+ }
2183
+
2184
+ /**
2185
+ * Output help information and exit.
2186
+ *
2187
+ * Outputs built-in help, and custom text added using `.addHelpText()`.
2188
+ *
2189
+ * @param {{ error: boolean }} [contextOptions] - pass {error:true} to write to stderr instead of stdout
2190
+ */
2191
+
2192
+ help(contextOptions) {
2193
+ this.outputHelp(contextOptions);
2194
+ let exitCode = process.exitCode || 0;
2195
+ if (exitCode === 0 && contextOptions && typeof contextOptions !== 'function' && contextOptions.error) {
2196
+ exitCode = 1;
2197
+ }
2198
+ // message: do not have all displayed text available so only passing placeholder.
2199
+ this._exit(exitCode, 'commander.help', '(outputHelp)');
2200
+ }
2201
+
2202
+ /**
2203
+ * Add additional text to be displayed with the built-in help.
2204
+ *
2205
+ * Position is 'before' or 'after' to affect just this command,
2206
+ * and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
2207
+ *
2208
+ * @param {string} position - before or after built-in help
2209
+ * @param {(string | Function)} text - string to add, or a function returning a string
2210
+ * @return {Command} `this` command for chaining
2211
+ */
2212
+ addHelpText(position, text) {
2213
+ const allowedValues = ['beforeAll', 'before', 'after', 'afterAll'];
2214
+ if (!allowedValues.includes(position)) {
2215
+ throw new Error(`Unexpected value for position to addHelpText.
2216
+ Expecting one of '${allowedValues.join("', '")}'`);
2217
+ }
2218
+ const helpEvent = `${position}Help`;
2219
+ this.on(helpEvent, (context) => {
2220
+ let helpStr;
2221
+ if (typeof text === 'function') {
2222
+ helpStr = text({ error: context.error, command: context.command });
2223
+ } else {
2224
+ helpStr = text;
2225
+ }
2226
+ // Ignore falsy value when nothing to output.
2227
+ if (helpStr) {
2228
+ context.write(`${helpStr}\n`);
2229
+ }
2230
+ });
2231
+ return this;
2232
+ }
2233
+
2234
+ /**
2235
+ * Output help information if help flags specified
2236
+ *
2237
+ * @param {Array} args - array of options to search for help flags
2238
+ * @private
2239
+ */
2240
+
2241
+ _outputHelpIfRequested(args) {
2242
+ const helpOption = this._getHelpOption();
2243
+ const helpRequested = helpOption && args.find(arg => helpOption.is(arg));
2244
+ if (helpRequested) {
2245
+ this.outputHelp();
2246
+ // (Do not have all displayed text available so only passing placeholder.)
2247
+ this._exit(0, 'commander.helpDisplayed', '(outputHelp)');
2248
+ }
2249
+ }
2250
+ }
2251
+
2252
+ /**
2253
+ * Scan arguments and increment port number for inspect calls (to avoid conflicts when spawning new command).
2254
+ *
2255
+ * @param {string[]} args - array of arguments from node.execArgv
2256
+ * @returns {string[]}
2257
+ * @private
2258
+ */
2259
+
2260
+ function incrementNodeInspectorPort(args) {
2261
+ // Testing for these options:
2262
+ // --inspect[=[host:]port]
2263
+ // --inspect-brk[=[host:]port]
2264
+ // --inspect-port=[host:]port
2265
+ return args.map((arg) => {
2266
+ if (!arg.startsWith('--inspect')) {
2267
+ return arg;
2268
+ }
2269
+ let debugOption;
2270
+ let debugHost = '127.0.0.1';
2271
+ let debugPort = '9229';
2272
+ let match;
2273
+ if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
2274
+ // e.g. --inspect
2275
+ debugOption = match[1];
2276
+ } else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
2277
+ debugOption = match[1];
2278
+ if (/^\d+$/.test(match[3])) {
2279
+ // e.g. --inspect=1234
2280
+ debugPort = match[3];
2281
+ } else {
2282
+ // e.g. --inspect=localhost
2283
+ debugHost = match[3];
2284
+ }
2285
+ } else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
2286
+ // e.g. --inspect=localhost:1234
2287
+ debugOption = match[1];
2288
+ debugHost = match[3];
2289
+ debugPort = match[4];
2290
+ }
2291
+
2292
+ if (debugOption && debugPort !== '0') {
2293
+ return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
2294
+ }
2295
+ return arg;
2296
+ });
2297
+ }
2298
+
2299
+ exports.Command = Command;