git-remote-ops 0.1.0

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 (245) hide show
  1. package/AGENTS.md +177 -0
  2. package/LICENSE +21 -0
  3. package/README.md +247 -0
  4. package/esm/_dnt.shims.js +72 -0
  5. package/esm/cli.js +217 -0
  6. package/esm/client.js +439 -0
  7. package/esm/deps/jsr.io/@cliffy/command/1.1.0/_argument_types.js +1 -0
  8. package/esm/deps/jsr.io/@cliffy/command/1.1.0/_errors.js +133 -0
  9. package/esm/deps/jsr.io/@cliffy/command/1.1.0/_spread.js +1 -0
  10. package/esm/deps/jsr.io/@cliffy/command/1.1.0/_type_utils.js +1 -0
  11. package/esm/deps/jsr.io/@cliffy/command/1.1.0/_utils.js +141 -0
  12. package/esm/deps/jsr.io/@cliffy/command/1.1.0/command.js +1861 -0
  13. package/esm/deps/jsr.io/@cliffy/command/1.1.0/help/_help_generator.js +357 -0
  14. package/esm/deps/jsr.io/@cliffy/command/1.1.0/mod.js +13 -0
  15. package/esm/deps/jsr.io/@cliffy/command/1.1.0/type.js +27 -0
  16. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types/action_list.js +16 -0
  17. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types/boolean.js +13 -0
  18. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types/child_command.js +14 -0
  19. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types/command.js +9 -0
  20. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types/enum.js +24 -0
  21. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types/file.js +12 -0
  22. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types/integer.js +9 -0
  23. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types/number.js +9 -0
  24. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types/secret.js +7 -0
  25. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types/string.js +9 -0
  26. package/esm/deps/jsr.io/@cliffy/command/1.1.0/types.js +2 -0
  27. package/esm/deps/jsr.io/@cliffy/command/1.1.0/upgrade/_check_version.js +26 -0
  28. package/esm/deps/jsr.io/@cliffy/flags/1.1.0/_errors.js +129 -0
  29. package/esm/deps/jsr.io/@cliffy/flags/1.1.0/_utils.js +100 -0
  30. package/esm/deps/jsr.io/@cliffy/flags/1.1.0/_validate_flags.js +166 -0
  31. package/esm/deps/jsr.io/@cliffy/flags/1.1.0/flags.js +750 -0
  32. package/esm/deps/jsr.io/@cliffy/flags/1.1.0/mod.js +55 -0
  33. package/esm/deps/jsr.io/@cliffy/flags/1.1.0/types/boolean.js +11 -0
  34. package/esm/deps/jsr.io/@cliffy/flags/1.1.0/types/integer.js +9 -0
  35. package/esm/deps/jsr.io/@cliffy/flags/1.1.0/types/number.js +11 -0
  36. package/esm/deps/jsr.io/@cliffy/flags/1.1.0/types/string.js +4 -0
  37. package/esm/deps/jsr.io/@cliffy/flags/1.1.0/types.js +1 -0
  38. package/esm/deps/jsr.io/@cliffy/internal/1.1.0/runtime/exit.js +16 -0
  39. package/esm/deps/jsr.io/@cliffy/internal/1.1.0/runtime/get_args.js +11 -0
  40. package/esm/deps/jsr.io/@cliffy/internal/1.1.0/runtime/get_columns.js +25 -0
  41. package/esm/deps/jsr.io/@cliffy/internal/1.1.0/runtime/get_env.js +18 -0
  42. package/esm/deps/jsr.io/@cliffy/internal/1.1.0/runtime/inspect.js +11 -0
  43. package/esm/deps/jsr.io/@cliffy/table/1.1.0/_layout.js +616 -0
  44. package/esm/deps/jsr.io/@cliffy/table/1.1.0/_utils.js +79 -0
  45. package/esm/deps/jsr.io/@cliffy/table/1.1.0/border.js +18 -0
  46. package/esm/deps/jsr.io/@cliffy/table/1.1.0/cell.js +190 -0
  47. package/esm/deps/jsr.io/@cliffy/table/1.1.0/column.js +117 -0
  48. package/esm/deps/jsr.io/@cliffy/table/1.1.0/consume_words.js +64 -0
  49. package/esm/deps/jsr.io/@cliffy/table/1.1.0/mod.js +42 -0
  50. package/esm/deps/jsr.io/@cliffy/table/1.1.0/row.js +82 -0
  51. package/esm/deps/jsr.io/@cliffy/table/1.1.0/table.js +341 -0
  52. package/esm/deps/jsr.io/@cliffy/table/1.1.0/unicode_width.js +101 -0
  53. package/esm/deps/jsr.io/@std/crypto/1.1.0/_types.js +2 -0
  54. package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.internal.js +237 -0
  55. package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.js +2277 -0
  56. package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/mod.js +46 -0
  57. package/esm/deps/jsr.io/@std/crypto/1.1.0/aes_gcm.js +132 -0
  58. package/esm/deps/jsr.io/@std/crypto/1.1.0/crypto.js +270 -0
  59. package/esm/deps/jsr.io/@std/crypto/1.1.0/mod.js +23 -0
  60. package/esm/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.js +61 -0
  61. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.js +51 -0
  62. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +13 -0
  63. package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.js +2 -0
  64. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.js +87 -0
  65. package/esm/deps/jsr.io/@std/fmt/1.0.10/colors.js +903 -0
  66. package/esm/deps/jsr.io/@std/text/1.0.18/closest_string.js +46 -0
  67. package/esm/deps/jsr.io/@std/text/1.0.18/levenshtein_distance.js +127 -0
  68. package/esm/errors.js +38 -0
  69. package/esm/index.js +10 -0
  70. package/esm/logger.js +216 -0
  71. package/esm/objects/commit.js +47 -0
  72. package/esm/objects/index.js +2 -0
  73. package/esm/objects/tree.js +149 -0
  74. package/esm/pack/delta.js +179 -0
  75. package/esm/pack/index.js +3 -0
  76. package/esm/pack/objects.js +72 -0
  77. package/esm/pack/parser.js +304 -0
  78. package/esm/package.json +3 -0
  79. package/esm/protocol/index.js +3 -0
  80. package/esm/protocol/pkt_line.js +103 -0
  81. package/esm/protocol/refs.js +100 -0
  82. package/esm/protocol/upload_pack.js +259 -0
  83. package/esm/transport.js +128 -0
  84. package/esm/types.js +8 -0
  85. package/package.json +50 -0
  86. package/types/_dnt.shims.d.ts +16 -0
  87. package/types/_dnt.shims.d.ts.map +1 -0
  88. package/types/cli.d.ts +3 -0
  89. package/types/cli.d.ts.map +1 -0
  90. package/types/client.d.ts +108 -0
  91. package/types/client.d.ts.map +1 -0
  92. package/types/deps/jsr.io/@cliffy/command/1.1.0/_argument_types.d.ts +163 -0
  93. package/types/deps/jsr.io/@cliffy/command/1.1.0/_argument_types.d.ts.map +1 -0
  94. package/types/deps/jsr.io/@cliffy/command/1.1.0/_errors.d.ts +71 -0
  95. package/types/deps/jsr.io/@cliffy/command/1.1.0/_errors.d.ts.map +1 -0
  96. package/types/deps/jsr.io/@cliffy/command/1.1.0/_spread.d.ts +16 -0
  97. package/types/deps/jsr.io/@cliffy/command/1.1.0/_spread.d.ts.map +1 -0
  98. package/types/deps/jsr.io/@cliffy/command/1.1.0/_type_utils.d.ts +15 -0
  99. package/types/deps/jsr.io/@cliffy/command/1.1.0/_type_utils.d.ts.map +1 -0
  100. package/types/deps/jsr.io/@cliffy/command/1.1.0/_utils.d.ts +38 -0
  101. package/types/deps/jsr.io/@cliffy/command/1.1.0/_utils.d.ts.map +1 -0
  102. package/types/deps/jsr.io/@cliffy/command/1.1.0/command.d.ts +1086 -0
  103. package/types/deps/jsr.io/@cliffy/command/1.1.0/command.d.ts.map +1 -0
  104. package/types/deps/jsr.io/@cliffy/command/1.1.0/help/_help_generator.d.ts +33 -0
  105. package/types/deps/jsr.io/@cliffy/command/1.1.0/help/_help_generator.d.ts.map +1 -0
  106. package/types/deps/jsr.io/@cliffy/command/1.1.0/mod.d.ts +78 -0
  107. package/types/deps/jsr.io/@cliffy/command/1.1.0/mod.d.ts.map +1 -0
  108. package/types/deps/jsr.io/@cliffy/command/1.1.0/type.d.ts +51 -0
  109. package/types/deps/jsr.io/@cliffy/command/1.1.0/type.d.ts.map +1 -0
  110. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/action_list.d.ts +10 -0
  111. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/action_list.d.ts.map +1 -0
  112. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/boolean.d.ts +10 -0
  113. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/boolean.d.ts.map +1 -0
  114. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/child_command.d.ts +10 -0
  115. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/child_command.d.ts.map +1 -0
  116. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/command.d.ts +8 -0
  117. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/command.d.ts.map +1 -0
  118. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/enum.d.ts +11 -0
  119. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/enum.d.ts.map +1 -0
  120. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/file.d.ts +6 -0
  121. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/file.d.ts.map +1 -0
  122. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/integer.d.ts +8 -0
  123. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/integer.d.ts.map +1 -0
  124. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/number.d.ts +8 -0
  125. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/number.d.ts.map +1 -0
  126. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/secret.d.ts +6 -0
  127. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/secret.d.ts.map +1 -0
  128. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/string.d.ts +8 -0
  129. package/types/deps/jsr.io/@cliffy/command/1.1.0/types/string.d.ts.map +1 -0
  130. package/types/deps/jsr.io/@cliffy/command/1.1.0/types.d.ts +161 -0
  131. package/types/deps/jsr.io/@cliffy/command/1.1.0/types.d.ts.map +1 -0
  132. package/types/deps/jsr.io/@cliffy/command/1.1.0/upgrade/_check_version.d.ts +4 -0
  133. package/types/deps/jsr.io/@cliffy/command/1.1.0/upgrade/_check_version.d.ts.map +1 -0
  134. package/types/deps/jsr.io/@cliffy/flags/1.1.0/_errors.d.ts +67 -0
  135. package/types/deps/jsr.io/@cliffy/flags/1.1.0/_errors.d.ts.map +1 -0
  136. package/types/deps/jsr.io/@cliffy/flags/1.1.0/_utils.d.ts +17 -0
  137. package/types/deps/jsr.io/@cliffy/flags/1.1.0/_utils.d.ts.map +1 -0
  138. package/types/deps/jsr.io/@cliffy/flags/1.1.0/_validate_flags.d.ts +11 -0
  139. package/types/deps/jsr.io/@cliffy/flags/1.1.0/_validate_flags.d.ts.map +1 -0
  140. package/types/deps/jsr.io/@cliffy/flags/1.1.0/flags.d.ts +154 -0
  141. package/types/deps/jsr.io/@cliffy/flags/1.1.0/flags.d.ts.map +1 -0
  142. package/types/deps/jsr.io/@cliffy/flags/1.1.0/mod.d.ts +57 -0
  143. package/types/deps/jsr.io/@cliffy/flags/1.1.0/mod.d.ts.map +1 -0
  144. package/types/deps/jsr.io/@cliffy/flags/1.1.0/types/boolean.d.ts +4 -0
  145. package/types/deps/jsr.io/@cliffy/flags/1.1.0/types/boolean.d.ts.map +1 -0
  146. package/types/deps/jsr.io/@cliffy/flags/1.1.0/types/integer.d.ts +4 -0
  147. package/types/deps/jsr.io/@cliffy/flags/1.1.0/types/integer.d.ts.map +1 -0
  148. package/types/deps/jsr.io/@cliffy/flags/1.1.0/types/number.d.ts +4 -0
  149. package/types/deps/jsr.io/@cliffy/flags/1.1.0/types/number.d.ts.map +1 -0
  150. package/types/deps/jsr.io/@cliffy/flags/1.1.0/types/string.d.ts +4 -0
  151. package/types/deps/jsr.io/@cliffy/flags/1.1.0/types/string.d.ts.map +1 -0
  152. package/types/deps/jsr.io/@cliffy/flags/1.1.0/types.d.ts +170 -0
  153. package/types/deps/jsr.io/@cliffy/flags/1.1.0/types.d.ts.map +1 -0
  154. package/types/deps/jsr.io/@cliffy/internal/1.1.0/runtime/exit.d.ts +8 -0
  155. package/types/deps/jsr.io/@cliffy/internal/1.1.0/runtime/exit.d.ts.map +1 -0
  156. package/types/deps/jsr.io/@cliffy/internal/1.1.0/runtime/get_args.d.ts +7 -0
  157. package/types/deps/jsr.io/@cliffy/internal/1.1.0/runtime/get_args.d.ts.map +1 -0
  158. package/types/deps/jsr.io/@cliffy/internal/1.1.0/runtime/get_columns.d.ts +7 -0
  159. package/types/deps/jsr.io/@cliffy/internal/1.1.0/runtime/get_columns.d.ts.map +1 -0
  160. package/types/deps/jsr.io/@cliffy/internal/1.1.0/runtime/get_env.d.ts +8 -0
  161. package/types/deps/jsr.io/@cliffy/internal/1.1.0/runtime/get_env.d.ts.map +1 -0
  162. package/types/deps/jsr.io/@cliffy/internal/1.1.0/runtime/inspect.d.ts +7 -0
  163. package/types/deps/jsr.io/@cliffy/internal/1.1.0/runtime/inspect.d.ts.map +1 -0
  164. package/types/deps/jsr.io/@cliffy/table/1.1.0/_layout.d.ts +108 -0
  165. package/types/deps/jsr.io/@cliffy/table/1.1.0/_layout.d.ts.map +1 -0
  166. package/types/deps/jsr.io/@cliffy/table/1.1.0/_utils.d.ts +26 -0
  167. package/types/deps/jsr.io/@cliffy/table/1.1.0/_utils.d.ts.map +1 -0
  168. package/types/deps/jsr.io/@cliffy/table/1.1.0/border.d.ts +21 -0
  169. package/types/deps/jsr.io/@cliffy/table/1.1.0/border.d.ts.map +1 -0
  170. package/types/deps/jsr.io/@cliffy/table/1.1.0/cell.d.ts +155 -0
  171. package/types/deps/jsr.io/@cliffy/table/1.1.0/cell.d.ts.map +1 -0
  172. package/types/deps/jsr.io/@cliffy/table/1.1.0/column.d.ts +97 -0
  173. package/types/deps/jsr.io/@cliffy/table/1.1.0/column.d.ts.map +1 -0
  174. package/types/deps/jsr.io/@cliffy/table/1.1.0/consume_words.d.ts +30 -0
  175. package/types/deps/jsr.io/@cliffy/table/1.1.0/consume_words.d.ts.map +1 -0
  176. package/types/deps/jsr.io/@cliffy/table/1.1.0/mod.d.ts +43 -0
  177. package/types/deps/jsr.io/@cliffy/table/1.1.0/mod.d.ts.map +1 -0
  178. package/types/deps/jsr.io/@cliffy/table/1.1.0/row.d.ts +67 -0
  179. package/types/deps/jsr.io/@cliffy/table/1.1.0/row.d.ts.map +1 -0
  180. package/types/deps/jsr.io/@cliffy/table/1.1.0/table.d.ts +235 -0
  181. package/types/deps/jsr.io/@cliffy/table/1.1.0/table.d.ts.map +1 -0
  182. package/types/deps/jsr.io/@cliffy/table/1.1.0/unicode_width.d.ts +40 -0
  183. package/types/deps/jsr.io/@cliffy/table/1.1.0/unicode_width.d.ts.map +1 -0
  184. package/types/deps/jsr.io/@std/crypto/1.1.0/_types.d.ts +9 -0
  185. package/types/deps/jsr.io/@std/crypto/1.1.0/_types.d.ts.map +1 -0
  186. package/types/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.d.ts +2 -0
  187. package/types/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.d.ts.map +1 -0
  188. package/types/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.internal.d.ts +69 -0
  189. package/types/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.internal.d.ts.map +1 -0
  190. package/types/deps/jsr.io/@std/crypto/1.1.0/_wasm/mod.d.ts +13 -0
  191. package/types/deps/jsr.io/@std/crypto/1.1.0/_wasm/mod.d.ts.map +1 -0
  192. package/types/deps/jsr.io/@std/crypto/1.1.0/aes_gcm.d.ts +76 -0
  193. package/types/deps/jsr.io/@std/crypto/1.1.0/aes_gcm.d.ts.map +1 -0
  194. package/types/deps/jsr.io/@std/crypto/1.1.0/crypto.d.ts +149 -0
  195. package/types/deps/jsr.io/@std/crypto/1.1.0/crypto.d.ts.map +1 -0
  196. package/types/deps/jsr.io/@std/crypto/1.1.0/mod.d.ts +22 -0
  197. package/types/deps/jsr.io/@std/crypto/1.1.0/mod.d.ts.map +1 -0
  198. package/types/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.d.ts +40 -0
  199. package/types/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.d.ts.map +1 -0
  200. package/types/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +23 -0
  201. package/types/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +1 -0
  202. package/types/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +4 -0
  203. package/types/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +1 -0
  204. package/types/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +9 -0
  205. package/types/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +1 -0
  206. package/types/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +39 -0
  207. package/types/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +1 -0
  208. package/types/deps/jsr.io/@std/fmt/1.0.10/colors.d.ts +700 -0
  209. package/types/deps/jsr.io/@std/fmt/1.0.10/colors.d.ts.map +1 -0
  210. package/types/deps/jsr.io/@std/text/1.0.18/closest_string.d.ts +42 -0
  211. package/types/deps/jsr.io/@std/text/1.0.18/closest_string.d.ts.map +1 -0
  212. package/types/deps/jsr.io/@std/text/1.0.18/levenshtein_distance.d.ts +23 -0
  213. package/types/deps/jsr.io/@std/text/1.0.18/levenshtein_distance.d.ts.map +1 -0
  214. package/types/errors.d.ts +73 -0
  215. package/types/errors.d.ts.map +1 -0
  216. package/types/index.d.ts +14 -0
  217. package/types/index.d.ts.map +1 -0
  218. package/types/logger.d.ts +70 -0
  219. package/types/logger.d.ts.map +1 -0
  220. package/types/objects/commit.d.ts +23 -0
  221. package/types/objects/commit.d.ts.map +1 -0
  222. package/types/objects/index.d.ts +3 -0
  223. package/types/objects/index.d.ts.map +1 -0
  224. package/types/objects/tree.d.ts +49 -0
  225. package/types/objects/tree.d.ts.map +1 -0
  226. package/types/pack/delta.d.ts +47 -0
  227. package/types/pack/delta.d.ts.map +1 -0
  228. package/types/pack/index.d.ts +4 -0
  229. package/types/pack/index.d.ts.map +1 -0
  230. package/types/pack/objects.d.ts +53 -0
  231. package/types/pack/objects.d.ts.map +1 -0
  232. package/types/pack/parser.d.ts +61 -0
  233. package/types/pack/parser.d.ts.map +1 -0
  234. package/types/protocol/index.d.ts +4 -0
  235. package/types/protocol/index.d.ts.map +1 -0
  236. package/types/protocol/pkt_line.d.ts +44 -0
  237. package/types/protocol/pkt_line.d.ts.map +1 -0
  238. package/types/protocol/refs.d.ts +40 -0
  239. package/types/protocol/refs.d.ts.map +1 -0
  240. package/types/protocol/upload_pack.d.ts +45 -0
  241. package/types/protocol/upload_pack.d.ts.map +1 -0
  242. package/types/transport.d.ts +24 -0
  243. package/types/transport.d.ts.map +1 -0
  244. package/types/types.d.ts +121 -0
  245. package/types/types.d.ts.map +1 -0
