@fnndsc/brasa 0.56.1 → 0.56.3

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 (361) hide show
  1. package/dist/buildinfo.json +1 -1
  2. package/dist/builtins/berth/berth.d.ts +90 -3
  3. package/dist/builtins/berth/berth.js +129 -76
  4. package/dist/builtins/berth/berth.js.map +1 -1
  5. package/dist/builtins/berth/berthClose.d.ts +25 -6
  6. package/dist/builtins/berth/berthClose.js +8 -64
  7. package/dist/builtins/berth/berthClose.js.map +1 -1
  8. package/dist/builtins/berth/berthCube.d.ts +3 -2
  9. package/dist/builtins/berth/berthCube.js +9 -16
  10. package/dist/builtins/berth/berthCube.js.map +1 -1
  11. package/dist/builtins/berth/berthProcesses.js +33 -3
  12. package/dist/builtins/berth/berthProcesses.js.map +1 -1
  13. package/dist/builtins/debug.d.ts +24 -3
  14. package/dist/builtins/debug.js +66 -13
  15. package/dist/builtins/debug.js.map +1 -1
  16. package/dist/builtins/fs/acl.args.d.ts +5 -38
  17. package/dist/builtins/fs/acl.args.js +6 -72
  18. package/dist/builtins/fs/acl.args.js.map +1 -1
  19. package/dist/builtins/fs/acl.d.ts +100 -10
  20. package/dist/builtins/fs/acl.js +222 -68
  21. package/dist/builtins/fs/acl.js.map +1 -1
  22. package/dist/builtins/fs/cat.args.d.ts +14 -15
  23. package/dist/builtins/fs/cat.args.js +13 -40
  24. package/dist/builtins/fs/cat.args.js.map +1 -1
  25. package/dist/builtins/fs/cat.d.ts +40 -3
  26. package/dist/builtins/fs/cat.js +92 -13
  27. package/dist/builtins/fs/cat.js.map +1 -1
  28. package/dist/builtins/fs/cd.d.ts +24 -6
  29. package/dist/builtins/fs/cd.js +71 -18
  30. package/dist/builtins/fs/cd.js.map +1 -1
  31. package/dist/builtins/fs/configWrite.d.ts +24 -8
  32. package/dist/builtins/fs/configWrite.js +77 -36
  33. package/dist/builtins/fs/configWrite.js.map +1 -1
  34. package/dist/builtins/fs/cp.d.ts +39 -4
  35. package/dist/builtins/fs/cp.js +122 -56
  36. package/dist/builtins/fs/cp.js.map +1 -1
  37. package/dist/builtins/fs/download.d.ts +31 -4
  38. package/dist/builtins/fs/download.js +75 -38
  39. package/dist/builtins/fs/download.js.map +1 -1
  40. package/dist/builtins/fs/du.d.ts +59 -33
  41. package/dist/builtins/fs/du.js +111 -79
  42. package/dist/builtins/fs/du.js.map +1 -1
  43. package/dist/builtins/fs/edit.d.ts +19 -4
  44. package/dist/builtins/fs/edit.js +77 -16
  45. package/dist/builtins/fs/edit.js.map +1 -1
  46. package/dist/builtins/fs/find.d.ts +25 -0
  47. package/dist/builtins/fs/find.js +76 -5
  48. package/dist/builtins/fs/find.js.map +1 -1
  49. package/dist/builtins/fs/ls.d.ts +69 -4
  50. package/dist/builtins/fs/ls.js +84 -45
  51. package/dist/builtins/fs/ls.js.map +1 -1
  52. package/dist/builtins/fs/mkdir.d.ts +28 -18
  53. package/dist/builtins/fs/mkdir.js +95 -66
  54. package/dist/builtins/fs/mkdir.js.map +1 -1
  55. package/dist/builtins/fs/mv.d.ts +34 -4
  56. package/dist/builtins/fs/mv.js +129 -64
  57. package/dist/builtins/fs/mv.js.map +1 -1
  58. package/dist/builtins/fs/pull.args.d.ts +56 -17
  59. package/dist/builtins/fs/pull.args.js +16 -66
  60. package/dist/builtins/fs/pull.args.js.map +1 -1
  61. package/dist/builtins/fs/pull.d.ts +62 -0
  62. package/dist/builtins/fs/pull.js +123 -31
  63. package/dist/builtins/fs/pull.js.map +1 -1
  64. package/dist/builtins/fs/pwd.d.ts +19 -5
  65. package/dist/builtins/fs/pwd.js +62 -8
  66. package/dist/builtins/fs/pwd.js.map +1 -1
  67. package/dist/builtins/fs/rm.d.ts +58 -21
  68. package/dist/builtins/fs/rm.js +99 -82
  69. package/dist/builtins/fs/rm.js.map +1 -1
  70. package/dist/builtins/fs/rmdir.d.ts +29 -11
  71. package/dist/builtins/fs/rmdir.js +87 -36
  72. package/dist/builtins/fs/rmdir.js.map +1 -1
  73. package/dist/builtins/fs/touch.d.ts +44 -9
  74. package/dist/builtins/fs/touch.js +91 -27
  75. package/dist/builtins/fs/touch.js.map +1 -1
  76. package/dist/builtins/fs/tree.d.ts +36 -9
  77. package/dist/builtins/fs/tree.js +126 -36
  78. package/dist/builtins/fs/tree.js.map +1 -1
  79. package/dist/builtins/fs/upload.d.ts +22 -3
  80. package/dist/builtins/fs/upload.js +82 -14
  81. package/dist/builtins/fs/upload.js.map +1 -1
  82. package/dist/builtins/fs/xattr.args.d.ts +12 -33
  83. package/dist/builtins/fs/xattr.args.js +17 -95
  84. package/dist/builtins/fs/xattr.args.js.map +1 -1
  85. package/dist/builtins/fs/xattr.d.ts +98 -8
  86. package/dist/builtins/fs/xattr.js +163 -24
  87. package/dist/builtins/fs/xattr.js.map +1 -1
  88. package/dist/builtins/games/bytes.d.ts +201 -5
  89. package/dist/builtins/games/bytes.js +255 -54
  90. package/dist/builtins/games/bytes.js.map +1 -1
  91. package/dist/builtins/games/chimes.d.ts +180 -3
  92. package/dist/builtins/games/chimes.js +203 -26
  93. package/dist/builtins/games/chimes.js.map +1 -1
  94. package/dist/builtins/games/chrislab.d.ts +101 -3
  95. package/dist/builtins/games/chrislab.js +117 -17
  96. package/dist/builtins/games/chrislab.js.map +1 -1
  97. package/dist/builtins/games/cowsay.d.ts +93 -2
  98. package/dist/builtins/games/cowsay.js +90 -31
  99. package/dist/builtins/games/cowsay.js.map +1 -1
  100. package/dist/builtins/games/figlet.d.ts +70 -2
  101. package/dist/builtins/games/figlet.js +83 -6
  102. package/dist/builtins/games/figlet.js.map +1 -1
  103. package/dist/builtins/games/lab.d.ts +104 -5
  104. package/dist/builtins/games/lab.js +144 -6
  105. package/dist/builtins/games/lab.js.map +1 -1
  106. package/dist/builtins/games/lolcat.d.ts +61 -1
  107. package/dist/builtins/games/lolcat.js +59 -24
  108. package/dist/builtins/games/lolcat.js.map +1 -1
  109. package/dist/builtins/games/morse.d.ts +36 -1
  110. package/dist/builtins/games/morse.js +50 -2
  111. package/dist/builtins/games/morse.js.map +1 -1
  112. package/dist/builtins/games/numbers.d.ts +241 -5
  113. package/dist/builtins/games/numbers.js +298 -23
  114. package/dist/builtins/games/numbers.js.map +1 -1
  115. package/dist/builtins/games/play.d.ts +96 -6
  116. package/dist/builtins/games/play.js +137 -6
  117. package/dist/builtins/games/play.js.map +1 -1
  118. package/dist/builtins/games/qr.d.ts +40 -1
  119. package/dist/builtins/games/qr.js +51 -2
  120. package/dist/builtins/games/qr.js.map +1 -1
  121. package/dist/builtins/games/show.d.ts +131 -6
  122. package/dist/builtins/games/show.js +208 -20
  123. package/dist/builtins/games/show.js.map +1 -1
  124. package/dist/builtins/games/sky.d.ts +178 -4
  125. package/dist/builtins/games/sky.js +228 -12
  126. package/dist/builtins/games/sky.js.map +1 -1
  127. package/dist/builtins/games/text.d.ts +258 -7
  128. package/dist/builtins/games/text.js +310 -29
  129. package/dist/builtins/games/text.js.map +1 -1
  130. package/dist/builtins/games/trek.d.ts +67 -3
  131. package/dist/builtins/games/trek.js +63 -10
  132. package/dist/builtins/games/trek.js.map +1 -1
  133. package/dist/builtins/games/wtf.d.ts +58 -1
  134. package/dist/builtins/games/wtf.js +67 -6
  135. package/dist/builtins/games/wtf.js.map +1 -1
  136. package/dist/builtins/help.d.ts +41 -3
  137. package/dist/builtins/help.js +92 -796
  138. package/dist/builtins/help.js.map +1 -1
  139. package/dist/builtins/net/connect.d.ts +36 -3
  140. package/dist/builtins/net/connect.js +84 -26
  141. package/dist/builtins/net/connect.js.map +1 -1
  142. package/dist/builtins/net/cubepath.d.ts +49 -5
  143. package/dist/builtins/net/cubepath.js +69 -27
  144. package/dist/builtins/net/cubepath.js.map +1 -1
  145. package/dist/builtins/net/logout.d.ts +13 -4
  146. package/dist/builtins/net/logout.js +49 -3
  147. package/dist/builtins/net/logout.js.map +1 -1
  148. package/dist/builtins/net/netstat.d.ts +29 -4
  149. package/dist/builtins/net/netstat.js +64 -23
  150. package/dist/builtins/net/netstat.js.map +1 -1
  151. package/dist/builtins/net/pacs.d.ts +169 -15
  152. package/dist/builtins/net/pacs.js +92 -33
  153. package/dist/builtins/net/pacs.js.map +1 -1
  154. package/dist/builtins/net/query.args.d.ts +95 -0
  155. package/dist/builtins/net/query.args.js +26 -0
  156. package/dist/builtins/net/query.args.js.map +1 -0
  157. package/dist/builtins/net/query.d.ts +98 -5
  158. package/dist/builtins/net/query.js +89 -83
  159. package/dist/builtins/net/query.js.map +1 -1
  160. package/dist/builtins/net/status.d.ts +5 -3
  161. package/dist/builtins/net/status.js +5 -12
  162. package/dist/builtins/net/status.js.map +1 -1
  163. package/dist/builtins/parametersofplugin.d.ts +82 -3
  164. package/dist/builtins/parametersofplugin.js +79 -23
  165. package/dist/builtins/parametersofplugin.js.map +1 -1
  166. package/dist/builtins/proc.d.ts +210 -3
  167. package/dist/builtins/proc.js +210 -119
  168. package/dist/builtins/proc.js.map +1 -1
  169. package/dist/builtins/res/compute.d.ts +67 -3
  170. package/dist/builtins/res/compute.js +121 -35
  171. package/dist/builtins/res/compute.js.map +1 -1
  172. package/dist/builtins/res/dicom.d.ts +55 -7
  173. package/dist/builtins/res/dicom.js +86 -52
  174. package/dist/builtins/res/dicom.js.map +1 -1
  175. package/dist/builtins/res/expect.d.ts +52 -3
  176. package/dist/builtins/res/expect.js +92 -29
  177. package/dist/builtins/res/expect.js.map +1 -1
  178. package/dist/builtins/res/feed.d.ts +475 -3
  179. package/dist/builtins/res/feed.js +253 -158
  180. package/dist/builtins/res/feed.js.map +1 -1
  181. package/dist/builtins/res/files.d.ts +517 -3
  182. package/dist/builtins/res/files.js +124 -44
  183. package/dist/builtins/res/files.js.map +1 -1
  184. package/dist/builtins/res/gather.d.ts +113 -3
  185. package/dist/builtins/res/gather.js +153 -44
  186. package/dist/builtins/res/gather.js.map +1 -1
  187. package/dist/builtins/res/gather.process.d.ts +27 -19
  188. package/dist/builtins/res/gather.process.js +29 -59
  189. package/dist/builtins/res/gather.process.js.map +1 -1
  190. package/dist/builtins/res/group.d.ts +284 -3
  191. package/dist/builtins/res/group.js +147 -76
  192. package/dist/builtins/res/group.js.map +1 -1
  193. package/dist/builtins/res/image.d.ts +30 -2
  194. package/dist/builtins/res/image.js +62 -10
  195. package/dist/builtins/res/image.js.map +1 -1
  196. package/dist/builtins/res/play.d.ts +71 -9
  197. package/dist/builtins/res/play.js +124 -82
  198. package/dist/builtins/res/play.js.map +1 -1
  199. package/dist/builtins/res/plugininstance.d.ts +307 -2
  200. package/dist/builtins/res/plugininstance.js +122 -50
  201. package/dist/builtins/res/plugininstance.js.map +1 -1
  202. package/dist/builtins/res/pluginmeta.d.ts +244 -2
  203. package/dist/builtins/res/pluginmeta.js +98 -40
  204. package/dist/builtins/res/pluginmeta.js.map +1 -1
  205. package/dist/builtins/res/record.d.ts +37 -3
  206. package/dist/builtins/res/record.js +127 -57
  207. package/dist/builtins/res/record.js.map +1 -1
  208. package/dist/builtins/res/resourceList.d.ts +136 -0
  209. package/dist/builtins/res/resourceList.js +51 -0
  210. package/dist/builtins/res/resourceList.js.map +1 -0
  211. package/dist/builtins/res/tag.d.ts +244 -3
  212. package/dist/builtins/res/tag.js +97 -41
  213. package/dist/builtins/res/tag.js.map +1 -1
  214. package/dist/builtins/res/user.d.ts +122 -3
  215. package/dist/builtins/res/user.js +83 -21
  216. package/dist/builtins/res/user.js.map +1 -1
  217. package/dist/builtins/res/workflow.d.ts +244 -2
  218. package/dist/builtins/res/workflow.js +97 -40
  219. package/dist/builtins/res/workflow.js.map +1 -1
  220. package/dist/builtins/store.d.ts +85 -3
  221. package/dist/builtins/store.js +135 -68
  222. package/dist/builtins/store.js.map +1 -1
  223. package/dist/builtins/sys/apropos.d.ts +80 -5
  224. package/dist/builtins/sys/apropos.js +121 -15
  225. package/dist/builtins/sys/apropos.js.map +1 -1
  226. package/dist/builtins/sys/cal.d.ts +44 -5
  227. package/dist/builtins/sys/cal.js +57 -10
  228. package/dist/builtins/sys/cal.js.map +1 -1
  229. package/dist/builtins/sys/command.d.ts +20 -0
  230. package/dist/builtins/sys/command.js +31 -0
  231. package/dist/builtins/sys/command.js.map +1 -1
  232. package/dist/builtins/sys/context.d.ts +13 -3
  233. package/dist/builtins/sys/context.js +51 -4
  234. package/dist/builtins/sys/context.js.map +1 -1
  235. package/dist/builtins/sys/date.d.ts +56 -5
  236. package/dist/builtins/sys/date.js +63 -9
  237. package/dist/builtins/sys/date.js.map +1 -1
  238. package/dist/builtins/sys/echo.d.ts +63 -2
  239. package/dist/builtins/sys/echo.js +87 -8
  240. package/dist/builtins/sys/echo.js.map +1 -1
  241. package/dist/builtins/sys/fortune.d.ts +27 -2
  242. package/dist/builtins/sys/fortune.js +44 -2
  243. package/dist/builtins/sys/fortune.js.map +1 -1
  244. package/dist/builtins/sys/grep.d.ts +245 -11
  245. package/dist/builtins/sys/grep.js +418 -131
  246. package/dist/builtins/sys/grep.js.map +1 -1
  247. package/dist/builtins/sys/joblets.d.ts +66 -7
  248. package/dist/builtins/sys/joblets.js +101 -14
  249. package/dist/builtins/sys/joblets.js.map +1 -1
  250. package/dist/builtins/sys/motd.d.ts +37 -3
  251. package/dist/builtins/sys/motd.js +49 -8
  252. package/dist/builtins/sys/motd.js.map +1 -1
  253. package/dist/builtins/sys/notes.d.ts +75 -3
  254. package/dist/builtins/sys/notes.js +90 -29
  255. package/dist/builtins/sys/notes.js.map +1 -1
  256. package/dist/builtins/sys/physicalmode.d.ts +24 -3
  257. package/dist/builtins/sys/physicalmode.js +68 -14
  258. package/dist/builtins/sys/physicalmode.js.map +1 -1
  259. package/dist/builtins/sys/tasks.d.ts +74 -5
  260. package/dist/builtins/sys/tasks.js +102 -14
  261. package/dist/builtins/sys/tasks.js.map +1 -1
  262. package/dist/builtins/sys/textFilters.d.ts +673 -41
  263. package/dist/builtins/sys/textFilters.js +719 -264
  264. package/dist/builtins/sys/textFilters.js.map +1 -1
  265. package/dist/builtins/sys/timing.d.ts +24 -3
  266. package/dist/builtins/sys/timing.js +67 -14
  267. package/dist/builtins/sys/timing.js.map +1 -1
  268. package/dist/builtins/sys/variables.d.ts +70 -4
  269. package/dist/builtins/sys/variables.js +103 -31
  270. package/dist/builtins/sys/variables.js.map +1 -1
  271. package/dist/builtins/sys/version.d.ts +27 -2
  272. package/dist/builtins/sys/version.js +48 -3
  273. package/dist/builtins/sys/version.js.map +1 -1
  274. package/dist/builtins/sys/weather.d.ts +92 -15
  275. package/dist/builtins/sys/weather.js +71 -45
  276. package/dist/builtins/sys/weather.js.map +1 -1
  277. package/dist/builtins/sys/whoami.d.ts +38 -18
  278. package/dist/builtins/sys/whoami.js +112 -8
  279. package/dist/builtins/sys/whoami.js.map +1 -1
  280. package/dist/builtins/utils.d.ts +1 -38
  281. package/dist/builtins/utils.js +1 -87
  282. package/dist/builtins/utils.js.map +1 -1
  283. package/dist/chris/backend.js +2 -0
  284. package/dist/chris/backend.js.map +1 -1
  285. package/dist/chris/chrisCommands.js +62 -159
  286. package/dist/chris/chrisCommands.js.map +1 -1
  287. package/dist/chris/commandFallback.d.ts +12 -0
  288. package/dist/chris/commandFallback.js +47 -0
  289. package/dist/chris/commandFallback.js.map +1 -1
  290. package/dist/chris/files.js +24 -85
  291. package/dist/chris/files.js.map +1 -1
  292. package/dist/chris/filesystem.js +7 -5
  293. package/dist/chris/filesystem.js.map +1 -1
  294. package/dist/chris/help.js +0 -1082
  295. package/dist/chris/help.js.map +1 -1
  296. package/dist/chris/kinds.d.ts +30 -0
  297. package/dist/chris/kinds.js +154 -0
  298. package/dist/chris/kinds.js.map +1 -0
  299. package/dist/chris/mounts.d.ts +4 -4
  300. package/dist/chris/mounts.js +9 -16
  301. package/dist/chris/mounts.js.map +1 -1
  302. package/dist/chris/navigation.d.ts +2 -3
  303. package/dist/chris/navigation.js +6 -20
  304. package/dist/chris/navigation.js.map +1 -1
  305. package/dist/chris/pacsResources.d.ts +259 -0
  306. package/dist/chris/pacsResources.js +168 -0
  307. package/dist/chris/pacsResources.js.map +1 -0
  308. package/dist/chris/promptContext.d.ts +6 -0
  309. package/dist/chris/promptContext.js +3 -1
  310. package/dist/chris/promptContext.js.map +1 -1
  311. package/dist/core/argumentKinds.d.ts +107 -0
  312. package/dist/core/argumentKinds.js +223 -0
  313. package/dist/core/argumentKinds.js.map +1 -0
  314. package/dist/core/backend.d.ts +4 -1
  315. package/dist/core/backend.js.map +1 -1
  316. package/dist/core/commandDeclaration.d.ts +453 -0
  317. package/dist/core/commandDeclaration.js +52 -0
  318. package/dist/core/commandDeclaration.js.map +1 -0
  319. package/dist/core/commandParse.d.ts +64 -0
  320. package/dist/core/commandParse.js +468 -0
  321. package/dist/core/commandParse.js.map +1 -0
  322. package/dist/core/commandRegistry.d.ts +37 -0
  323. package/dist/core/commandRegistry.js +100 -3
  324. package/dist/core/commandRegistry.js.map +1 -1
  325. package/dist/core/commandSchema.d.ts +32 -0
  326. package/dist/core/commandSchema.js +117 -0
  327. package/dist/core/commandSchema.js.map +1 -0
  328. package/dist/core/commandUsage.d.ts +62 -0
  329. package/dist/core/commandUsage.js +247 -0
  330. package/dist/core/commandUsage.js.map +1 -0
  331. package/dist/core/coreCommands.js +66 -214
  332. package/dist/core/coreCommands.js.map +1 -1
  333. package/dist/core/dispatch.js +15 -8
  334. package/dist/core/dispatch.js.map +1 -1
  335. package/dist/core/paths.d.ts +51 -0
  336. package/dist/core/paths.js +86 -2
  337. package/dist/core/paths.js.map +1 -1
  338. package/dist/core/preprocess.d.ts +10 -9
  339. package/dist/core/preprocess.js +10 -20
  340. package/dist/core/preprocess.js.map +1 -1
  341. package/dist/core/warmupFailures.d.ts +34 -2
  342. package/dist/core/warmupFailures.js +43 -2
  343. package/dist/core/warmupFailures.js.map +1 -1
  344. package/dist/lib/completer/cfsPaths.d.ts +14 -0
  345. package/dist/lib/completer/cfsPaths.js +91 -0
  346. package/dist/lib/completer/cfsPaths.js.map +1 -0
  347. package/dist/lib/completer/declared.d.ts +15 -0
  348. package/dist/lib/completer/declared.js +189 -0
  349. package/dist/lib/completer/declared.js.map +1 -0
  350. package/dist/lib/completer/index.js +33 -79
  351. package/dist/lib/completer/index.js.map +1 -1
  352. package/dist/lib/parser.d.ts +5 -8
  353. package/dist/lib/parser.js +2 -11
  354. package/dist/lib/parser.js.map +1 -1
  355. package/dist/lib/vfs/vfs.d.ts +2 -1
  356. package/dist/lib/vfs/vfs.js +9 -6
  357. package/dist/lib/vfs/vfs.js.map +1 -1
  358. package/dist/lib/wildcard.js +2 -3
  359. package/dist/lib/wildcard.js.map +1 -1
  360. package/dist/notes.json +1 -1
  361. package/package.json +6 -5
