@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.
- package/dist/buildinfo.json +1 -1
- package/dist/builtins/berth/berth.d.ts +90 -3
- package/dist/builtins/berth/berth.js +129 -76
- package/dist/builtins/berth/berth.js.map +1 -1
- package/dist/builtins/berth/berthClose.d.ts +25 -6
- package/dist/builtins/berth/berthClose.js +8 -64
- package/dist/builtins/berth/berthClose.js.map +1 -1
- package/dist/builtins/berth/berthCube.d.ts +3 -2
- package/dist/builtins/berth/berthCube.js +9 -16
- package/dist/builtins/berth/berthCube.js.map +1 -1
- package/dist/builtins/berth/berthProcesses.js +33 -3
- package/dist/builtins/berth/berthProcesses.js.map +1 -1
- package/dist/builtins/debug.d.ts +24 -3
- package/dist/builtins/debug.js +66 -13
- package/dist/builtins/debug.js.map +1 -1
- package/dist/builtins/fs/acl.args.d.ts +5 -38
- package/dist/builtins/fs/acl.args.js +6 -72
- package/dist/builtins/fs/acl.args.js.map +1 -1
- package/dist/builtins/fs/acl.d.ts +100 -10
- package/dist/builtins/fs/acl.js +222 -68
- package/dist/builtins/fs/acl.js.map +1 -1
- package/dist/builtins/fs/cat.args.d.ts +14 -15
- package/dist/builtins/fs/cat.args.js +13 -40
- package/dist/builtins/fs/cat.args.js.map +1 -1
- package/dist/builtins/fs/cat.d.ts +40 -3
- package/dist/builtins/fs/cat.js +92 -13
- package/dist/builtins/fs/cat.js.map +1 -1
- package/dist/builtins/fs/cd.d.ts +24 -6
- package/dist/builtins/fs/cd.js +71 -18
- package/dist/builtins/fs/cd.js.map +1 -1
- package/dist/builtins/fs/configWrite.d.ts +24 -8
- package/dist/builtins/fs/configWrite.js +77 -36
- package/dist/builtins/fs/configWrite.js.map +1 -1
- package/dist/builtins/fs/cp.d.ts +39 -4
- package/dist/builtins/fs/cp.js +122 -56
- package/dist/builtins/fs/cp.js.map +1 -1
- package/dist/builtins/fs/download.d.ts +31 -4
- package/dist/builtins/fs/download.js +75 -38
- package/dist/builtins/fs/download.js.map +1 -1
- package/dist/builtins/fs/du.d.ts +59 -33
- package/dist/builtins/fs/du.js +111 -79
- package/dist/builtins/fs/du.js.map +1 -1
- package/dist/builtins/fs/edit.d.ts +19 -4
- package/dist/builtins/fs/edit.js +77 -16
- package/dist/builtins/fs/edit.js.map +1 -1
- package/dist/builtins/fs/find.d.ts +25 -0
- package/dist/builtins/fs/find.js +76 -5
- package/dist/builtins/fs/find.js.map +1 -1
- package/dist/builtins/fs/ls.d.ts +69 -4
- package/dist/builtins/fs/ls.js +84 -45
- package/dist/builtins/fs/ls.js.map +1 -1
- package/dist/builtins/fs/mkdir.d.ts +28 -18
- package/dist/builtins/fs/mkdir.js +95 -66
- package/dist/builtins/fs/mkdir.js.map +1 -1
- package/dist/builtins/fs/mv.d.ts +34 -4
- package/dist/builtins/fs/mv.js +129 -64
- package/dist/builtins/fs/mv.js.map +1 -1
- package/dist/builtins/fs/pull.args.d.ts +56 -17
- package/dist/builtins/fs/pull.args.js +16 -66
- package/dist/builtins/fs/pull.args.js.map +1 -1
- package/dist/builtins/fs/pull.d.ts +62 -0
- package/dist/builtins/fs/pull.js +123 -31
- package/dist/builtins/fs/pull.js.map +1 -1
- package/dist/builtins/fs/pwd.d.ts +19 -5
- package/dist/builtins/fs/pwd.js +62 -8
- package/dist/builtins/fs/pwd.js.map +1 -1
- package/dist/builtins/fs/rm.d.ts +58 -21
- package/dist/builtins/fs/rm.js +99 -82
- package/dist/builtins/fs/rm.js.map +1 -1
- package/dist/builtins/fs/rmdir.d.ts +29 -11
- package/dist/builtins/fs/rmdir.js +87 -36
- package/dist/builtins/fs/rmdir.js.map +1 -1
- package/dist/builtins/fs/touch.d.ts +44 -9
- package/dist/builtins/fs/touch.js +91 -27
- package/dist/builtins/fs/touch.js.map +1 -1
- package/dist/builtins/fs/tree.d.ts +36 -9
- package/dist/builtins/fs/tree.js +126 -36
- package/dist/builtins/fs/tree.js.map +1 -1
- package/dist/builtins/fs/upload.d.ts +22 -3
- package/dist/builtins/fs/upload.js +82 -14
- package/dist/builtins/fs/upload.js.map +1 -1
- package/dist/builtins/fs/xattr.args.d.ts +12 -33
- package/dist/builtins/fs/xattr.args.js +17 -95
- package/dist/builtins/fs/xattr.args.js.map +1 -1
- package/dist/builtins/fs/xattr.d.ts +98 -8
- package/dist/builtins/fs/xattr.js +163 -24
- package/dist/builtins/fs/xattr.js.map +1 -1
- package/dist/builtins/games/bytes.d.ts +201 -5
- package/dist/builtins/games/bytes.js +255 -54
- package/dist/builtins/games/bytes.js.map +1 -1
- package/dist/builtins/games/chimes.d.ts +180 -3
- package/dist/builtins/games/chimes.js +203 -26
- package/dist/builtins/games/chimes.js.map +1 -1
- package/dist/builtins/games/chrislab.d.ts +101 -3
- package/dist/builtins/games/chrislab.js +117 -17
- package/dist/builtins/games/chrislab.js.map +1 -1
- package/dist/builtins/games/cowsay.d.ts +93 -2
- package/dist/builtins/games/cowsay.js +90 -31
- package/dist/builtins/games/cowsay.js.map +1 -1
- package/dist/builtins/games/figlet.d.ts +70 -2
- package/dist/builtins/games/figlet.js +83 -6
- package/dist/builtins/games/figlet.js.map +1 -1
- package/dist/builtins/games/lab.d.ts +104 -5
- package/dist/builtins/games/lab.js +144 -6
- package/dist/builtins/games/lab.js.map +1 -1
- package/dist/builtins/games/lolcat.d.ts +61 -1
- package/dist/builtins/games/lolcat.js +59 -24
- package/dist/builtins/games/lolcat.js.map +1 -1
- package/dist/builtins/games/morse.d.ts +36 -1
- package/dist/builtins/games/morse.js +50 -2
- package/dist/builtins/games/morse.js.map +1 -1
- package/dist/builtins/games/numbers.d.ts +241 -5
- package/dist/builtins/games/numbers.js +298 -23
- package/dist/builtins/games/numbers.js.map +1 -1
- package/dist/builtins/games/play.d.ts +96 -6
- package/dist/builtins/games/play.js +137 -6
- package/dist/builtins/games/play.js.map +1 -1
- package/dist/builtins/games/qr.d.ts +40 -1
- package/dist/builtins/games/qr.js +51 -2
- package/dist/builtins/games/qr.js.map +1 -1
- package/dist/builtins/games/show.d.ts +131 -6
- package/dist/builtins/games/show.js +208 -20
- package/dist/builtins/games/show.js.map +1 -1
- package/dist/builtins/games/sky.d.ts +178 -4
- package/dist/builtins/games/sky.js +228 -12
- package/dist/builtins/games/sky.js.map +1 -1
- package/dist/builtins/games/text.d.ts +258 -7
- package/dist/builtins/games/text.js +310 -29
- package/dist/builtins/games/text.js.map +1 -1
- package/dist/builtins/games/trek.d.ts +67 -3
- package/dist/builtins/games/trek.js +63 -10
- package/dist/builtins/games/trek.js.map +1 -1
- package/dist/builtins/games/wtf.d.ts +58 -1
- package/dist/builtins/games/wtf.js +67 -6
- package/dist/builtins/games/wtf.js.map +1 -1
- package/dist/builtins/help.d.ts +41 -3
- package/dist/builtins/help.js +92 -796
- package/dist/builtins/help.js.map +1 -1
- package/dist/builtins/net/connect.d.ts +36 -3
- package/dist/builtins/net/connect.js +84 -26
- package/dist/builtins/net/connect.js.map +1 -1
- package/dist/builtins/net/cubepath.d.ts +49 -5
- package/dist/builtins/net/cubepath.js +69 -27
- package/dist/builtins/net/cubepath.js.map +1 -1
- package/dist/builtins/net/logout.d.ts +13 -4
- package/dist/builtins/net/logout.js +49 -3
- package/dist/builtins/net/logout.js.map +1 -1
- package/dist/builtins/net/netstat.d.ts +29 -4
- package/dist/builtins/net/netstat.js +64 -23
- package/dist/builtins/net/netstat.js.map +1 -1
- package/dist/builtins/net/pacs.d.ts +169 -15
- package/dist/builtins/net/pacs.js +92 -33
- package/dist/builtins/net/pacs.js.map +1 -1
- package/dist/builtins/net/query.args.d.ts +95 -0
- package/dist/builtins/net/query.args.js +26 -0
- package/dist/builtins/net/query.args.js.map +1 -0
- package/dist/builtins/net/query.d.ts +98 -5
- package/dist/builtins/net/query.js +89 -83
- package/dist/builtins/net/query.js.map +1 -1
- package/dist/builtins/net/status.d.ts +5 -3
- package/dist/builtins/net/status.js +5 -12
- package/dist/builtins/net/status.js.map +1 -1
- package/dist/builtins/parametersofplugin.d.ts +82 -3
- package/dist/builtins/parametersofplugin.js +79 -23
- package/dist/builtins/parametersofplugin.js.map +1 -1
- package/dist/builtins/proc.d.ts +210 -3
- package/dist/builtins/proc.js +210 -119
- package/dist/builtins/proc.js.map +1 -1
- package/dist/builtins/res/compute.d.ts +67 -3
- package/dist/builtins/res/compute.js +121 -35
- package/dist/builtins/res/compute.js.map +1 -1
- package/dist/builtins/res/dicom.d.ts +55 -7
- package/dist/builtins/res/dicom.js +86 -52
- package/dist/builtins/res/dicom.js.map +1 -1
- package/dist/builtins/res/expect.d.ts +52 -3
- package/dist/builtins/res/expect.js +92 -29
- package/dist/builtins/res/expect.js.map +1 -1
- package/dist/builtins/res/feed.d.ts +475 -3
- package/dist/builtins/res/feed.js +253 -158
- package/dist/builtins/res/feed.js.map +1 -1
- package/dist/builtins/res/files.d.ts +517 -3
- package/dist/builtins/res/files.js +124 -44
- package/dist/builtins/res/files.js.map +1 -1
- package/dist/builtins/res/gather.d.ts +113 -3
- package/dist/builtins/res/gather.js +153 -44
- package/dist/builtins/res/gather.js.map +1 -1
- package/dist/builtins/res/gather.process.d.ts +27 -19
- package/dist/builtins/res/gather.process.js +29 -59
- package/dist/builtins/res/gather.process.js.map +1 -1
- package/dist/builtins/res/group.d.ts +284 -3
- package/dist/builtins/res/group.js +147 -76
- package/dist/builtins/res/group.js.map +1 -1
- package/dist/builtins/res/image.d.ts +30 -2
- package/dist/builtins/res/image.js +62 -10
- package/dist/builtins/res/image.js.map +1 -1
- package/dist/builtins/res/play.d.ts +71 -9
- package/dist/builtins/res/play.js +124 -82
- package/dist/builtins/res/play.js.map +1 -1
- package/dist/builtins/res/plugininstance.d.ts +307 -2
- package/dist/builtins/res/plugininstance.js +122 -50
- package/dist/builtins/res/plugininstance.js.map +1 -1
- package/dist/builtins/res/pluginmeta.d.ts +244 -2
- package/dist/builtins/res/pluginmeta.js +98 -40
- package/dist/builtins/res/pluginmeta.js.map +1 -1
- package/dist/builtins/res/record.d.ts +37 -3
- package/dist/builtins/res/record.js +127 -57
- package/dist/builtins/res/record.js.map +1 -1
- package/dist/builtins/res/resourceList.d.ts +136 -0
- package/dist/builtins/res/resourceList.js +51 -0
- package/dist/builtins/res/resourceList.js.map +1 -0
- package/dist/builtins/res/tag.d.ts +244 -3
- package/dist/builtins/res/tag.js +97 -41
- package/dist/builtins/res/tag.js.map +1 -1
- package/dist/builtins/res/user.d.ts +122 -3
- package/dist/builtins/res/user.js +83 -21
- package/dist/builtins/res/user.js.map +1 -1
- package/dist/builtins/res/workflow.d.ts +244 -2
- package/dist/builtins/res/workflow.js +97 -40
- package/dist/builtins/res/workflow.js.map +1 -1
- package/dist/builtins/store.d.ts +85 -3
- package/dist/builtins/store.js +135 -68
- package/dist/builtins/store.js.map +1 -1
- package/dist/builtins/sys/apropos.d.ts +80 -5
- package/dist/builtins/sys/apropos.js +121 -15
- package/dist/builtins/sys/apropos.js.map +1 -1
- package/dist/builtins/sys/cal.d.ts +44 -5
- package/dist/builtins/sys/cal.js +57 -10
- package/dist/builtins/sys/cal.js.map +1 -1
- package/dist/builtins/sys/command.d.ts +20 -0
- package/dist/builtins/sys/command.js +31 -0
- package/dist/builtins/sys/command.js.map +1 -1
- package/dist/builtins/sys/context.d.ts +13 -3
- package/dist/builtins/sys/context.js +51 -4
- package/dist/builtins/sys/context.js.map +1 -1
- package/dist/builtins/sys/date.d.ts +56 -5
- package/dist/builtins/sys/date.js +63 -9
- package/dist/builtins/sys/date.js.map +1 -1
- package/dist/builtins/sys/echo.d.ts +63 -2
- package/dist/builtins/sys/echo.js +87 -8
- package/dist/builtins/sys/echo.js.map +1 -1
- package/dist/builtins/sys/fortune.d.ts +27 -2
- package/dist/builtins/sys/fortune.js +44 -2
- package/dist/builtins/sys/fortune.js.map +1 -1
- package/dist/builtins/sys/grep.d.ts +245 -11
- package/dist/builtins/sys/grep.js +418 -131
- package/dist/builtins/sys/grep.js.map +1 -1
- package/dist/builtins/sys/joblets.d.ts +66 -7
- package/dist/builtins/sys/joblets.js +101 -14
- package/dist/builtins/sys/joblets.js.map +1 -1
- package/dist/builtins/sys/motd.d.ts +37 -3
- package/dist/builtins/sys/motd.js +49 -8
- package/dist/builtins/sys/motd.js.map +1 -1
- package/dist/builtins/sys/notes.d.ts +75 -3
- package/dist/builtins/sys/notes.js +90 -29
- package/dist/builtins/sys/notes.js.map +1 -1
- package/dist/builtins/sys/physicalmode.d.ts +24 -3
- package/dist/builtins/sys/physicalmode.js +68 -14
- package/dist/builtins/sys/physicalmode.js.map +1 -1
- package/dist/builtins/sys/tasks.d.ts +74 -5
- package/dist/builtins/sys/tasks.js +102 -14
- package/dist/builtins/sys/tasks.js.map +1 -1
- package/dist/builtins/sys/textFilters.d.ts +673 -41
- package/dist/builtins/sys/textFilters.js +719 -264
- package/dist/builtins/sys/textFilters.js.map +1 -1
- package/dist/builtins/sys/timing.d.ts +24 -3
- package/dist/builtins/sys/timing.js +67 -14
- package/dist/builtins/sys/timing.js.map +1 -1
- package/dist/builtins/sys/variables.d.ts +70 -4
- package/dist/builtins/sys/variables.js +103 -31
- package/dist/builtins/sys/variables.js.map +1 -1
- package/dist/builtins/sys/version.d.ts +27 -2
- package/dist/builtins/sys/version.js +48 -3
- package/dist/builtins/sys/version.js.map +1 -1
- package/dist/builtins/sys/weather.d.ts +92 -15
- package/dist/builtins/sys/weather.js +71 -45
- package/dist/builtins/sys/weather.js.map +1 -1
- package/dist/builtins/sys/whoami.d.ts +38 -18
- package/dist/builtins/sys/whoami.js +112 -8
- package/dist/builtins/sys/whoami.js.map +1 -1
- package/dist/builtins/utils.d.ts +1 -38
- package/dist/builtins/utils.js +1 -87
- package/dist/builtins/utils.js.map +1 -1
- package/dist/chris/backend.js +2 -0
- package/dist/chris/backend.js.map +1 -1
- package/dist/chris/chrisCommands.js +62 -159
- package/dist/chris/chrisCommands.js.map +1 -1
- package/dist/chris/commandFallback.d.ts +12 -0
- package/dist/chris/commandFallback.js +47 -0
- package/dist/chris/commandFallback.js.map +1 -1
- package/dist/chris/files.js +24 -85
- package/dist/chris/files.js.map +1 -1
- package/dist/chris/filesystem.js +7 -5
- package/dist/chris/filesystem.js.map +1 -1
- package/dist/chris/help.js +0 -1082
- package/dist/chris/help.js.map +1 -1
- package/dist/chris/kinds.d.ts +30 -0
- package/dist/chris/kinds.js +154 -0
- package/dist/chris/kinds.js.map +1 -0
- package/dist/chris/mounts.d.ts +4 -4
- package/dist/chris/mounts.js +9 -16
- package/dist/chris/mounts.js.map +1 -1
- package/dist/chris/navigation.d.ts +2 -3
- package/dist/chris/navigation.js +6 -20
- package/dist/chris/navigation.js.map +1 -1
- package/dist/chris/pacsResources.d.ts +259 -0
- package/dist/chris/pacsResources.js +168 -0
- package/dist/chris/pacsResources.js.map +1 -0
- package/dist/chris/promptContext.d.ts +6 -0
- package/dist/chris/promptContext.js +3 -1
- package/dist/chris/promptContext.js.map +1 -1
- package/dist/core/argumentKinds.d.ts +107 -0
- package/dist/core/argumentKinds.js +223 -0
- package/dist/core/argumentKinds.js.map +1 -0
- package/dist/core/backend.d.ts +4 -1
- package/dist/core/backend.js.map +1 -1
- package/dist/core/commandDeclaration.d.ts +453 -0
- package/dist/core/commandDeclaration.js +52 -0
- package/dist/core/commandDeclaration.js.map +1 -0
- package/dist/core/commandParse.d.ts +64 -0
- package/dist/core/commandParse.js +468 -0
- package/dist/core/commandParse.js.map +1 -0
- package/dist/core/commandRegistry.d.ts +37 -0
- package/dist/core/commandRegistry.js +100 -3
- package/dist/core/commandRegistry.js.map +1 -1
- package/dist/core/commandSchema.d.ts +32 -0
- package/dist/core/commandSchema.js +117 -0
- package/dist/core/commandSchema.js.map +1 -0
- package/dist/core/commandUsage.d.ts +62 -0
- package/dist/core/commandUsage.js +247 -0
- package/dist/core/commandUsage.js.map +1 -0
- package/dist/core/coreCommands.js +66 -214
- package/dist/core/coreCommands.js.map +1 -1
- package/dist/core/dispatch.js +15 -8
- package/dist/core/dispatch.js.map +1 -1
- package/dist/core/paths.d.ts +51 -0
- package/dist/core/paths.js +86 -2
- package/dist/core/paths.js.map +1 -1
- package/dist/core/preprocess.d.ts +10 -9
- package/dist/core/preprocess.js +10 -20
- package/dist/core/preprocess.js.map +1 -1
- package/dist/core/warmupFailures.d.ts +34 -2
- package/dist/core/warmupFailures.js +43 -2
- package/dist/core/warmupFailures.js.map +1 -1
- package/dist/lib/completer/cfsPaths.d.ts +14 -0
- package/dist/lib/completer/cfsPaths.js +91 -0
- package/dist/lib/completer/cfsPaths.js.map +1 -0
- package/dist/lib/completer/declared.d.ts +15 -0
- package/dist/lib/completer/declared.js +189 -0
- package/dist/lib/completer/declared.js.map +1 -0
- package/dist/lib/completer/index.js +33 -79
- package/dist/lib/completer/index.js.map +1 -1
- package/dist/lib/parser.d.ts +5 -8
- package/dist/lib/parser.js +2 -11
- package/dist/lib/parser.js.map +1 -1
- package/dist/lib/vfs/vfs.d.ts +2 -1
- package/dist/lib/vfs/vfs.js +9 -6
- package/dist/lib/vfs/vfs.js.map +1 -1
- package/dist/lib/wildcard.js +2 -3
- package/dist/lib/wildcard.js.map +1 -1
- package/dist/notes.json +1 -1
- package/package.json +6 -5
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import { commandAliases_list, declaration_isParsed } from './commandDeclaration.js';
|
|
2
|
+
import { declaredHandler_make } from './commandParse.js';
|
|
3
|
+
import { declarationHelp_derive } from './commandUsage.js';
|
|
1
4
|
/** The names the core registered, which no backend may take. */
|
|
2
5
|
const coreNames = new Set();
|
|
3
6
|
const envelopeHandlers = {};
|
|
4
7
|
const plainHandlers = {};
|
|
5
8
|
const helpEntries = {};
|
|
6
9
|
const holdsEntries = new Map();
|
|
10
|
+
const declarationEntries = new Map();
|
|
11
|
+
/** Each alias of a declared command, to its declaration. */
|
|
12
|
+
const aliasEntries = new Map();
|
|
7
13
|
/** The listing order, by kind; empty until set. */
|
|
8
14
|
const listingOrder = { envelope: [], plain: [], help: [] };
|
|
9
15
|
/**
|
|
@@ -56,14 +62,15 @@ function names_ordered(record, order) {
|
|
|
56
62
|
* @throws {Error} When a backend's group names a core command.
|
|
57
63
|
*/
|
|
58
64
|
export function commands_register(group, owner = 'core') {
|
|
65
|
+
const declared = (group.declarations ?? []).flatMap((declaration) => [declaration.name, ...declarationAliases_list(declaration).map((alias) => alias.name)]);
|
|
66
|
+
const names = [...Object.keys(group.envelope ?? {}), ...Object.keys(group.plain ?? {}), ...declared];
|
|
59
67
|
if (owner === 'backend') {
|
|
60
|
-
const taken =
|
|
61
|
-
.filter((name) => coreNames.has(name));
|
|
68
|
+
const taken = names.filter((name) => coreNames.has(name));
|
|
62
69
|
if (taken.length > 0)
|
|
63
70
|
throw new Error(`a backend cannot replace the core's commands: ${[...new Set(taken)].join(', ')}`);
|
|
64
71
|
}
|
|
65
72
|
else {
|
|
66
|
-
for (const name of
|
|
73
|
+
for (const name of names)
|
|
67
74
|
coreNames.add(name);
|
|
68
75
|
}
|
|
69
76
|
if (group.envelope !== undefined)
|
|
@@ -74,6 +81,96 @@ export function commands_register(group, owner = 'core') {
|
|
|
74
81
|
Object.assign(helpEntries, group.help);
|
|
75
82
|
for (const [name, pieces] of Object.entries(group.holds ?? {}))
|
|
76
83
|
holdsEntries.set(name, pieces);
|
|
84
|
+
for (const declaration of group.declarations ?? [])
|
|
85
|
+
declaration_register(declaration);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The command under each of its other words, as the registry answers them.
|
|
89
|
+
*
|
|
90
|
+
* @param declaration - The command's declaration.
|
|
91
|
+
* @returns One record per alias; none for a command without any.
|
|
92
|
+
*/
|
|
93
|
+
function declarationAliases_list(declaration) {
|
|
94
|
+
return commandAliases_list(declaration);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Registers one declared command: its name answered by a handler that parses
|
|
98
|
+
* the line against the grammar (an expression grammar's handler takes the
|
|
99
|
+
* words), its help generated from the record, and what it holds. Each alias
|
|
100
|
+
* is registered the same way under its own word, so its usage and refusals
|
|
101
|
+
* say the word typed; the command alone is listed among the declarations,
|
|
102
|
+
* which the schema reads.
|
|
103
|
+
*
|
|
104
|
+
* @param declaration - The command's declaration.
|
|
105
|
+
*/
|
|
106
|
+
function declaration_register(declaration) {
|
|
107
|
+
declarationEntries.set(declaration.name, declaration);
|
|
108
|
+
declaredName_register(declaration);
|
|
109
|
+
for (const alias of declarationAliases_list(declaration)) {
|
|
110
|
+
aliasEntries.set(alias.name, alias);
|
|
111
|
+
declaredName_register(alias);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Answers one word of a declared command: its handlers, its help entry and
|
|
116
|
+
* what it holds.
|
|
117
|
+
*
|
|
118
|
+
* @param declaration - The command, named as the word.
|
|
119
|
+
*/
|
|
120
|
+
function declaredName_register(declaration) {
|
|
121
|
+
const handler = declaration_isParsed(declaration)
|
|
122
|
+
? declaredHandler_make(declaration)
|
|
123
|
+
: (args) => declaration.handler(args);
|
|
124
|
+
envelopeHandlers[declaration.name] = handler;
|
|
125
|
+
// The plain form delivers what the handler answers, as envelopeHandler_wrap
|
|
126
|
+
// does; the sink is loaded when it runs, so the registry loads no output path.
|
|
127
|
+
plainHandlers[declaration.name] = async (args) => {
|
|
128
|
+
const envelope = await handler(args);
|
|
129
|
+
if (envelope === undefined)
|
|
130
|
+
return;
|
|
131
|
+
const { envelope_deliver } = await import('./sink.js');
|
|
132
|
+
envelope_deliver(envelope);
|
|
133
|
+
};
|
|
134
|
+
helpEntries[declaration.name] = declaration_isParsed(declaration)
|
|
135
|
+
? declarationHelp_derive(declaration)
|
|
136
|
+
: {
|
|
137
|
+
usage: declaration.help.usage,
|
|
138
|
+
summary: declaration.help.summary,
|
|
139
|
+
description: declaration.help.description,
|
|
140
|
+
...(declaration.help.category !== undefined ? { category: declaration.help.category } : {}),
|
|
141
|
+
...(declaration.help.posix !== undefined ? { posix: { ...declaration.help.posix } } : {}),
|
|
142
|
+
...(declaration.help.examples !== undefined ? { examples: [...declaration.help.examples] } : {}),
|
|
143
|
+
};
|
|
144
|
+
if (declaration.holds !== undefined)
|
|
145
|
+
holdsEntries.set(declaration.name, declaration.holds);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* A command's declaration, when it has one, by its name or an alias.
|
|
149
|
+
*
|
|
150
|
+
* @param name - The command name, or an alias of it (`feeds`).
|
|
151
|
+
* @returns The declaration (an alias's named as the alias), or undefined for a command not yet declared in one record.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* commandDeclaration_get('ls')?.grammar;
|
|
156
|
+
* commandDeclaration_get('feeds')?.name; // 'feeds', the feed command under that word
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
export function commandDeclaration_get(name) {
|
|
160
|
+
return declarationEntries.get(name) ?? aliasEntries.get(name);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Every declared command, in registration order.
|
|
164
|
+
*
|
|
165
|
+
* @returns The declarations.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* commandDeclarations_list().map((declaration) => declaration.name);
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export function commandDeclarations_list() {
|
|
173
|
+
return [...declarationEntries.values()];
|
|
77
174
|
}
|
|
78
175
|
/**
|
|
79
176
|
* What a command holds of the session while it runs.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandRegistry.js","sourceRoot":"","sources":["../../src/core/commandRegistry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"commandRegistry.js","sourceRoot":"","sources":["../../src/core/commandRegistry.ts"],"names":[],"mappings":"AAiCA,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAA8B,MAAM,yBAAyB,CAAC;AAChH,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAgE3D,gEAAgE;AAChE,MAAM,SA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,CAAC;AAChE,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,kBAAkB;IAChC,OAAO,aAAa,CAAC,aAAa,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAC/C,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED,0GAA0G;AAC1G,MAAM,UAAU,eAAe;IAC7B,OAAO,aAAa,CAAC,WAAW,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CommandDeclaration } from './commandDeclaration.js';
|
|
2
|
+
/**
|
|
3
|
+
* One tool: a command, or one of its subcommands, as an assistant calls it.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const tool: CommandTool = { name: 'ls', description: 'List directory contents', inputSchema: { type: 'object' } };
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export interface CommandTool {
|
|
11
|
+
/** The command's name, and the subcommand's after an underscore (`berth_anchor`). */
|
|
12
|
+
readonly name: string;
|
|
13
|
+
/** What it does: the command's summary, or the subcommand's. */
|
|
14
|
+
readonly description: string;
|
|
15
|
+
/** The JSON Schema of its input: an object of its operands and options. */
|
|
16
|
+
readonly inputSchema: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A declared command's tools: the command itself (when it runs bare, or
|
|
20
|
+
* has no subcommands), and each subcommand, with the command's options
|
|
21
|
+
* beside the subcommand's own.
|
|
22
|
+
*
|
|
23
|
+
* @param declaration - The command.
|
|
24
|
+
* @returns The tools, the bare command's first.
|
|
25
|
+
* @throws {Error} For a kind no one registered, or an operand and an option of one name.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* commandTools_derive(lsCommand)[0]?.inputSchema; // { type: 'object', properties: { paths: …, long: … }, … }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function commandTools_derive(declaration: CommandDeclaration): CommandTool[];
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file A declared command as tools: one JSON Schema per command and per
|
|
3
|
+
* subcommand, whose properties are the operands and options the grammar
|
|
4
|
+
* declares, each typed by its kind. A pure function of the declaration, so
|
|
5
|
+
* what an assistant may call is exactly what the shell parses.
|
|
6
|
+
*
|
|
7
|
+
* Key components:
|
|
8
|
+
* - CommandTool: one tool, its name, description and input schema.
|
|
9
|
+
* - commandTools_derive: the tools of a declaration.
|
|
10
|
+
*
|
|
11
|
+
* Typical usage:
|
|
12
|
+
* ```ts
|
|
13
|
+
* const tools: CommandTool[] = commandTools_derive(berthCommand);
|
|
14
|
+
* tools.map((tool) => tool.name); // ['berth', 'berth_anchor', 'berth_close', 'berth_drop', 'berth_clear']
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Dependencies: zod, which writes the JSON Schema; the argument kinds, which
|
|
18
|
+
* give each value's schema.
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
import { z } from 'zod';
|
|
23
|
+
import { argumentKind_get } from './argumentKinds.js';
|
|
24
|
+
/**
|
|
25
|
+
* The schema of one argument's value, by its kind.
|
|
26
|
+
*
|
|
27
|
+
* @param argument - The argument.
|
|
28
|
+
* @param summary - What it is, for the schema's description.
|
|
29
|
+
* @returns The schema.
|
|
30
|
+
* @throws {Error} For a kind no one registered.
|
|
31
|
+
*/
|
|
32
|
+
function argument_schema(argument, summary) {
|
|
33
|
+
const kind = argumentKind_get(argument.kind);
|
|
34
|
+
if (kind === null)
|
|
35
|
+
throw new Error(`no argument kind ${argument.kind}`);
|
|
36
|
+
return kind.schema_make(argument).describe(summary);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The input schema of one stretch: each operand (a list when it repeats,
|
|
40
|
+
* required unless optional) and each option (a switch a boolean, a value
|
|
41
|
+
* option its value or its list of values), all as properties of one object.
|
|
42
|
+
*
|
|
43
|
+
* @param grammar - The stretch.
|
|
44
|
+
* @returns The zod object.
|
|
45
|
+
* @throws {Error} For an operand and an option of one name.
|
|
46
|
+
*/
|
|
47
|
+
function toolInput_make(grammar) {
|
|
48
|
+
const shape = {};
|
|
49
|
+
for (const operand of grammar.operands) {
|
|
50
|
+
const value = argument_schema(operand, operand.summary);
|
|
51
|
+
const schema = operand.repeat === true
|
|
52
|
+
? z.array(value).min(operand.optional === true ? 0 : 1).describe(operand.summary)
|
|
53
|
+
: value;
|
|
54
|
+
shape[operand.name] = operand.optional === true ? schema.optional() : schema;
|
|
55
|
+
}
|
|
56
|
+
for (const [key, option] of Object.entries(grammar.options)) {
|
|
57
|
+
if (Object.hasOwn(shape, key))
|
|
58
|
+
throw new Error(`${key} names an operand and an option`);
|
|
59
|
+
shape[key] = optionValue_schema(option).optional();
|
|
60
|
+
}
|
|
61
|
+
return z.object(shape).strict();
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* One option's value schema: a boolean for a switch, else its value's kind,
|
|
65
|
+
* a list of them when it repeats.
|
|
66
|
+
*
|
|
67
|
+
* @param option - The option.
|
|
68
|
+
* @returns The schema.
|
|
69
|
+
*/
|
|
70
|
+
function optionValue_schema(option) {
|
|
71
|
+
if (option.value === undefined)
|
|
72
|
+
return z.boolean().describe(option.summary);
|
|
73
|
+
const value = argument_schema(option.value, option.summary);
|
|
74
|
+
if (option.repeat === true)
|
|
75
|
+
return z.array(value).describe(option.summary);
|
|
76
|
+
// One that asks takes null for "ask me".
|
|
77
|
+
return option.asks === true ? value.nullable() : value;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* One tool, its schema written by zod.
|
|
81
|
+
*
|
|
82
|
+
* @param name - The tool's name.
|
|
83
|
+
* @param description - What it does.
|
|
84
|
+
* @param grammar - Its stretch of the line.
|
|
85
|
+
* @returns The tool.
|
|
86
|
+
*/
|
|
87
|
+
function tool_make(name, description, grammar) {
|
|
88
|
+
return { name, description, inputSchema: z.toJSONSchema(toolInput_make(grammar)) };
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* A declared command's tools: the command itself (when it runs bare, or
|
|
92
|
+
* has no subcommands), and each subcommand, with the command's options
|
|
93
|
+
* beside the subcommand's own.
|
|
94
|
+
*
|
|
95
|
+
* @param declaration - The command.
|
|
96
|
+
* @returns The tools, the bare command's first.
|
|
97
|
+
* @throws {Error} For a kind no one registered, or an operand and an option of one name.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* commandTools_derive(lsCommand)[0]?.inputSchema; // { type: 'object', properties: { paths: …, long: … }, … }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export function commandTools_derive(declaration) {
|
|
105
|
+
const grammar = declaration.grammar;
|
|
106
|
+
const own = grammar.options ?? {};
|
|
107
|
+
const tools = [];
|
|
108
|
+
if (grammar.subcommands === undefined || grammar.bare !== undefined) {
|
|
109
|
+
const description = grammar.subcommands === undefined ? declaration.help.summary : (grammar.bare?.summary ?? declaration.help.summary);
|
|
110
|
+
tools.push(tool_make(declaration.name, description, { operands: grammar.operands ?? [], options: { ...own, ...(grammar.bare?.options ?? {}) } }));
|
|
111
|
+
}
|
|
112
|
+
for (const [word, sub] of Object.entries(grammar.subcommands ?? {})) {
|
|
113
|
+
tools.push(tool_make(`${declaration.name}_${word}`, sub.summary, { operands: sub.operands ?? [], options: { ...own, ...(sub.options ?? {}) } }));
|
|
114
|
+
}
|
|
115
|
+
return tools;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=commandSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandSchema.js","sourceRoot":"","sources":["../../src/core/commandSchema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,E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ClD,MAAM,KAAK,GAAkB,EAAE,CAAC;IAChC,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QACpE,MAAM,WAAW,GAAW,OAAO,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/I,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,EAAE,EAAE,OAAO,EAAE,EAAE,GAAG,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IACpJ,CAAC;IACD,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,IAAI,EAAE,CAAuC,EAAE,CAAC;QAC1G,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,WAAW,CAAC,IAAI,IAAI,IAAI,EAAE,EAAE,GAAG,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,IAAI,EAAE,EAAE,OAAO,EAAE,EAAE,GAAG,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IACnJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file A declared command's usage line and help page, generated from its
|
|
3
|
+
* grammar: the usage `help` shows and every refusal ends with, and the help
|
|
4
|
+
* record `help`, `/bin` and the listings read.
|
|
5
|
+
*
|
|
6
|
+
* Key components:
|
|
7
|
+
* - commandUsage_render: the usage line of a command or one of its subcommands.
|
|
8
|
+
* - declarationHelp_derive: the help record of a declared command.
|
|
9
|
+
*
|
|
10
|
+
* Typical usage:
|
|
11
|
+
* ```ts
|
|
12
|
+
* commandUsage_render(lsCommand); // 'ls [-l1hrdfaA] [--sort <field>] [path…]'
|
|
13
|
+
* const help: CommandHelp = declarationHelp_derive(berthCommand);
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Dependencies: the declaration types and the registry's help record.
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/
|
|
20
|
+
import type { CommandHelp } from './commandRegistry.js';
|
|
21
|
+
import type { CommandDeclaration } from './commandDeclaration.js';
|
|
22
|
+
/**
|
|
23
|
+
* A command's usage line, or one subcommand's.
|
|
24
|
+
*
|
|
25
|
+
* @param declaration - The command.
|
|
26
|
+
* @param subcommand - The subcommand, or none for the whole command.
|
|
27
|
+
* @returns The line, starting with the command's name.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* commandUsage_render(berthCommand, 'drop'); // 'berth drop <name>'
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function commandUsage_render(declaration: CommandDeclaration, subcommand?: string | null): string;
|
|
35
|
+
/**
|
|
36
|
+
* The help record of a declared command: the usage its grammar generates,
|
|
37
|
+
* its subcommands, operands and options with their summaries, and its prose.
|
|
38
|
+
*
|
|
39
|
+
* @param declaration - The command.
|
|
40
|
+
* @returns The record `help` renders and the listings read.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* declarationHelp_derive(lsCommand).usage; // 'ls [-l1hrdfaA] [--sort <field>] [path…]'
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function declarationHelp_derive(declaration: CommandDeclaration): CommandHelp;
|
|
48
|
+
/**
|
|
49
|
+
* The help record of one subcommand of a declared command (`help pacs
|
|
50
|
+
* query`): its usage, its summary, and its operands and options with the
|
|
51
|
+
* command's own beside them; the command's examples that run it.
|
|
52
|
+
*
|
|
53
|
+
* @param declaration - The command.
|
|
54
|
+
* @param subcommand - The subcommand's word.
|
|
55
|
+
* @returns The record, or undefined when the command has no such subcommand.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* subcommandHelp_derive(berthCommand, 'drop')?.usage; // 'berth drop <name>'
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function subcommandHelp_derive(declaration: CommandDeclaration, subcommand: string): CommandHelp | undefined;
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/** The gap between a help line's left column and its summary. */
|
|
2
|
+
const COLUMN_GAP = 2;
|
|
3
|
+
/**
|
|
4
|
+
* One operand as usage writes it: `<path>`, `[name]`, `<source>…`, `[path…]`.
|
|
5
|
+
*
|
|
6
|
+
* @param operand - The operand.
|
|
7
|
+
* @returns Its word.
|
|
8
|
+
*/
|
|
9
|
+
function operand_usage(operand) {
|
|
10
|
+
const word = `${operand.name}${operand.repeat === true ? '…' : ''}`;
|
|
11
|
+
return operand.optional === true ? `[${word}]` : `<${word}>`;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* One option's name as help writes it: `-l, --long`, `-l`, `--sort <field>`.
|
|
15
|
+
*
|
|
16
|
+
* @param option - The option.
|
|
17
|
+
* @returns Its names, with its value's word.
|
|
18
|
+
*/
|
|
19
|
+
function optionNames_render(option) {
|
|
20
|
+
const names = [];
|
|
21
|
+
if (option.short !== undefined)
|
|
22
|
+
names.push(`-${option.short}`);
|
|
23
|
+
if (option.long !== undefined)
|
|
24
|
+
names.push(`--${option.long}`);
|
|
25
|
+
return `${names.join(', ')}${optionValue_render(option)}`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* An option's value as usage writes it: ` <field>`, `[=<language>]` for one
|
|
29
|
+
* that may be left out, ` [<file>]` for one that asks when it has none,
|
|
30
|
+
* nothing for a switch.
|
|
31
|
+
*
|
|
32
|
+
* @param option - The option.
|
|
33
|
+
* @returns The value's words.
|
|
34
|
+
*/
|
|
35
|
+
function optionValue_render(option) {
|
|
36
|
+
if (option.value === undefined)
|
|
37
|
+
return '';
|
|
38
|
+
if (option.value.optional === true)
|
|
39
|
+
return `[=<${option.value.name}>]`;
|
|
40
|
+
return option.asks === true ? ` [<${option.value.name}>]` : ` <${option.value.name}>`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The options and operands of one stretch of a line, as usage writes them:
|
|
44
|
+
* the one-letter switches bundled, the long-only switches, the options that
|
|
45
|
+
* take a value, then the operands.
|
|
46
|
+
*
|
|
47
|
+
* @param line - The stretch's grammar.
|
|
48
|
+
* @returns Its words, joined by spaces; empty when it takes nothing.
|
|
49
|
+
*/
|
|
50
|
+
function lineTail_render(line) {
|
|
51
|
+
const options = Object.values(line.options ?? {});
|
|
52
|
+
const shortSwitches = options
|
|
53
|
+
.filter((option) => option.value === undefined && option.short !== undefined)
|
|
54
|
+
.map((option) => option.short)
|
|
55
|
+
.join('');
|
|
56
|
+
const parts = [];
|
|
57
|
+
if (shortSwitches !== '')
|
|
58
|
+
parts.push(`[-${shortSwitches}]`);
|
|
59
|
+
for (const option of options) {
|
|
60
|
+
if (option.value === undefined && option.short === undefined && option.long !== undefined)
|
|
61
|
+
parts.push(`[--${option.long}]`);
|
|
62
|
+
}
|
|
63
|
+
for (const option of options) {
|
|
64
|
+
if (option.value === undefined)
|
|
65
|
+
continue;
|
|
66
|
+
const name = option.long !== undefined ? `--${option.long}` : `-${option.short ?? ''}`;
|
|
67
|
+
parts.push(`[${name}${optionValue_render(option)}]`);
|
|
68
|
+
}
|
|
69
|
+
for (const operand of line.operands ?? [])
|
|
70
|
+
parts.push(operand_usage(operand));
|
|
71
|
+
return parts.join(' ');
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Joins a head and a tail with a space, or gives the head alone.
|
|
75
|
+
*
|
|
76
|
+
* @param head - The words before.
|
|
77
|
+
* @param tail - The words after, perhaps none.
|
|
78
|
+
* @returns The line.
|
|
79
|
+
*/
|
|
80
|
+
function words_join(head, tail) {
|
|
81
|
+
return tail === '' ? head : `${head} ${tail}`;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* A command's usage line, or one subcommand's.
|
|
85
|
+
*
|
|
86
|
+
* @param declaration - The command.
|
|
87
|
+
* @param subcommand - The subcommand, or none for the whole command.
|
|
88
|
+
* @returns The line, starting with the command's name.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* commandUsage_render(berthCommand, 'drop'); // 'berth drop <name>'
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export function commandUsage_render(declaration, subcommand = null) {
|
|
96
|
+
const grammar = declaration.grammar;
|
|
97
|
+
const subcommands = grammar.subcommands;
|
|
98
|
+
if (subcommand !== null && subcommands !== undefined) {
|
|
99
|
+
const chosen = subcommands[subcommand];
|
|
100
|
+
if (chosen !== undefined)
|
|
101
|
+
return words_join(`${declaration.name} ${subcommand}`, lineTail_render(chosen));
|
|
102
|
+
}
|
|
103
|
+
const own = lineTail_render({ ...(grammar.options !== undefined ? { options: grammar.options } : {}), ...(subcommands === undefined && grammar.operands !== undefined ? { operands: grammar.operands } : {}) });
|
|
104
|
+
if (subcommands === undefined)
|
|
105
|
+
return words_join(declaration.name, own);
|
|
106
|
+
// The bare command's own options are its line, the first choice.
|
|
107
|
+
const bareTail = grammar.bare?.options !== undefined ? lineTail_render({ options: grammar.bare.options }) : '';
|
|
108
|
+
const choices = [
|
|
109
|
+
...(bareTail !== '' ? [bareTail] : []),
|
|
110
|
+
...Object.entries(subcommands).map(([word, sub]) => words_join(word, lineTail_render(sub))),
|
|
111
|
+
].join(' | ');
|
|
112
|
+
const bracketed = grammar.bare !== undefined ? `[${choices}]` : `<${choices}>`;
|
|
113
|
+
return words_join(words_join(declaration.name, own), bracketed);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Lines of a help column: each left part padded to the widest, then its summary.
|
|
117
|
+
*
|
|
118
|
+
* @param rows - Left part and summary, by row.
|
|
119
|
+
* @param indent - The spaces before each row.
|
|
120
|
+
* @returns The lines.
|
|
121
|
+
*/
|
|
122
|
+
function columns_render(rows, indent) {
|
|
123
|
+
const width = Math.max(0, ...rows.map(([left]) => left.length));
|
|
124
|
+
return rows.map(([left, summary]) => `${indent}${left.padEnd(width + COLUMN_GAP)}${summary}`);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* One option's help row: its names and its summary, an enum's words after.
|
|
128
|
+
*
|
|
129
|
+
* @param option - The option.
|
|
130
|
+
* @returns The row.
|
|
131
|
+
*/
|
|
132
|
+
function optionRow_make(option) {
|
|
133
|
+
const values = option.value?.kind === 'enum' ? option.value.values : undefined;
|
|
134
|
+
return [optionNames_render(option), values === undefined ? option.summary : `${option.summary} (${values.join(', ')})`];
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The help lines of a stretch's operands and options.
|
|
138
|
+
*
|
|
139
|
+
* @param line - The stretch's grammar.
|
|
140
|
+
* @param indent - The spaces before each row.
|
|
141
|
+
* @returns The lines.
|
|
142
|
+
*/
|
|
143
|
+
function lineRows_render(line, indent) {
|
|
144
|
+
const rows = [
|
|
145
|
+
...(line.operands ?? []).map((operand) => [operand_usage(operand), operand.summary]),
|
|
146
|
+
...Object.values(line.options ?? {}).map(optionRow_make),
|
|
147
|
+
];
|
|
148
|
+
return rows.length === 0 ? [] : columns_render(rows, indent);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* The SUBCOMMANDS lines: the bare command's, then each subcommand's with its
|
|
152
|
+
* operands and options beneath it.
|
|
153
|
+
*
|
|
154
|
+
* @param grammar - The command's grammar.
|
|
155
|
+
* @returns The lines; none for a command without subcommands.
|
|
156
|
+
*/
|
|
157
|
+
function subcommandLines_render(grammar) {
|
|
158
|
+
const subcommands = grammar.subcommands;
|
|
159
|
+
if (subcommands === undefined)
|
|
160
|
+
return [];
|
|
161
|
+
const heads = [
|
|
162
|
+
...(grammar.bare !== undefined ? [['(none)', grammar.bare.summary]] : []),
|
|
163
|
+
...Object.entries(subcommands).map(([word, sub]) => [word, sub.summary]),
|
|
164
|
+
];
|
|
165
|
+
const headLines = columns_render(heads, '');
|
|
166
|
+
const lines = [];
|
|
167
|
+
let at = 0;
|
|
168
|
+
if (grammar.bare !== undefined) {
|
|
169
|
+
lines.push(headLines[at++]);
|
|
170
|
+
lines.push(...lineRows_render({ ...(grammar.bare.options !== undefined ? { options: grammar.bare.options } : {}) }, ' '));
|
|
171
|
+
}
|
|
172
|
+
for (const sub of Object.values(subcommands)) {
|
|
173
|
+
lines.push(headLines[at++]);
|
|
174
|
+
lines.push(...lineRows_render(sub, ' '));
|
|
175
|
+
}
|
|
176
|
+
return lines;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* The help record of a declared command: the usage its grammar generates,
|
|
180
|
+
* its subcommands, operands and options with their summaries, and its prose.
|
|
181
|
+
*
|
|
182
|
+
* @param declaration - The command.
|
|
183
|
+
* @returns The record `help` renders and the listings read.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```ts
|
|
187
|
+
* declarationHelp_derive(lsCommand).usage; // 'ls [-l1hrdfaA] [--sort <field>] [path…]'
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
export function declarationHelp_derive(declaration) {
|
|
191
|
+
const grammar = declaration.grammar;
|
|
192
|
+
const subcommands = subcommandLines_render(grammar);
|
|
193
|
+
const own = {
|
|
194
|
+
...(grammar.subcommands === undefined && grammar.operands !== undefined ? { operands: grammar.operands } : {}),
|
|
195
|
+
...(grammar.options !== undefined ? { options: grammar.options } : {}),
|
|
196
|
+
};
|
|
197
|
+
// The subcommands lead the OPTIONS block under a heading of their own,
|
|
198
|
+
// since that block keeps each line's indent and the subcommands' options
|
|
199
|
+
// sit beneath them.
|
|
200
|
+
const ownRows = lineRows_render(own, '');
|
|
201
|
+
const options = subcommands.length === 0
|
|
202
|
+
? ownRows
|
|
203
|
+
: ['SUBCOMMANDS:', ...subcommands.map((line) => ` ${line}`), ...(ownRows.length > 0 ? ['', ...ownRows] : [])];
|
|
204
|
+
return {
|
|
205
|
+
usage: commandUsage_render(declaration),
|
|
206
|
+
summary: declaration.help.summary,
|
|
207
|
+
description: declaration.help.description,
|
|
208
|
+
...(declaration.help.category !== undefined ? { category: declaration.help.category } : {}),
|
|
209
|
+
...(declaration.help.posix !== undefined ? { posix: { ...declaration.help.posix } } : {}),
|
|
210
|
+
...(options.length > 0 ? { options } : {}),
|
|
211
|
+
...(declaration.help.examples !== undefined ? { examples: [...declaration.help.examples] } : {}),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* The help record of one subcommand of a declared command (`help pacs
|
|
216
|
+
* query`): its usage, its summary, and its operands and options with the
|
|
217
|
+
* command's own beside them; the command's examples that run it.
|
|
218
|
+
*
|
|
219
|
+
* @param declaration - The command.
|
|
220
|
+
* @param subcommand - The subcommand's word.
|
|
221
|
+
* @returns The record, or undefined when the command has no such subcommand.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```ts
|
|
225
|
+
* subcommandHelp_derive(berthCommand, 'drop')?.usage; // 'berth drop <name>'
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
export function subcommandHelp_derive(declaration, subcommand) {
|
|
229
|
+
const subcommands = declaration.grammar.subcommands;
|
|
230
|
+
if (subcommands === undefined || !Object.hasOwn(subcommands, subcommand))
|
|
231
|
+
return undefined;
|
|
232
|
+
const chosen = subcommands[subcommand];
|
|
233
|
+
const options = lineRows_render({
|
|
234
|
+
...(chosen.operands !== undefined ? { operands: chosen.operands } : {}),
|
|
235
|
+
options: { ...(chosen.options ?? {}), ...(declaration.grammar.options ?? {}) },
|
|
236
|
+
}, '');
|
|
237
|
+
const lead = `${declaration.name} ${subcommand}`;
|
|
238
|
+
const examples = (declaration.help.examples ?? []).filter((line) => line === lead || line.startsWith(`${lead} `));
|
|
239
|
+
return {
|
|
240
|
+
usage: commandUsage_render(declaration, subcommand),
|
|
241
|
+
summary: chosen.summary,
|
|
242
|
+
description: chosen.summary,
|
|
243
|
+
...(options.length > 0 ? { options } : {}),
|
|
244
|
+
...(examples.length > 0 ? { examples } : {}),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=commandUsage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandUsage.js","sourceRoot":"","sources":["../../src/core/commandUsage.ts"],"names":[],"mappings":"AAwBA,iEAAiE;AACjE,MAAM,UAAU,GAAW,CAAC,CAAC;AAU7B;;;;;GAKG;AACH,SAAS,aAAa,CAAC,OAAuB;IAC5C,MAAM,IAAI,GAAW,GAAG,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAC5E,OAAO,OAAO,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,IAAI,GAAG,CAAC;AAC/D,CAAC;AAED;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,MAAqB;IAC/C,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS;QAAE,KAAK,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IAC/D,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS;QAAE,KAAK,CAAC,IAAI,CAAC,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9D,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,G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