@@ -0,0 +1,357 @@
1
+ import { Table } from "../../../table/1.1.0/mod.js";
2
+ import { bold, brightBlue, brightMagenta, dim, getColorEnabled, green, italic, red, setColorEnabled, yellow, } from "../../../../@std/fmt/1.0.10/colors.js";
3
+ import { getColumns } from "../../../internal/1.1.0/runtime/get_columns.js";
4
+ import { inspect } from "../../../internal/1.1.0/runtime/inspect.js";
5
+ import { dedent, getDescription, getFlag, parseArgumentsDefinition, } from "../_utils.js";
6
+ import { Type } from "../type.js";
7
+ /** Help text generator. */
8
+ export class HelpGenerator {
9
+ cmd;
10
+ indent = 2;
11
+ options;
12
+ /** Generate help text for given command. */
13
+ static generate(cmd, options) {
14
+ return new HelpGenerator(cmd, options).generate();
15
+ }
16
+ constructor(cmd, options = {}) {
17
+ this.cmd = cmd;
18
+ this.options = {
19
+ types: false,
20
+ hints: true,
21
+ colors: true,
22
+ long: false,
23
+ width: getColumns() ?? 150,
24
+ maxWidth: Infinity,
25
+ ...options,
26
+ };
27
+ this.options.width = Math.min(this.options.width, this.options.maxWidth);
28
+ }
29
+ generate() {
30
+ const areColorsEnabled = getColorEnabled();
31
+ setColorEnabled(this.options.colors);
32
+ const result = this.generateHeader() +
33
+ this.generateMeta() +
34
+ this.generateDescription() +
35
+ this.generateArguments() +
36
+ this.generateOptions() +
37
+ this.generateCommands() +
38
+ this.generateEnvironmentVariables() +
39
+ this.generateExamples();
40
+ setColorEnabled(areColorsEnabled);
41
+ return result;
42
+ }
43
+ generateHeader() {
44
+ const usage = this.cmd.getUsage();
45
+ const rows = [
46
+ [
47
+ bold("Usage:"),
48
+ brightMagenta(this.cmd.getPath() +
49
+ (usage ? " " + highlightArguments(usage, this.options.types) : "")),
50
+ ],
51
+ ];
52
+ const version = this.cmd.getVersion();
53
+ if (version) {
54
+ rows.push([bold("Version:"), yellow(`${this.cmd.getVersion()}`)]);
55
+ }
56
+ return "\n" +
57
+ Table.from(rows)
58
+ .padding(1)
59
+ .toString() +
60
+ "\n";
61
+ }
62
+ generateMeta() {
63
+ const meta = Object.entries(this.cmd.getMeta());
64
+ if (!meta.length) {
65
+ return "";
66
+ }
67
+ const rows = [];
68
+ for (const [name, value] of meta) {
69
+ rows.push([bold(`${name}: `) + value]);
70
+ }
71
+ return "\n" +
72
+ Table.from(rows)
73
+ .padding(1)
74
+ .toString() +
75
+ "\n";
76
+ }
77
+ generateDescription() {
78
+ if (!this.cmd.getDescription()) {
79
+ return "";
80
+ }
81
+ return this.label("Description") +
82
+ Table.from([
83
+ [dedent(this.cmd.getDescription())],
84
+ ])
85
+ .indent(this.indent)
86
+ .maxColWidth(this.options.width - this.indent)
87
+ .padding(1)
88
+ .toString() +
89
+ "\n";
90
+ }
91
+ generateArguments() {
92
+ const args = this.cmd.getArguments();
93
+ if (!args.length || !args.find((arg) => arg.description)) {
94
+ return "";
95
+ }
96
+ return this.label("Arguments") +
97
+ Table.from([
98
+ ...args
99
+ .filter((arg) => arg.description)
100
+ .map((argument) => [
101
+ highlightArguments(argument.raw || "", this.options.types),
102
+ red(bold("-")),
103
+ getDescription(argument.description ?? "", !this.options.long),
104
+ this.generateArgumentHints(argument),
105
+ ]),
106
+ ])
107
+ .padding([2, 1, 2])
108
+ .indent(this.indent)
109
+ .maxWidth(this.options.width - this.indent)
110
+ .flexShrink([0, 0, 1, 1])
111
+ .toString() +
112
+ "\n";
113
+ }
114
+ generateOptions() {
115
+ const options = this.cmd.getOptions(false);
116
+ if (!options.length) {
117
+ return "";
118
+ }
119
+ let groups = [];
120
+ const hasGroups = options.some((option) => option.groupName);
121
+ if (hasGroups) {
122
+ for (const option of options) {
123
+ let group = groups.find((group) => group.name === option.groupName);
124
+ if (!group) {
125
+ group = {
126
+ name: option.groupName,
127
+ options: [],
128
+ };
129
+ groups.push(group);
130
+ }
131
+ group.options.push(option);
132
+ }
133
+ }
134
+ else {
135
+ groups = [{
136
+ name: "Options",
137
+ options,
138
+ }];
139
+ }
140
+ let result = "";
141
+ for (const group of groups) {
142
+ result += this.generateOptionGroup(group);
143
+ }
144
+ return result;
145
+ }
146
+ generateOptionGroup(group) {
147
+ if (!group.options.length) {
148
+ return "";
149
+ }
150
+ const hasTypeDefinitions = !!group.options.find((option) => !!option.typeDefinition);
151
+ if (hasTypeDefinitions) {
152
+ return this.label(group.name ?? "Options") +
153
+ Table.from([
154
+ ...group.options.map((option) => [
155
+ option.flags.map((flag) => brightBlue(flag)).join(", "),
156
+ highlightArguments(option.typeDefinition || "", this.options.types),
157
+ red(bold("-")),
158
+ getDescription(option.description, !this.options.long),
159
+ this.generateOptionHints(option),
160
+ ]),
161
+ ])
162
+ .padding([2, 2, 1, 2])
163
+ .indent(this.indent)
164
+ .maxWidth(this.options.width - this.indent)
165
+ .flexShrink([0, 0, 0, 1, 1])
166
+ .toString() +
167
+ "\n";
168
+ }
169
+ return this.label(group.name ?? "Options") +
170
+ Table.from([
171
+ ...group.options.map((option) => [
172
+ option.flags.map((flag) => brightBlue(flag)).join(", "),
173
+ red(bold("-")),
174
+ getDescription(option.description, !this.options.long),
175
+ this.generateOptionHints(option),
176
+ ]),
177
+ ])
178
+ .indent(this.indent)
179
+ .maxWidth(this.options.width - this.indent)
180
+ .flexShrink([0, 0, 1, 1])
181
+ .padding([2, 1, 2])
182
+ .toString() +
183
+ "\n";
184
+ }
185
+ generateCommands() {
186
+ const commands = this.cmd.getCommands(false);
187
+ if (!commands.length) {
188
+ return "";
189
+ }
190
+ const hasTypeDefinitions = !!commands.find((command) => !!command.getArgsDefinition());
191
+ if (hasTypeDefinitions) {
192
+ return this.label("Commands") +
193
+ Table.from([
194
+ ...commands.map((command) => [
195
+ [command.getName(), ...command.getAliases()].map((name) => brightBlue(name)).join(", "),
196
+ highlightArguments(command.getArgsDefinition() || "", this.options.types),
197
+ red(bold("-")),
198
+ command.getShortDescription(),
199
+ ]),
200
+ ])
201
+ .indent(this.indent)
202
+ .maxWidth(this.options.width - this.indent)
203
+ .flexShrink([0, 0, 0, 1])
204
+ .padding([2, 2, 1, 2])
205
+ .toString() +
206
+ "\n";
207
+ }
208
+ return this.label("Commands") +
209
+ Table.from([
210
+ ...commands.map((command) => [
211
+ [command.getName(), ...command.getAliases()].map((name) => brightBlue(name))
212
+ .join(", "),
213
+ red(bold("-")),
214
+ command.getShortDescription(),
215
+ ]),
216
+ ])
217
+ .maxWidth(this.options.width - this.indent)
218
+ .flexShrink([0, 0, 1])
219
+ .padding([2, 1, 2])
220
+ .indent(this.indent)
221
+ .toString() +
222
+ "\n";
223
+ }
224
+ generateEnvironmentVariables() {
225
+ const envVars = this.cmd.getEnvVars(false);
226
+ if (!envVars.length) {
227
+ return "";
228
+ }
229
+ return this.label("Environment variables") +
230
+ Table.from([
231
+ ...envVars.map((envVar) => [
232
+ envVar.names.map((name) => brightBlue(name)).join(", "),
233
+ highlightArgumentDetails(envVar.details, this.options.types),
234
+ red(bold("-")),
235
+ this.options.long
236
+ ? dedent(envVar.description)
237
+ : envVar.description.trim().split("\n", 1)[0],
238
+ envVar.required ? `(${yellow(`required`)})` : "",
239
+ ]),
240
+ ])
241
+ .padding([2, 2, 1, 2])
242
+ .indent(this.indent)
243
+ .maxWidth(this.options.width - this.indent)
244
+ .flexShrink([0, 0, 0, 1, 1])
245
+ .toString() +
246
+ "\n";
247
+ }
248
+ generateExamples() {
249
+ const examples = this.cmd.getExamples();
250
+ if (!examples.length) {
251
+ return "";
252
+ }
253
+ return this.label("Examples") +
254
+ Table.from(examples.map((example) => [
255
+ dim(bold(example.name)),
256
+ dedent(example.description),
257
+ ]))
258
+ .padding(1)
259
+ .indent(this.indent)
260
+ .maxWidth(this.options.width - this.indent)
261
+ .flexShrink([0, 1])
262
+ .toString() +
263
+ "\n";
264
+ }
265
+ generateOptionHints(option) {
266
+ if (!this.options.hints) {
267
+ return "";
268
+ }
269
+ const hints = [];
270
+ option.required && hints.push(yellow(`required`));
271
+ const type = this.cmd.getType(option.args[0]?.type)?.handler;
272
+ if (typeof option.default !== "undefined" ||
273
+ typeof option.defaultText !== "undefined") {
274
+ const defaultValue = typeof option.default === "function"
275
+ ? option.default()
276
+ : option.default;
277
+ const defaultText = typeof option.defaultText === "function"
278
+ ? option.defaultText(defaultValue)
279
+ : (typeof option.defaultText !== "undefined"
280
+ ? option.defaultText
281
+ : ((type instanceof Type && type.defaultText)
282
+ ? type.defaultText()
283
+ : defaultValue));
284
+ if (typeof defaultText !== "undefined") {
285
+ hints.push(bold(`Default: `) + inspect(defaultText, this.options.colors));
286
+ }
287
+ }
288
+ option.depends?.length && hints.push(yellow(bold(`Depends: `)) +
289
+ italic(option.depends.map(getFlag).join(", ")));
290
+ option.conflicts?.length && hints.push(red(bold(`Conflicts: `)) +
291
+ italic(option.conflicts.map(getFlag).join(", ")));
292
+ return this.generateHints(type, hints);
293
+ }
294
+ generateArgumentHints(option) {
295
+ if (!this.options.hints) {
296
+ return "";
297
+ }
298
+ const hints = [];
299
+ !option.optional && hints.push(yellow(`required`));
300
+ const type = this.cmd.getType(option.type)?.handler;
301
+ return this.generateHints(type, hints);
302
+ }
303
+ generateHints(type, hints) {
304
+ if (type instanceof Type) {
305
+ const possibleValues = type.values?.(this.cmd, this.cmd.getParent());
306
+ if (possibleValues?.length) {
307
+ hints.push(bold(`Values: `) +
308
+ possibleValues.map((value) => inspect(value, this.options.colors)).join(", "));
309
+ }
310
+ }
311
+ if (hints.length) {
312
+ return `(${hints.join(", ")})`;
313
+ }
314
+ return "";
315
+ }
316
+ label(label) {
317
+ return "\n" + bold(`${label}:`) + "\n\n";
318
+ }
319
+ }
320
+ /**
321
+ * Colorize arguments string.
322
+ * @param argsDefinition Arguments definition: `<color1:string> <color2:string>`
323
+ * @param types Show types.
324
+ */
325
+ function highlightArguments(argsDefinition, types = true) {
326
+ if (!argsDefinition) {
327
+ return "";
328
+ }
329
+ return parseArgumentsDefinition(argsDefinition, false, true)
330
+ .map((arg) => typeof arg === "string" ? arg : highlightArgumentDetails(arg, types))
331
+ .join(" ");
332
+ }
333
+ /**
334
+ * Colorize argument string.
335
+ * @param arg Argument details.
336
+ * @param types Show types.
337
+ */
338
+ function highlightArgumentDetails(arg, types = true) {
339
+ let str = "";
340
+ str += yellow(arg.optional ? "[" : "<");
341
+ let name = "";
342
+ name += arg.name;
343
+ if (arg.variadic) {
344
+ name += "...";
345
+ }
346
+ name = brightMagenta(name);
347
+ str += name;
348
+ if (types) {
349
+ str += yellow(":");
350
+ str += red(arg.type);
351
+ if (arg.list) {
352
+ str += green("[]");
353
+ }
354
+ }
355
+ str += yellow(arg.optional ? "]" : ">");
356
+ return str;
357
+ }
@@ -0,0 +1,13 @@
1
+ export { Command } from "./command.js";
2
+ export { ActionListType } from "./types/action_list.js";
3
+ export { BooleanType } from "./types/boolean.js";
4
+ export { ChildCommandType } from "./types/child_command.js";
5
+ export { CommandType } from "./types/command.js";
6
+ export { EnumType } from "./types/enum.js";
7
+ export { FileType } from "./types/file.js";
8
+ export { IntegerType } from "./types/integer.js";
9
+ export { NumberType } from "./types/number.js";
10
+ export { SecretType } from "./types/secret.js";
11
+ export { StringType } from "./types/string.js";
12
+ export { Type } from "./type.js";
13
+ export { ValidationError } from "./_errors.js";
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Base class for custom types.
3
+ *
4
+ * **Custom type example:**
5
+ *
6
+ * ```ts
7
+ * import { Type, ArgumentValue } from "./mod.ts";
8
+ *
9
+ * export class ColorType extends Type<string> {
10
+ * public parse({ label, name, value, type }: ArgumentValue): string {
11
+ * if (["red", "blue"].includes(value)) {
12
+ * throw new Error(
13
+ * `${label} "${name}" must be of type "${type}", but got "${value}".` +
14
+ * "Valid colors are: red, blue"
15
+ * );
16
+ * }
17
+ * return value;
18
+ * }
19
+ *
20
+ * public override complete(): string[] {
21
+ * return ["red", "blue"];
22
+ * }
23
+ * }
24
+ * ```
25
+ */
26
+ export class Type {
27
+ }
@@ -0,0 +1,16 @@
1
+ import { StringType } from "./string.js";
2
+ /** Completion list type. */
3
+ export class ActionListType extends StringType {
4
+ cmd;
5
+ constructor(cmd) {
6
+ super();
7
+ this.cmd = cmd;
8
+ }
9
+ /** Complete action names. */
10
+ complete() {
11
+ return this.cmd.getCompletions()
12
+ .map((type) => type.name)
13
+ // filter unique values
14
+ .filter((value, index, self) => self.indexOf(value) === index);
15
+ }
16
+ }
@@ -0,0 +1,13 @@
1
+ import { boolean } from "../../../flags/1.1.0/mod.js";
2
+ import { Type } from "../type.js";
3
+ /** Boolean type with auto completion. Allows `true`, `false`, `0` and `1`. */
4
+ export class BooleanType extends Type {
5
+ /** Parse boolean type. */
6
+ parse(type) {
7
+ return boolean(type);
8
+ }
9
+ /** Complete boolean type. */
10
+ complete() {
11
+ return ["true", "false"];
12
+ }
13
+ }
@@ -0,0 +1,14 @@
1
+ import { StringType } from "./string.js";
2
+ /** String type with auto completion of child command names. */
3
+ export class ChildCommandType extends StringType {
4
+ #cmd;
5
+ constructor(cmd) {
6
+ super();
7
+ this.#cmd = cmd;
8
+ }
9
+ /** Complete child command names. */
10
+ complete(cmd) {
11
+ return (this.#cmd ?? cmd)?.getCommands(false)
12
+ .map((cmd) => cmd.getName()) || [];
13
+ }
14
+ }
@@ -0,0 +1,9 @@
1
+ import { StringType } from "./string.js";
2
+ /** String type with auto completion of sibling command names. */
3
+ export class CommandType extends StringType {
4
+ /** Complete sub-command names of global parent command. */
5
+ complete(_cmd, parent) {
6
+ return parent?.getCommands(false)
7
+ .map((cmd) => cmd.getName()) || [];
8
+ }
9
+ }
@@ -0,0 +1,24 @@
1
+ import { Type } from "../type.js";
2
+ import { InvalidTypeError } from "../../../flags/1.1.0/mod.js";
3
+ /** Enum type. Allows only provided values. */
4
+ export class EnumType extends Type {
5
+ allowedValues;
6
+ constructor(values) {
7
+ super();
8
+ this.allowedValues = Array.isArray(values) ? values : Object.values(values);
9
+ }
10
+ parse(type) {
11
+ for (const value of this.allowedValues) {
12
+ if (value.toString() === type.value) {
13
+ return value;
14
+ }
15
+ }
16
+ throw new InvalidTypeError(type, this.allowedValues.slice());
17
+ }
18
+ values() {
19
+ return this.allowedValues.slice();
20
+ }
21
+ complete() {
22
+ return this.values();
23
+ }
24
+ }
@@ -0,0 +1,12 @@
1
+ import { StringType } from "./string.js";
2
+ // export interface FileTypeOptions {
3
+ // dirsOnly?: boolean;
4
+ // pattern?: string;
5
+ // ignore?: Array<string>;
6
+ // }
7
+ /** Integer type. */
8
+ export class FileType extends StringType {
9
+ constructor() {
10
+ super();
11
+ }
12
+ }
@@ -0,0 +1,9 @@
1
+ import { Type } from "../type.js";
2
+ import { integer } from "../../../flags/1.1.0/mod.js";
3
+ /** Integer type. */
4
+ export class IntegerType extends Type {
5
+ /** Parse integer type. */
6
+ parse(type) {
7
+ return integer(type);
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ import { number } from "../../../flags/1.1.0/mod.js";
2
+ import { Type } from "../type.js";
3
+ /** Number type. */
4
+ export class NumberType extends Type {
5
+ /** Parse number type. */
6
+ parse(type) {
7
+ return number(type);
8
+ }
9
+ }
@@ -0,0 +1,7 @@
1
+ import { StringType } from "./string.js";
2
+ /** Secret type. Allows any value, and does not show values in help text. */
3
+ export class SecretType extends StringType {
4
+ defaultText() {
5
+ return "******";
6
+ }
7
+ }
@@ -0,0 +1,9 @@
1
+ import { string } from "../../../flags/1.1.0/mod.js";
2
+ import { Type } from "../type.js";
3
+ /** String type. Allows any value. */
4
+ export class StringType extends Type {
5
+ /** Complete string type. */
6
+ parse(type) {
7
+ return string(type);
8
+ }
9
+ }
@@ -0,0 +1,2 @@
1
+ // deno-lint-ignore-file no-explicit-any
2
+ export {};
@@ -0,0 +1,26 @@
1
+ import { bold, yellow } from "../../../../@std/fmt/1.0.10/colors.js";
2
+ import { Command } from "../command.js";
3
+ /** Check if new version is available and add hint to version. */
4
+ // deno-lint-ignore no-explicit-any
5
+ export async function checkVersion(cmd) {
6
+ const mainCommand = cmd.getMainCommand();
7
+ const upgradeCommand = mainCommand.getCommand("upgrade");
8
+ if (!isUpgradeCommand(upgradeCommand)) {
9
+ return;
10
+ }
11
+ if (!await upgradeCommand.hasRequiredPermissions()) {
12
+ // If not all required permissions were pre-granted, skip the version check to prevent prompting user
13
+ return;
14
+ }
15
+ const latestVersion = await upgradeCommand.getLatestVersion();
16
+ const currentVersion = mainCommand.getVersion();
17
+ if (!currentVersion || currentVersion === latestVersion) {
18
+ return;
19
+ }
20
+ const versionHelpText = `(New version available: ${latestVersion}. Run '${mainCommand.getName()} upgrade' to upgrade to the latest version!)`;
21
+ mainCommand.version(`${currentVersion} ${bold(yellow(versionHelpText))}`);
22
+ }
23
+ function isUpgradeCommand(command) {
24
+ return command instanceof Command && "getLatestVersion" in command &&
25
+ "hasRequiredPermissions" in command;
26
+ }