@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
@@ -1,15 +1,37 @@
1
1
  /**
2
- * @file Builtin touch command.
3
- * Creates files, reported as a command envelope.
2
+ * @file `touch`: makes files in ChRIS's filesystem (CFS), empty or with text.
3
+ *
4
+ * Declared in one record (`touchCommand`): files, which glob, and the text
5
+ * to write, given inline (`--withContents`) or from a file on this machine
6
+ * (`--withContentsFromFile`). A path through a link is written where the
7
+ * link points.
8
+ *
9
+ * Key components:
10
+ * - touchCommand: the declaration.
11
+ * - builtin_touch: the declaration run over words already split.
12
+ * - touch_run: the typed core behind both, and the typed API.
13
+ *
14
+ * Typical usage:
15
+ * ```ts
16
+ * await builtin_touch(['--withContents', 'Hello!', 'greeting.txt']);
17
+ * await touch_run({ paths: ['greeting.txt'], contents: 'Hello!' });
18
+ * ```
19
+ *
20
+ * Dependencies: the session's filesystem and listing cache, the store-path
21
+ * resolver, and this machine's disk (for `--withContentsFromFile`).
22
+ *
23
+ * @module
4
24
  */
5
25
  import chalk from 'chalk';
6
26
  import fs from 'fs';
7
27
  import path from 'path';
8
- import { commandArgs_process, optionsUnknown_refusal, path_resolve } from '../utils.js';
28
+ import { path_resolve, storePath_resolve } from '../utils.js';
9
29
  import { listingCache_get, vfsDispatcher_get } from '../../core/filesystem.js';
10
30
  import { pathEntry_find, entry_isFolder } from './entries.js';
11
31
  import { errno_words, touch_render, vfs_fail } from '@fnndsc/fond';
12
32
  import { envelope_ok, envelope_error } from '@fnndsc/menu';