@@ -0,0 +1,453 @@
1
+ /**
2
+ * @file A command's declaration: its name, the grammar its line is parsed
3
+ * against, the kind of every argument, its help prose, what it holds of the
4
+ * session, and its handler, in one record.
5
+ *
6
+ * The grammar is the shell's own: subcommands; operands in order, each
7
+ * optional or repeated; options with a short name, a long name, or both, and
8
+ * a value or none. Every argument names a kind (`argumentKinds.ts`), which
9
+ * checks its value and completes it. The handler receives a typed object the
10
+ * compiler infers from the grammar, written `as const`: its operands, its
11
+ * options and, for a subcommand, which one. Reading an undeclared option is a
12
+ * build error, and the handler never sees the words.
13
+ *
14
+ * A command whose arguments form an expression language (`find`) declares
15
+ * `grammar: 'expression'` instead, keeps its own parser and completion, and
16
+ * receives its words after references expand.
17
+ *
18
+ * Key components:
19
+ * - CommandGrammar: subcommands, operands and options, as a value.
20
+ * - BareGrammar: the line with no subcommand, and its own options.
21
+ * - CommandDeclaration: the whole record for a parsed command.
22
+ * - ExpressionDeclaration: the record for an expression-grammar command.
23
+ * - CommandArguments: the typed object a handler receives.
24
+ * - SubcommandArguments: one subcommand's share of it.
25
+ * - command_declare: declares a command, inferring its handler's argument.
26
+ *
27
+ * Typical usage:
28
+ * ```ts
29
+ * const HELLO_GRAMMAR = {
30
+ * operands: [{ name: 'who', kind: 'word', optional: true, summary: 'Whom to greet' }],
31
+ * options: { loud: { short: 'l', long: 'loud', summary: 'Shout' } },
32
+ * } as const satisfies CommandGrammar;
33
+ * export const helloCommand = command_declare({
34
+ * name: 'hello',
35
+ * grammar: HELLO_GRAMMAR,
36
+ * help: { summary: 'Say hello', description: 'Greets someone.' },
37
+ * handler: async (args) => envelope_ok(`hello ${args.operands.who ?? 'world'}${args.options.loud ? '!' : ''}\n`),
38
+ * });
39
+ * ```
40
+ *
41
+ * Dependencies: types only (`@fnndsc/menu` for the envelope, the registry for
42
+ * session pieces).
43
+ *
44
+ * @module
45
+ */
46
+ import type { CommandEnvelope } from '@fnndsc/menu';
47
+ import type { SessionPiece } from './commandRegistry.js';
48
+ /**
49
+ * What an argument is: the kind that checks and completes it, and that
50
+ * kind's parameters.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * const sortField: ArgumentGrammar = { kind: 'enum', values: ['name', 'size'] };
55
+ * ```
56
+ */
57
+ export interface ArgumentGrammar {
58
+ /** The kind's name: a core kind (`word`, `enum`, `int`, `number`, `cfsPath`, `hostPath`, `variable`, `job`) or one a backend registers. */
59
+ readonly kind: string;
60
+ /** The words an `enum` takes. */
61
+ readonly values?: readonly string[];
62
+ /** Pathname expansion for a `cfsPath` or `hostPath` operand: a wildcard in it matches paths. */
63
+ readonly glob?: boolean;
64
+ /** The least an `int` or `number` takes. */
65
+ readonly min?: number;
66
+ /** The most an `int` or `number` takes. */
67
+ readonly max?: number;
68
+ }
69
+ /**
70
+ * One operand: a word that is not an option, in its place on the line.
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * const paths: OperandGrammar = { name: 'paths', kind: 'cfsPath', optional: true, repeat: true, glob: true, summary: 'What to list' };
75
+ * ```
76
+ */
77
+ export interface OperandGrammar extends ArgumentGrammar {
78
+ /** Its name: the property the handler reads, and the word usage shows (`<path>`). */
79
+ readonly name: string;
80
+ /** One line for help and the schema. */
81
+ readonly summary: string;
82
+ /** It may be left out. */
83
+ readonly optional?: boolean;
84
+ /** It takes every word left over: at most one operand of a grammar repeats. */
85
+ readonly repeat?: boolean;
86
+ /**
87
+ * It stands only when this option (by its property) is not given: grep's
88
+ * pattern operand is gone once `-e` gives the pattern, and every word is a
89
+ * file. Such an operand is optional.
90
+ */
91
+ readonly unless?: string;
92
+ }
93
+ /** An option's value: an argument with the word usage shows for it (`<field>`). */
94
+ export interface OptionValueGrammar extends ArgumentGrammar {
95
+ /** The word usage shows: `--sort <field>`. */
96
+ readonly name: string;
97
+ /**
98
+ * The value may be left out (GNU's `optional_argument`): it is given only
99
+ * in the same word, `--highlight=python` or `-hpython`, and the option
100
+ * alone (`--highlight`) reads as the empty value.
101
+ */
102
+ readonly optional?: boolean;
103
+ }
104
+ /**
105
+ * One option: `-l`, `--long`, or both; a switch, or one that takes a value.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * const sort: OptionGrammar = { long: 'sort', summary: 'Sort by', value: { name: 'field', kind: 'enum', values: ['name', 'size'] } };
110
+ * ```
111
+ */
112
+ export interface OptionGrammar {
113
+ /** Its one-character name, without the dash. */
114
+ readonly short?: string;
115
+ /** Its long name, without the dashes. */
116
+ readonly long?: string;
117
+ /** One line for help and the schema. */
118
+ readonly summary: string;
119
+ /** What it takes; absent, it is a switch. */
120
+ readonly value?: OptionValueGrammar;
121
+ /** A value option given more than once keeps every value; otherwise the last one counts. */
122
+ readonly repeat?: boolean;
123
+ /**
124
+ * A value option given no value (last on the line, or before another
125
+ * option) is a question, not a refusal: the handler reads `null` and asks
126
+ * for the value (`query … --csv-to`).
127
+ */
128
+ readonly asks?: boolean;
129
+ /**
130
+ * A word of digits after a dash (`-5`) is this option with that value, as
131
+ * `head -5` is `head -n 5`. At most one option of a line says so.
132
+ */
133
+ readonly numeral?: boolean;
134
+ }
135
+ /** A grammar's options, by the property the handler reads them as. */
136
+ export type OptionsGrammar = {
137
+ readonly [key: string]: OptionGrammar;
138
+ };
139
+ /**
140
+ * A subcommand: the word after the command, with operands and options of its
141
+ * own. The command's own options hold after it too.
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * const drop: SubcommandGrammar = { summary: 'Remove one anchor', operands: [{ name: 'name', kind: 'word', summary: 'The anchor' }] };
146
+ * ```
147
+ */
148
+ export interface SubcommandGrammar {
149
+ /** One line for help and the schema. */
150
+ readonly summary: string;
151
+ /** Its operands, in order. */
152
+ readonly operands?: readonly OperandGrammar[];
153
+ /** Its options. */
154
+ readonly options?: OptionsGrammar;
155
+ }
156
+ /**
157
+ * A command's grammar: what its line may hold, as a value. Written `as const`,
158
+ * so the handler's argument is inferred from it.
159
+ *
160
+ * @example
161
+ * ```ts
162
+ * const grammar = { operands: [{ name: 'path', kind: 'cfsPath', summary: 'Where' }] } as const satisfies CommandGrammar;
163
+ * ```
164
+ */
165
+ export interface CommandGrammar {
166
+ /** Its operands, in order; with subcommands, the words of the bare command. */
167
+ readonly operands?: readonly OperandGrammar[];
168
+ /** Its options, which hold after any subcommand too. */
169
+ readonly options?: OptionsGrammar;
170
+ /** Its subcommands, by the word that names each. */
171
+ readonly subcommands?: {
172
+ readonly [word: string]: SubcommandGrammar;
173
+ };
174
+ /** What the command does with no subcommand; absent, a command with subcommands needs one. */
175
+ readonly bare?: BareGrammar;
176
+ }
177
+ /**
178
+ * A command's line with no subcommand, when it has subcommands: what it does,
179
+ * and the options it takes of its own (`jobs --all`, as `jobs list --all`).
180
+ * The command's own options hold beside them.
181
+ *
182
+ * @example
183
+ * ```ts
184
+ * const bare: BareGrammar = { summary: 'List the first page', options: { all: { long: 'all', summary: 'Every page' } } };
185
+ * ```
186
+ */
187
+ export interface BareGrammar {
188
+ /** One line for help and the schema. */
189
+ readonly summary: string;
190
+ /** Its options. */
191
+ readonly options?: OptionsGrammar;
192
+ }
193
+ /**
194
+ * A command's help prose: what `help` shows beside the usage the grammar
195
+ * generates.
196
+ *
197
+ * @example
198
+ * ```ts
199
+ * const prose: CommandProse = { summary: 'List directory contents', description: 'Lists…', category: 'Navigation' };
200
+ * ```
201
+ */
202
+ export interface CommandProse {
203
+ /** One line for listings. */
204
+ readonly summary: string;
205
+ /** What the command does, as one paragraph. */
206
+ readonly description: string;
207
+ /** Lines `help` shows under EXAMPLES; a `#` starts a comment. */
208
+ readonly examples?: readonly string[];
209
+ /** Where `help` lists it: one of the help sections. */
210
+ readonly category?: string;
211
+ /** It mirrors a Unix utility: the group `help POSIX` lists it under, and how it differs, in a line. */
212
+ readonly posix?: {
213
+ readonly group: 'Files' | 'Text' | 'System' | 'Shell';
214
+ readonly differs: string;
215
+ };
216
+ }
217
+ /** A kind's value type: a number for `int` and `number`, the declared words for `enum`, else text. */
218
+ type KindValue<A> = A extends {
219
+ readonly kind: 'int' | 'number';
220
+ } ? number : A extends {
221
+ readonly kind: 'enum';
222
+ readonly values: readonly (infer V extends string)[];
223
+ } ? V : string;
224
+ /** An operand's value: a list when it repeats, possibly absent when optional. */
225
+ type OperandValue<O> = O extends {
226
+ readonly repeat: true;
227
+ } ? KindValue<O>[] : O extends {
228
+ readonly optional: true;
229
+ } ? KindValue<O> | undefined : KindValue<O>;
230
+ /** The operands a grammar declares, by name. */
231
+ type OperandsOf<G> = G extends {
232
+ readonly operands: readonly (infer O)[];
233
+ } ? {
234
+ readonly [P in O as P extends {
235
+ readonly name: infer N extends string;
236
+ } ? N : never]: OperandValue<P>;
237
+ } : Record<never, never>;
238
+ /** The names of a grammar's operands that expand pathnames. */
239
+ type GlobNamesOf<G> = G extends {
240
+ readonly operands: readonly (infer O)[];
241
+ } ? O extends {
242
+ readonly glob: true;
243
+ readonly name: infer N extends string;
244
+ } ? N : never : never;
245
+ /** Whether each globbing operand's words came from pathname expansion. */
246
+ type ExpandedOf<G> = {
247
+ readonly [N in GlobNamesOf<G>]: boolean;
248
+ };
249
+ /** An option's value: a switch is a boolean; a value option its value, or every value when it repeats; null when it asks. */
250
+ type OptionValue<O> = O extends {
251
+ readonly value: infer V;
252
+ } ? O extends {
253
+ readonly repeat: true;
254
+ } ? KindValue<V>[] : KindValue<V> | undefined | (O extends {
255
+ readonly asks: true;
256
+ } ? null : never) : boolean;
257
+ /** The options a grammar declares, by property. */
258
+ type OptionsOf<G> = G extends {
259
+ readonly options: infer M;
260
+ } ? {
261
+ readonly [K in keyof M]: OptionValue<M[K]>;
262
+ } : Record<never, never>;
263
+ /** One parsed line: what a handler reads, for a grammar and the command's own options. */
264
+ interface ParsedLine<S, G> {
265
+ /** The operands, by name. */
266
+ readonly operands: OperandsOf<S>;
267
+ /** The options, by property: the subcommand's and the command's. */
268
+ readonly options: OptionsOf<S> & OptionsOf<G>;
269
+ /** For each operand that globs, whether its words came from pathname expansion. */
270
+ readonly expanded: ExpandedOf<S>;
271
+ }
272
+ /** The options the bare command takes of its own. */
273
+ type BareOptionsOf<G> = G extends {
274
+ readonly bare: {
275
+ readonly options: infer M;
276
+ };
277
+ } ? {
278
+ readonly [K in keyof M]: OptionValue<M[K]>;
279
+ } : Record<never, never>;
280
+ /** The bare command's parsed line: the grammar's operands, its own options and the command's. */
281
+ interface BareParsedLine<G> {
282
+ /** The operands, by name. */
283
+ readonly operands: OperandsOf<G>;
284
+ /** The options, by property: the bare command's and the command's. */
285
+ readonly options: BareOptionsOf<G> & OptionsOf<G>;
286
+ /** For each operand that globs, whether its words came from pathname expansion. */
287
+ readonly expanded: ExpandedOf<G>;
288
+ }
289
+ /** The bare command's line, when the grammar allows one. */
290
+ type BareLine<G> = G extends {
291
+ readonly subcommands: object;
292
+ } ? G extends {
293
+ readonly bare: object;
294
+ } ? {
295
+ readonly subcommand: null;
296
+ } & BareParsedLine<G> : never : {
297
+ readonly subcommand: null;
298
+ } & BareParsedLine<G>;
299
+ /** Each subcommand's line. */
300
+ type SubcommandLine<G> = G extends {
301
+ readonly subcommands: infer S;
302
+ } ? {
303
+ [K in keyof S & string]: {
304
+ readonly subcommand: K;
305
+ } & ParsedLine<S[K], G>;
306
+ }[keyof S & string] : never;
307
+ /**
308
+ * The typed object a handler receives: which subcommand (null for none), its
309
+ * operands, its options, and which operands came from pathname expansion.
310
+ *
311
+ * @example
312
+ * ```ts
313
+ * type LsArguments = CommandArguments<typeof LS_GRAMMAR>;
314
+ * const paths: string[] = (args as LsArguments).operands.paths;
315
+ * ```
316
+ */
317
+ export type CommandArguments<G extends CommandGrammar> = BareLine<G> | SubcommandLine<G>;
318
+ /**
319
+ * One subcommand's share of a handler's argument, for a function that runs it.
320
+ *
321
+ * @example
322
+ * ```ts
323
+ * function drop_run(args: SubcommandArguments<typeof BERTH_GRAMMAR, 'drop'>): CommandEnvelope { … }
324
+ * ```
325
+ */
326
+ export type SubcommandArguments<G extends CommandGrammar, K extends string> = Extract<CommandArguments<G>, {
327
+ readonly subcommand: K;
328
+ }>;
329
+ /**
330
+ * Another word that runs a command: the word alone, holding what the command
331
+ * holds, or the word with what it holds when that differs (`feeds`, a read,
332
+ * holds nothing while `feed` may create one).
333
+ *
334
+ * @example
335
+ * ```ts
336
+ * const aliases: readonly CommandAlias[] = [{ name: feeds, holds: [] }, job];
337
+ * ```
338
+ */
339
+ export type CommandAlias = string | {
340
+ readonly name: string;
341
+ readonly holds: readonly SessionPiece[];
342
+ };
343
+ /**
344
+ * A command parsed against its grammar: the one record that is its help,
345
+ * its completion, its schema and its dispatch.
346
+ *
347
+ * @example
348
+ * ```ts
349
+ * const declaration: CommandDeclaration<typeof HELLO_GRAMMAR> = helloCommand;
350
+ * ```
351
+ */
352
+ export interface CommandDeclaration<G extends CommandGrammar = CommandGrammar> {
353
+ /** The word that runs it. */
354
+ readonly name: string;
355
+ /** What its line may hold. */
356
+ readonly grammar: G;
357
+ /** What `help` says of it. */
358
+ readonly help: CommandProse;
359
+ /** Other words that run it (`feeds` for `feed`): parsed, completed, listed and described as the command, usage and refusals saying the word typed. */
360
+ readonly aliases?: readonly CommandAlias[];
361
+ /** The pieces of the session it changes while it runs; absent, it holds the whole session. */
362
+ readonly holds?: readonly SessionPiece[];
363
+ /**
364
+ * Runs it, given the line parsed and checked. A method, so a record of one
365
+ * grammar stands where any declaration is read.
366
+ *
367
+ * @param args - The typed line.
368
+ * @returns Its outcome.
369
+ */
370
+ handler(args: CommandArguments<G>): Promise<CommandEnvelope>;
371
+ }
372
+ /**
373
+ * A command whose arguments are an expression language of its own (`find`):
374
+ * it parses and completes them itself, under a ratchet.
375
+ *
376
+ * @example
377
+ * ```ts
378
+ * const findCommand: ExpressionDeclaration = { name: 'find', grammar: 'expression', help, handler: builtin_find };
379
+ * ```
380
+ */
381
+ export interface ExpressionDeclaration {
382
+ /** The word that runs it. */
383
+ readonly name: string;
384
+ /** Says it parses its own words. */
385
+ readonly grammar: 'expression';
386
+ /** What `help` says of it; its usage is its own. */
387
+ readonly help: CommandProse & {
388
+ readonly usage: string;
389
+ };
390
+ /** Other words that run it, answered as the command. */
391
+ readonly aliases?: readonly CommandAlias[];
392
+ /** The pieces of the session it changes while it runs. */
393
+ readonly holds?: readonly SessionPiece[];
394
+ /**
395
+ * Runs it over its words, references expanded and nothing globbed.
396
+ *
397
+ * @param args - The words after the command.
398
+ * @returns Its outcome.
399
+ */
400
+ handler(args: string[]): Promise<CommandEnvelope>;
401
+ /**
402
+ * Completes one word of its line.
403
+ *
404
+ * @param words - The words before the one completed.
405
+ * @param word - The word typed so far.
406
+ * @returns The candidates.
407
+ */
408
+ complete?(words: readonly string[], word: string): Promise<string[]>;
409
+ }
410
+ /** Any declaration the registry holds. */
411
+ export type AnyCommandDeclaration = CommandDeclaration | ExpressionDeclaration;
412
+ /**
413
+ * Declares a command. Returns its argument unchanged; what it adds is the
414
+ * inference: the handler's argument is typed from the grammar beside it.
415
+ *
416
+ * @param declaration - The record.
417
+ * @returns The same record.
418
+ *
419
+ * @example
420
+ * ```ts
421
+ * export const helloCommand = command_declare({ name: 'hello', grammar: HELLO_GRAMMAR, help, handler: async (args) => … });
422
+ * ```
423
+ */
424
+ export declare function command_declare<const G extends CommandGrammar>(declaration: CommandDeclaration<G>): CommandDeclaration<G>;
425
+ /**
426
+ * The command under each of its other words: the same grammar, help and
427
+ * handler, named as typed, holding what that word holds. The registry
428
+ * answers each word with one of these; the schema and the migration count
429
+ * read the command once.
430
+ *
431
+ * @param declaration - The command.
432
+ * @returns One record per alias, in the order declared; none without aliases.
433
+ *
434
+ * @example
435
+ * ```ts
436
+ * commandAliases_list(feedCommand).map((alias) => alias.name); // [feeds]
437
+ * ```
438
+ */
439
+ export declare function commandAliases_list<D extends AnyCommandDeclaration>(declaration: D): D[];
440
+ /**
441
+ * Whether a declaration parses its line against a grammar (rather than an
442
+ * expression language of its own).
443
+ *
444
+ * @param declaration - The record.
445
+ * @returns True for a grammar.
446
+ *
447
+ * @example
448
+ * ```ts
449
+ * if (declaration_isParsed(declaration)) declaration.grammar.operands;
450
+ * ```
451
+ */
452
+ export declare function declaration_isParsed(declaration: AnyCommandDeclaration): declaration is CommandDeclaration;
453
+ export {};
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Declares a command. Returns its argument unchanged; what it adds is the
3
+ * inference: the handler's argument is typed from the grammar beside it.
4
+ *
5
+ * @param declaration - The record.
6
+ * @returns The same record.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * export const helloCommand = command_declare({ name: 'hello', grammar: HELLO_GRAMMAR, help, handler: async (args) => … });
11
+ * ```
12
+ */
13
+ export function command_declare(declaration) {
14
+ return declaration;
15
+ }
16
+ /**
17
+ * The command under each of its other words: the same grammar, help and
18
+ * handler, named as typed, holding what that word holds. The registry
19
+ * answers each word with one of these; the schema and the migration count
20
+ * read the command once.
21
+ *
22
+ * @param declaration - The command.
23
+ * @returns One record per alias, in the order declared; none without aliases.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * commandAliases_list(feedCommand).map((alias) => alias.name); // [feeds]
28
+ * ```
29
+ */
30
+ export function commandAliases_list(declaration) {
31
+ return (declaration.aliases ?? []).map((alias) => {
32
+ const { aliases: _aliases, ...command } = declaration;
33
+ // The same record under another word: only the name and the holds differ.
34
+ return (typeof alias === 'string' ? { ...command, name: alias } : { ...command, name: alias.name, holds: alias.holds });
35
+ });
36
+ }
37
+ /**
38
+ * Whether a declaration parses its line against a grammar (rather than an
39
+ * expression language of its own).
40
+ *
41
+ * @param declaration - The record.
42
+ * @returns True for a grammar.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * if (declaration_isParsed(declaration)) declaration.grammar.operands;
47
+ * ```
48
+ */
49
+ export function declaration_isParsed(declaration) {
50
+ return declaration.grammar !== 'expression';
51
+ }
52
+ //# sourceMappingURL=commandDeclaration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commandDeclaration.js","sourceRoot":"","sources":["../../src/core/commandDeclaration.ts"],"names":[],"mappings":"AA8YA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,eAAe,CAAiC,WAAkC;IAChG,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,mBAAmB,CAAkC,WAAc;IACjF,OAAO,CAAC,WAAW,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAmB,EAAK,EAAE;QAChE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE,GAAG,WAAW,CAAC;QACtD,0EAA0E;QAC1E,OAAO,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAM,CAAC;IAC/H,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,oBAAoB,CAAC,WAAkC;IACrE,OAAO,WAAW,CAAC,OAAO,KAAK,YAAY,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,64 @@
1
+ import { type CommandEnvelope } from '@fnndsc/menu';
2
+ import type { ShellWord } from '../lib/parser.js';
3
+ import type { CommandDeclaration } from './commandDeclaration.js';
4
+ /** What parsing a line came to: the handler's argument, or the refusal. */
5
+ export type LineParse = {
6
+ readonly ok: true;
7
+ readonly args: ParsedArguments;
8
+ } | {
9
+ readonly ok: false;
10
+ readonly refusal: string;
11
+ };
12
+ /** The handler's argument, before the grammar's types are put on it. */
13
+ export interface ParsedArguments {
14
+ /** The subcommand, or null for none. */
15
+ readonly subcommand: string | null;
16
+ /** The operands, by name. */
17
+ readonly operands: Record<string, unknown>;
18
+ /** The options, by property. */
19
+ readonly options: Record<string, unknown>;
20
+ /** For each operand that globs, whether its words came from pathname expansion. */
21
+ readonly expanded: Record<string, boolean>;
22
+ }
23
+ /**
24
+ * Parses a declared command's line into the object its handler reads.
25
+ *
26
+ * @param declaration - The command.
27
+ * @param words - The words after the command, references expanded, quoting kept.
28
+ * @returns The handler's argument, or the refusal (`ls: unrecognized option '--x'; usage: …`).
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const parsed: LineParse = await commandLine_parse(lsCommand, [shellWord_literal('-l')]);
33
+ * if (parsed.ok) parsed.args.options['long']; // true
34
+ * ```
35
+ */
36
+ export declare function commandLine_parse(declaration: CommandDeclaration, words: readonly ShellWord[]): Promise<LineParse>;
37
+ /**
38
+ * Parses a line against its declaration and runs the handler on it; a bad
39
+ * line is refused on the error channel, the handler never called.
40
+ *
41
+ * @param declaration - The command.
42
+ * @param args - The words after the command.
43
+ * @returns The handler's envelope, or the refusal's.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * await declaredCommand_run(lsCommand, ['--nosuch']); // renderedErr: "ls: unrecognized option '--nosuch'; usage: …"
48
+ * ```
49
+ */
50
+ export declare function declaredCommand_run(declaration: CommandDeclaration, args: readonly string[]): Promise<CommandEnvelope>;
51
+ /**
52
+ * The registry's handler for a declared command: the words a line hands
53
+ * on, parsed against the declaration.
54
+ *
55
+ * @param declaration - The command.
56
+ * @returns The handler.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const handler = declaredHandler_make(lsCommand);
61
+ * await handler(['-l']);
62
+ * ```
63
+ */
64
+ export declare function declaredHandler_make(declaration: CommandDeclaration): (args: string[]) => Promise<CommandEnvelope>;