33
+ import { command_declare } from '../../core/commandDeclaration.js';
34
+ import { declaredCommand_run } from '../../core/commandParse.js';
13
35
  /**
14
36
  * Reads the local file whose text a touch writes.
15
37
  *
@@ -53,6 +75,64 @@ async function file_touch(dispatcher, targetPath, content) {
53
75
  const written = await dispatcher.write(targetPath, content ?? '');
54
76
  return written.ok || written.errno !== 'EISDIR' ? written : vfs_fail('EISDIR', `Is a directory: a folder already holds ${targetPath}`);
55
77
  }
78
+ /**
79
+ * Forgets the listing of the folder that holds a touched file, by the
80
+ * session's path and by the store's.
81
+ *
82
+ * @param shown - The file as the session names it.
83
+ * @param targetPath - The file in the store.
84
+ */
85
+ function parentListings_forget(shown, targetPath) {
86
+ for (const at of new Set([shown, targetPath]))
87
+ listingCache_get().cache_invalidate?.(path.posix.dirname(at));
88
+ }
89
+ /** What a `touch` line may hold. */
90
+ const TOUCH_GRAMMAR = {
91
+ operands: [
92
+ { name: 'paths', kind: 'cfsPath', repeat: true, glob: true, summary: 'The files to make; with text, only the first takes it' },
93
+ ],
94
+ options: {
95
+ withContents: { long: 'withContents', summary: 'Create the file with this text inline', value: { name: 'string', kind: 'word' } },
96
+ withContentsFromFile: { long: 'withContentsFromFile', summary: 'Create the file with the text of a file on this machine', value: { name: 'file', kind: 'hostPath' } },
97
+ },
98
+ };
99
+ /**
100
+ * `touch [--withContents <string>] [--withContentsFromFile <file>] <file…>`: the declaration.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * commands_register({ declarations: [touchCommand] });
105
+ * ```
106
+ */
107
+ export const touchCommand = command_declare({
108
+ name: 'touch',
109
+ grammar: TOUCH_GRAMMAR,
110
+ help: {
111
+ summary: 'Create empty files or files with content',
112
+ description: "Makes each file in ChRIS's filesystem: a file already there is left as it is, a missing one is made empty. With --withContents or --withContentsFromFile the first file is written whole with that text. A path through a link is written where the link points. touch makes no folders (mkdir -p does).",
113
+ category: 'Files',
114
+ posix: { group: 'Files', differs: 'makes a CFS file; --withContents writes text into it' },
115
+ examples: [
116
+ 'touch file.txt # Create empty file',
117
+ 'touch --withContents "Hello!" greeting.txt # Create file with string',
118
+ 'touch --withContentsFromFile template.json config.json # Create from local file',
119
+ ],
120
+ },
121
+ handler: async (args) => touch_run({
122
+ paths: args.operands.paths,
123
+ contents: args.options.withContents,
124
+ contentsFromFile: args.options.withContentsFromFile,
125
+ }),
126
+ });
127
+ /**
128
+ * `touch` over words already split: the declaration's parse and handler.
129
+ *
130
+ * @param args - The words after `touch`.
131
+ * @returns The envelope from {@link touch_run}, or the refusal of a bad line.
132
+ */
133
+ export async function builtin_touch(args) {
134
+ return declaredCommand_run(touchCommand, args);
135
+ }
56
136
  /**
57
137
  * Creates empty files or updates timestamps: the shared typed core behind
58
138
  * the parsed builtin and the typed API.
@@ -77,24 +157,25 @@ export async function touch_run(runOptions) {
77
157
  }
78
158
  const wrote = content !== undefined;
79
159
  // Only the first path takes content.
80
- const filesToTouch = wrote ? [pathArgs[0]] : pathArgs;
160
+ const filesToTouch = wrote ? pathArgs.slice(0, 1) : pathArgs;
81
161
  let rendered = '';
82
162
  let renderedErr = '';
83
163
  const outcomes = [];
84
164
  const dispatcher = vfsDispatcher_get();
85
165
  for (const pathArg of filesToTouch) {
86
166
  try {
87
- const targetPath = await path_resolve(pathArg);
167
+ const shown = await path_resolve(pathArg);
168
+ const targetPath = await storePath_resolve(pathArg);
88
169
  const done = await file_touch(dispatcher, targetPath, content);
89
170
  if (done.ok) {
90
- rendered += `${touch_render(targetPath, true, wrote)}\n`;
91
- outcomes.push({ path: targetPath, created: true });
92
- listingCache_get().cache_invalidate?.(path.posix.dirname(targetPath));
171
+ rendered += `${touch_render(shown, true, wrote)}\n`;
172
+ outcomes.push({ path: shown, created: true });
173
+ parentListings_forget(shown, targetPath);
93
174
  }
94
175
  else {
95
- renderedErr += `${chalk.red(`Failed to create file: ${targetPath}`)}\n`;
176
+ renderedErr += `${chalk.red(`Failed to create file: ${shown}`)}\n`;
96
177
  renderedErr += `${chalk.gray(` ${done.reason ?? errno_words(done.errno)}`)}\n`;
97
- outcomes.push({ path: targetPath, created: false });
178
+ outcomes.push({ path: shown, created: false });
98
179
  }
99
180
  }
100
181
  catch (e) {
@@ -112,21 +193,4 @@ export async function touch_run(runOptions) {
112
193
  }
113
194
  return envelope_ok(rendered, model);
114
195
  }
115
- /**
116
- * Creates files from parsed command-line arguments.
117
- *
118
- * @param args - Command line arguments (paths and --withContents flags).
119
- * @returns The envelope from {@link touch_run}.
120
- */
121
- export async function builtin_touch(args) {
122
- const parsed = commandArgs_process(args);
123
- const refusal = optionsUnknown_refusal('touch', parsed, ['withContents', 'withContentsFromFile']);
124
- if (refusal !== null)
125
- return envelope_error('', undefined, `${chalk.red(refusal)}\n`);
126
- return touch_run({
127
- paths: parsed._,
128
- contents: parsed['withContents'] !== undefined ? String(parsed['withContents']) : undefined,
129
- contentsFromFile: parsed['withContentsFromFile'] !== undefined ? String(parsed['withContentsFromFile']) : undefined,
130
- });
131
- }
132
196
  //# sourceMappingURL=touch.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"touch.js","sourceRoot":"","sources":["../../../src/builtins/fs/touch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAc,mBAAmB,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACpG,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAqD,MAAM,cAAc,CAAC;AACtH,OAAO,EAAmB,WAAW,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAkB5E;;;;;GAKG;AACH,SAAS,cAAc,CAAC,aAAqB;IAC3C,IAAI,CAAC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O,CAAC,OAAO,CAAC,CAAC;IAC/F,MAAM,KAAK,GAA2C,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAC3F,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,QAAQ,GAAoB,cAAc,CAAC,QAAQ,EAAE,SAAS,EAAE,WAAW,IAAI,SAAS,CAAC,CAAC;QAChG,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC;QACvB,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,OAAO,WAAW,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AACtC,CAAC"}
@@ -1,16 +1,43 @@
1
1
  import { CommandEnvelope } from '@fnndsc/menu';
2
2
  /**
3
- * Displays a directory tree of the ChRIS filesystem.
4
- * Uses chili's scan_do machinery for recursive filesystem traversal.
5
- *
6
- * @param args - Command line arguments (optional path and flags).
7
- * @returns A Promise that resolves when the tree is displayed.
3
+ * `tree [--follow] [--path] [--dirs] [--dirpath] [path]`: the declaration.
8
4
  *
9
5
  * @example
6
+ * ```ts
7
+ * commands_register({ declarations: [treeCommand] }, 'backend');
10
8
  * ```
11
- * tree # Tree of current directory
12
- * tree /home/user/data # Tree of specific path
13
- * tree --follow # Follow symbolic links
14
- * ```
9
+ */
10
+ export declare const treeCommand: import("../../core/commandDeclaration.js").CommandDeclaration<{
11
+ readonly operands: readonly [{
12
+ readonly name: "path";
13
+ readonly kind: "cfsPath";
14
+ readonly optional: true;
15
+ readonly glob: true;
16
+ readonly summary: "The folder to draw; the working directory when none is given";
17
+ }];
18
+ readonly options: {
19
+ readonly follow: {
20
+ readonly long: "follow";
21
+ readonly summary: "Follow symbolic links when traversing";
22
+ };
23
+ readonly listPaths: {
24
+ readonly long: "path";
25
+ readonly summary: "Emit one full path per entry (grep-friendly, no tree art)";
26
+ };
27
+ readonly dirs: {
28
+ readonly long: "dirs";
29
+ readonly summary: "Show directories only";
30
+ };
31
+ readonly dirpath: {
32
+ readonly long: "dirpath";
33
+ readonly summary: "Emit one full directory path per line";
34
+ };
35
+ };
36
+ }>;
37
+ /**
38
+ * `tree` over words already split: the declaration's parse and handler.
39
+ *
40
+ * @param args - The words after `tree`.
41
+ * @returns The tree, or the refusal of a bad line.
15
42
  */
16
43
  export declare function builtin_tree(args: string[]): Promise<CommandEnvelope>;
@@ -1,9 +1,27 @@
1
1
  /**
2
- * @file Builtin tree command.
3
- * Displays directory structure.
2
+ * @file `tree`: a folder of ChRIS's filesystem (CFS) drawn as a tree, or
3
+ * listed one path per line.
4
+ *
5
+ * Declared in one record (`treeCommand`): one path, and its switches.
6
+ *
7
+ * Key components:
8
+ * - treeCommand: the declaration.
9
+ * - builtin_tree: the declaration run over words already split.
10
+ *
11
+ * Typical usage:
12
+ * ```ts
13
+ * await builtin_tree(['--dirs', '~/feeds']);
14
+ * ```
15
+ *
16
+ * Dependencies: chili's scan for the walk; the listing for whether a path
17
+ * is there.
18
+ *
19
+ * @module
4
20
  */
5
21
  import chalk from 'chalk';
6
- import { commandArgs_process, optionsUnknown_refusal, path_resolve, error_stripDebugPrefix } from '../utils.js';
22
+ import { path_resolve, storePath_resolve, error_stripDebugPrefix } from '../utils.js';
23
+ import { command_declare } from '../../core/commandDeclaration.js';
24
+ import { declaredCommand_run } from '../../core/commandParse.js';
7
25
  import { vfs } from '../../lib/vfs/vfs.js';
8
26
  import { session } from '../../session/index.js';
9
27
  import { spinner } from '../../lib/spinner.js';
@@ -12,55 +30,92 @@ import { bytes_format } from '@fnndsc/chili/commands/fs/upload.js';
12
30
  import { errorStack } from '@fnndsc/fond';
13
31
  import { envelope_ok, envelope_error } from '@fnndsc/menu';
14
32
  import { exitCode_set } from '../../core/handlerRun.js';
15
- /** The options tree reads; any other is refused by name. */
16
- const TREE_OPTIONS = ['follow', 'path', 'dirs', 'dirpath'];
17
33
  /**
18
- * Displays a directory tree of the ChRIS filesystem.
19
- * Uses chili's scan_do machinery for recursive filesystem traversal.
20
- *
21
- * @param args - Command line arguments (optional path and flags).
22
- * @returns A Promise that resolves when the tree is displayed.
34
+ * What a `tree` line may hold. An option it does not have is refused, not
35
+ * skipped: `tree -L 1 x` once scanned a folder named `1`, and
36
+ * `tree --bogus x` the whole home.
37
+ */
38
+ const TREE_GRAMMAR = {
39
+ operands: [
40
+ { name: 'path', kind: 'cfsPath', optional: true, glob: true, summary: 'The folder to draw; the working directory when none is given' },
41
+ ],
42
+ options: {
43
+ follow: { long: 'follow', summary: 'Follow symbolic links when traversing' },
44
+ listPaths: { long: 'path', summary: 'Emit one full path per entry (grep-friendly, no tree art)' },
45
+ dirs: { long: 'dirs', summary: 'Show directories only' },
46
+ dirpath: { long: 'dirpath', summary: 'Emit one full directory path per line' },
47
+ },
48
+ };
49
+ /**
50
+ * `tree [--follow] [--path] [--dirs] [--dirpath] [path]`: the declaration.
23
51
  *
24
52
  * @example
25
- * ```
26
- * tree # Tree of current directory
27
- * tree /home/user/data # Tree of specific path
28
- * tree --follow # Follow symbolic links
53
+ * ```ts
54
+ * commands_register({ declarations: [treeCommand] }, 'backend');
29
55
  * ```
30
56
  */
57
+ export const treeCommand = command_declare({
58
+ name: 'tree',
59
+ grammar: TREE_GRAMMAR,
60
+ help: {
61
+ summary: 'Display directory tree structure',
62
+ description: "Draws a folder of ChRIS's filesystem and everything under it as a tree, with the total size and the number of items; or, with --path or --dirpath, lists one full path per line. The working directory when no path is given.",
63
+ category: 'Navigation',
64
+ posix: { group: 'Files', differs: 'a CFS tree' },
65
+ examples: [
66
+ 'tree # Tree of current directory',
67
+ 'tree /home/user/data # Tree of specific path',
68
+ 'tree --follow # Follow symbolic links',
69
+ 'tree --path # One path per line, no decoration',
70
+ 'tree --dirs # Directory hierarchy only',
71
+ 'tree --dirpath # One directory path per line',
72
+ ],
73
+ },
74
+ holds: [],
75
+ handler: tree_run,
76
+ });
77
+ /**
78
+ * `tree` over words already split: the declaration's parse and handler.
79
+ *
80
+ * @param args - The words after `tree`.
81
+ * @returns The tree, or the refusal of a bad line.
82
+ */
31
83
  export async function builtin_tree(args) {
32
- const parsed = commandArgs_process(args, {
33
- booleanLongOptions: TREE_OPTIONS,
34
- });
35
- // An option tree does not have is refused, not skipped: `tree -L 1 x`
36
- // once scanned a folder named `1`, and `tree --bogus x` the whole home.
37
- const unknown = optionsUnknown_refusal('tree', parsed, TREE_OPTIONS);
38
- if (unknown !== null) {
39
- exitCode_set(1);
40
- return envelope_error('', undefined, `${chalk.red(unknown)}\n`);
41
- }
42
- const pathArgs = parsed._;
43
- const dirpathMode = !!parsed['dirpath'];
44
- const pathMode = !!parsed['path'] || dirpathMode;
45
- const dirsOnly = !!parsed['dirs'] || dirpathMode;
46
- // Determine target path
84
+ return declaredCommand_run(treeCommand, args);
85
+ }
86
+ /**
87
+ * Displays a directory tree of the ChRIS filesystem.
88
+ * Uses chili's scan_do machinery for recursive filesystem traversal.
89
+ *
90
+ * @param args - The line, parsed.
91
+ * @returns The tree and its summary, or why it could not be drawn.
92
+ */
93
+ async function tree_run(args) {
94
+ const pathArg = args.operands.path;
95
+ const dirpathMode = args.options.dirpath;
96
+ const pathMode = args.options.listPaths || dirpathMode;
97
+ const dirsOnly = args.options.dirs || dirpathMode;
98
+ // Read where the store keeps it (a run's data path, a link on the line),
99
+ // and shown as it was asked: the tree's root is the path as typed.
47
100
  let targetPath;
48
- if (pathArgs.length > 0) {
49
- targetPath = await path_resolve(pathArgs[0]);
101
+ let logicalRoot;
102
+ if (pathArg !== undefined) {
103
+ logicalRoot = await path_resolve(pathArg);
104
+ targetPath = await storePath_resolve(pathArg);
50
105
  // A path that is not there is said to be not there, as tree says it,
51
106
  // rather than scanned into an empty tree.
52
107
  const entry = await vfs.data_get(targetPath, { directory: true });
53
108
  if (!entry.ok) {
54
109
  errorStack.stack_pop();
55
110
  exitCode_set(1);
56
- return envelope_error('', undefined, `${chalk.red(`tree: ${pathArgs[0]}: No such file or directory`)}\n`);
111
+ return envelope_error('', undefined, `${chalk.red(`tree: ${pathArg}: No such file or directory`)}\n`);
57
112
  }
58
113
  }
59
114
  // Build scan options
60
115
  const scanOptions = {
61
116
  silent: true,
62
117
  tree: false, // We'll format it ourselves
63
- follow: !!parsed['follow'],
118
+ follow: args.options.follow,
64
119
  dirsOnly,
65
120
  // A named folder is scanned where it stands: the shared directory stays put.
66
121
  ...(targetPath ? { folder: targetPath } : {}),
@@ -78,14 +133,18 @@ export async function builtin_tree(args) {
78
133
  spinner.stop();
79
134
  let rendered = '';
80
135
  if (pathMode) {
81
- // --path: emit one full chrisPath per entry — grep-friendly
136
+ // --path: emit one full path per entry — grep-friendly, under the path asked
82
137
  for (const item of scanResult.fileInfo) {
83
- rendered += `${item.chrisPath}\n`;
138
+ rendered += `${shownPath_derive(item.chrisPath, targetPath, logicalRoot)}\n`;
84
139
  }
85
140
  }
86
141
  else if (scanResult.fileInfo.length === 0) {
87
142
  // An empty folder is its own tree: its name, and nothing under it.
88
- rendered += `${targetPath ?? originalFolder}\n`;
143
+ rendered += `${pathArg ?? originalFolder}\n`;
144
+ }
145
+ else if (targetPath !== undefined && pathArg !== undefined) {
146
+ // The tree hangs from the path as typed, its entries below it.
147
+ rendered += `${treeUnder_render(scanResult.fileInfo, targetPath, pathArg)}\n`;
89
148
  }
90
149
  else {
91
150
  // Default: ASCII tree
@@ -96,4 +155,35 @@ export async function builtin_tree(args) {
96
155
  rendered += `${chalk.gray(`${scanResult.fileInfo.length} items`)}\n`;
97
156
  return envelope_ok(rendered);
98
157
  }
158
+ /**
159
+ * A scanned path as the person asked for it: under the logical root in
160
+ * place of the store folder it was read from.
161
+ *
162
+ * @param chrisPath - The path the scan gave (a store path).
163
+ * @param storeRoot - The store folder scanned, when one was named.
164
+ * @param logicalRoot - The same folder as the session names it.
165
+ * @returns The path to show.
166
+ */
167
+ function shownPath_derive(chrisPath, storeRoot, logicalRoot) {
168
+ if (storeRoot === undefined || logicalRoot === undefined)
169
+ return chrisPath;
170
+ if (chrisPath === storeRoot)
171
+ return logicalRoot;
172
+ return chrisPath.startsWith(`${storeRoot}/`) ? `${logicalRoot}${chrisPath.slice(storeRoot.length)}` : chrisPath;
173
+ }
174
+ /**
175
+ * Draws a scanned folder's tree hanging from the path as typed: its entries
176
+ * relative to the store folder they were read from.
177
+ *
178
+ * @param files - What the scan found.
179
+ * @param storeRoot - The store folder scanned.
180
+ * @param shown - The root's label: the path as typed.
181
+ * @returns The tree.
182
+ */
183
+ function treeUnder_render(files, storeRoot, shown) {
184
+ const under = files.map((file) => (file.chrisPath.startsWith(`${storeRoot}/`) ? { ...file, chrisPath: file.chrisPath.slice(storeRoot.length + 1) } : file));
185
+ // archy draws the root's own label first: an empty line, which the path takes.
186
+ const lines = archyTree_create(under).split('\n');
187
+ return [shown, ...lines.slice(1)].join('\n').replace(/\n+$/, '');
188
+ }
99
189
  //# sourceMappingURL=tree.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tree.js","sourceRoot":"","sources":["../../../src/builtins/fs/tree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAc,mBAAmB,EAAE,sBAAsB,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC5H,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAiC,MAAM,mCAAmC,CAAC;AAC7G,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAmB,WAAW,EAAE,cAAc,EAAoB,MAAM,cAAc,CAAC;AAE9F,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,4DAA4D;AAC5D,MAAM,YAAY,GAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAA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,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CACvH,CAAC,CAAC;IACH,+EAA+E;IAC/E,MAAM,KAAK,GAAa,gBAAgB,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC5D,OAAO,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACnE,CAAC"}
@@ -1,8 +1,27 @@
1
1
  import { type CommandEnvelope } from '@fnndsc/menu';
2
2
  /**
3
- * Uploads a local file or directory to ChRIS.
3
+ * `upload <source> <destination>`: the declaration.
4
4
  *
5
- * @param args - [localPath, remotePath]
6
- * @returns An envelope carrying the upload summary.
5
+ * @example
6
+ * ```ts
7
+ * commands_register({ declarations: [uploadCommand] }, 'backend');
8
+ * ```
9
+ */
10
+ export declare const uploadCommand: import("../../core/commandDeclaration.js").CommandDeclaration<{
11
+ readonly operands: readonly [{
12
+ readonly name: "source";
13
+ readonly kind: "hostPath";
14
+ readonly summary: "What to upload from this machine's disk: a file, a folder, or a wildcard chili matches there";
15
+ }, {
16
+ readonly name: "destination";
17
+ readonly kind: "cfsPath";
18
+ readonly summary: "The ChRIS folder it goes into";
19
+ }];
20
+ }>;
21
+ /**
22
+ * `upload` over words already split: the declaration's parse and handler.
23
+ *
24
+ * @param args - The words after `upload`.
25
+ * @returns The upload summary, or the refusal of a bad line.
7
26
  */
8
27
  export declare function builtin_upload(args: string[]): Promise<CommandEnvelope>;
@@ -1,18 +1,41 @@
1
1
  /**
2
- * @file Builtin upload command.
3
- * Uploads files to ChRIS.
2
+ * @file `upload`: files, folders or the matches of a wildcard on this
3
+ * machine's disk, into ChRIS, with progress.
4
+ *
5
+ * The destination is where the store keeps it (`storePath_resolve`): an
6
+ * upload into a link lands in the folder the link points at.
7
+ *
8
+ * Declared in one record (`uploadCommand`): a host path operand, then one
9
+ * CFS path. The host path is never globbed by the line: chili matches a
10
+ * wildcard in it against the engine's disk.
11
+ *
12
+ * Key components:
13
+ * - uploadCommand: the declaration.
14
+ * - builtin_upload: the declaration run over words already split.
15
+ *
16
+ * Typical usage:
17
+ * ```ts
18
+ * await builtin_upload(['~/data/file.csv', '/home/user/uploads/']);
19
+ * ```
20
+ *
21
+ * Dependencies: chili's transfer, cumin's listing cache, the session's surface.
22
+ *
23
+ * @module
4
24
  */
5
25
  import chalk from 'chalk';
6
- import { path_resolve } from '../utils.js';
26
+ import { path_resolve, storePath_resolve } from '../utils.js';
7
27
  import { files_uploadWithProgress as chefs_upload_cmd, bytes_format } from '@fnndsc/chili/commands/fs/upload.js';
8
28
  import { listCache_get } from '@fnndsc/cumin';
9
29
  import { sink_get } from '../../core/sink.js';
10
- import { shellArguments_pathnameExpansion } from '../../lib/parser.js';
11
30
  import { surface_get } from '../../core/surface.js';
12
31
  import { repl_confirm } from '../../core/question.js';
32
+ import { command_declare } from '../../core/commandDeclaration.js';
33
+ import { declaredCommand_run } from '../../core/commandParse.js';
13
34
  import { errorStack } from '@fnndsc/fond';
14
35
  import { envelope_ok, envelope_error } from '@fnndsc/menu';
15
36
  import { exitCode_set } from '../../core/handlerRun.js';
37
+ /** The characters that make a host path a pattern chili matches against the disk. */
38
+ const HOST_WILDCARD = /[*?[]/;
16
39
  /**
17
40
  * Asks the issuing surface to confirm replacement of an existing CFS target.
18
41
  *
@@ -27,18 +50,54 @@ async function uploadConfirmation_request(message) {
27
50
  throw new Error('Operation cancelled by user.');
28
51
  }
29
52
  }
53
+ /** What an `upload` line may hold: one place on this machine, then one ChRIS path. */
54
+ const UPLOAD_GRAMMAR = {
55
+ operands: [
56
+ { name: 'source', kind: 'hostPath', summary: "What to upload from this machine's disk: a file, a folder, or a wildcard chili matches there" },
57
+ { name: 'destination', kind: 'cfsPath', summary: 'The ChRIS folder it goes into' },
58
+ ],
59
+ };
60
+ /**
61
+ * `upload <source> <destination>`: the declaration.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * commands_register({ declarations: [uploadCommand] }, 'backend');
66
+ * ```
67
+ */
68
+ export const uploadCommand = command_declare({
69
+ name: 'upload',
70
+ grammar: UPLOAD_GRAMMAR,
71
+ help: {
72
+ summary: 'Upload local files, directories, or glob matches to ChRIS',
73
+ description: 'Upload local files, directories, or glob matches to ChRIS with progress tracking. A progress bar shows the file count and percentage complete, the estimated time remaining (ETA) and the data transferred; summary statistics follow the upload.',
74
+ category: 'Files',
75
+ examples: [
76
+ 'upload ~/data/file.csv /home/user/uploads/',
77
+ 'upload ~/Pictures/earthandmoon* .',
78
+ 'upload ./results/ ~/data/',
79
+ 'upload ~/experiment/data /home/user/projects/',
80
+ ],
81
+ },
82
+ handler: async (args) => upload_run(args.operands.source, args.operands.destination),
83
+ });
84
+ /**
85
+ * `upload` over words already split: the declaration's parse and handler.
86
+ *
87
+ * @param args - The words after `upload`.
88
+ * @returns The upload summary, or the refusal of a bad line.
89
+ */
90
+ export async function builtin_upload(args) {
91
+ return declaredCommand_run(uploadCommand, args);
92
+ }
30
93
  /**
31
94
  * Uploads a local file or directory to ChRIS.
32
95
  *
33
- * @param args - [localPath, remotePath]
96
+ * @param localPath - The host path, as typed: a wildcard in it is matched on the engine's disk.
97
+ * @param remotePath - The ChRIS destination, as typed.
34
98
  * @returns An envelope carrying the upload summary.
35
99
  */
36
- export async function builtin_upload(args) {
37
- if (args.length < 2) {
38
- return envelope_ok(`${chalk.red('Usage: upload <local_path> <remote_path>')}\n`);
39
- }
40
- const localPath = args[0];
41
- const remotePath = args[1];
100
+ async function upload_run(localPath, remotePath) {
42
101
  // The local path is read by the ENGINE: under a daemon that is the daemon
43
102
  // host's disk, which belongs to nobody attending the session unless the
44
103
  // operator declared it theirs (--host-control=files). Without that, refuse
@@ -47,8 +106,11 @@ export async function builtin_upload(args) {
47
106
  exitCode_set(1);
48
107
  return envelope_error('', undefined, `${chalk.red("upload: calypso's host disk is nobody's; start calypso with --host-control=files, or upload from a surface that can supply the bytes.")}\n`);
49
108
  }
50
- const localGlob = shellArguments_pathnameExpansion(args, 0);
51
- const targetRemote = await path_resolve(remotePath);
109
+ // chili reads an exact path first and matches a pattern only when nothing
110
+ // stands at it.
111
+ const localGlob = HOST_WILDCARD.test(localPath);
112
+ // Where the store keeps the destination: a link's target, not the link.
113
+ const targetRemote = await storePath_resolve(remotePath);
52
114
  try {
53
115
  const summary = await chefs_upload_cmd(localPath, targetRemote, {
54
116
  expandLocalGlob: localGlob,
@@ -85,8 +147,14 @@ export async function builtin_upload(args) {
85
147
  if (summary.transferredCount > 0) {
86
148
  const listCache = listCache_get();
87
149
  listCache.cache_invalidateTree(summary.actualTargetPath);
88
- // Also invalidate parent to refresh its listing
150
+ // The destination's own listing, by both its names: where the store
151
+ // keeps it, and the path it was reached by.
89
152
  listCache.cache_invalidate(targetRemote);
153
+ listCache.cache_invalidate(await path_resolve(remotePath));
154
+ }
155
+ if (summary.failedCount > 0) {
156
+ exitCode_set(1);
157
+ return envelope_error(rendered, undefined, '');
90
158
  }
91
159
  return envelope_ok(rendered);
92
160
  }