@fnndsc/brasa 0.56.2 → 0.56.4
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 +11 -0
- package/dist/builtins/berth/berth.js +53 -22
- package/dist/builtins/berth/berth.js.map +1 -1
- package/dist/builtins/berth/berthCube.d.ts +17 -2
- package/dist/builtins/berth/berthCube.js +22 -10
- package/dist/builtins/berth/berthCube.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 +89 -10
- 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 +120 -55
- package/dist/builtins/fs/cp.js.map +1 -1
- package/dist/builtins/fs/download.d.ts +12 -1
- package/dist/builtins/fs/download.js +24 -4
- 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/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 +86 -22
- 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/transferJobs.d.ts +64 -0
- package/dist/builtins/fs/transferJobs.js +98 -0
- package/dist/builtins/fs/transferJobs.js.map +1 -0
- 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 +35 -3
- package/dist/builtins/fs/upload.js +99 -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 +38 -2
- package/dist/builtins/help.js +76 -769
- package/dist/builtins/help.js.map +1 -1
- package/dist/builtins/helpSections.js +4 -1
- package/dist/builtins/helpSections.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 +52 -3
- package/dist/builtins/res/dicom.js +82 -34
- 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 +718 -263
- 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 +0 -37
- package/dist/builtins/utils.js +0 -86
- package/dist/builtins/utils.js.map +1 -1
- package/dist/chris/chrisCommands.js +58 -152
- 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/filesystem.js +7 -5
- package/dist/chris/filesystem.js.map +1 -1
- package/dist/chris/help.js +0 -1018
- package/dist/chris/help.js.map +1 -1
- package/dist/chris/kinds.d.ts +21 -0
- package/dist/chris/kinds.js +114 -2
- package/dist/chris/kinds.js.map +1 -1
- 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/core/commandDeclaration.d.ts +97 -7
- package/dist/core/commandDeclaration.js +21 -0
- package/dist/core/commandDeclaration.js.map +1 -1
- package/dist/core/commandParse.js +65 -17
- package/dist/core/commandParse.js.map +1 -1
- package/dist/core/commandRegistry.d.ts +4 -3
- package/dist/core/commandRegistry.js +36 -8
- package/dist/core/commandRegistry.js.map +1 -1
- package/dist/core/commandSchema.js +5 -2
- package/dist/core/commandSchema.js.map +1 -1
- package/dist/core/commandUsage.d.ts +15 -0
- package/dist/core/commandUsage.js +59 -7
- package/dist/core/commandUsage.js.map +1 -1
- package/dist/core/coreCommands.js +63 -212
- package/dist/core/coreCommands.js.map +1 -1
- package/dist/core/paths.d.ts +29 -1
- package/dist/core/paths.js +15 -2
- package/dist/core/paths.js.map +1 -1
- package/dist/core/preprocess.d.ts +3 -4
- package/dist/core/preprocess.js +4 -5
- package/dist/core/preprocess.js.map +1 -1
- package/dist/lib/completer/declared.js +7 -4
- package/dist/lib/completer/declared.js.map +1 -1
- package/dist/lib/completer/index.js +2 -7
- package/dist/lib/completer/index.js.map +1 -1
- package/dist/lib/parser.d.ts +0 -8
- package/dist/lib/parser.js +0 -11
- package/dist/lib/parser.js.map +1 -1
- package/dist/lib/vfs/vfs.d.ts +2 -1
- package/dist/lib/vfs/vfs.js +5 -4
- package/dist/lib/vfs/vfs.js.map +1 -1
- package/dist/notes.json +1 -1
- package/package.json +5 -5
|
@@ -12,20 +12,63 @@
|
|
|
12
12
|
* Both answer with text and no model, as the text filters do, so
|
|
13
13
|
* `A=$(echo …)` holds what was written.
|
|
14
14
|
*
|
|
15
|
+
* Each is declared in one record (`echoCommand`, `printfCommand`). `printf`
|
|
16
|
+
* parses its line as every declared command does; `echo` declares its words
|
|
17
|
+
* its own (`grammar: 'expression'`), since a dash-word past the front is a
|
|
18
|
+
* word to it, never an option.
|
|
19
|
+
*
|
|
15
20
|
* @module
|
|
16
21
|
*/
|
|
17
22
|
import { type CommandEnvelope } from '@fnndsc/menu';
|
|
23
|
+
import { type ExpressionDeclaration } from '../../core/commandDeclaration.js';
|
|
18
24
|
/** What a format turned into, or why it could not be. */
|
|
19
25
|
type Formatted = {
|
|
20
26
|
text: string;
|
|
21
27
|
} | {
|
|
22
28
|
refused: string;
|
|
23
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* `echo [WORD]…`: the declaration. Its grammar is its own: every word is a
|
|
32
|
+
* word, dashes and all, so the GNU option grammar would take `echo use -n
|
|
33
|
+
* here` for an option; only `-n`, `-e` or `-E` at the front is refused.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* commands_register({ declarations: [echoCommand] });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare const echoCommand: ExpressionDeclaration;
|
|
41
|
+
/**
|
|
42
|
+
* `printf FORMAT [ARG]…`: the declaration.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* commands_register({ declarations: [printfCommand] });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare const printfCommand: import("../../core/commandDeclaration.js").CommandDeclaration<{
|
|
50
|
+
readonly operands: readonly [{
|
|
51
|
+
readonly name: "format";
|
|
52
|
+
readonly kind: "word";
|
|
53
|
+
readonly summary: "The format: %s, %d, %i and %% with flags, width and precision; the escapes \\n, \\t and \\\\";
|
|
54
|
+
}, {
|
|
55
|
+
readonly name: "argument";
|
|
56
|
+
readonly kind: "word";
|
|
57
|
+
readonly optional: true;
|
|
58
|
+
readonly repeat: true;
|
|
59
|
+
readonly summary: "The values the format takes, in turn";
|
|
60
|
+
}];
|
|
61
|
+
}>;
|
|
24
62
|
/**
|
|
25
63
|
* `echo [WORD]…`: the words, joined by a space, on one line.
|
|
26
64
|
*
|
|
27
65
|
* @param args - The words after `echo`.
|
|
28
66
|
* @returns The line.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* (await builtin_echo(['feed', '5596'])).rendered; // 'feed 5596\n'
|
|
71
|
+
* ```
|
|
29
72
|
*/
|
|
30
73
|
export declare function builtin_echo(args: string[]): Promise<CommandEnvelope>;
|
|
31
74
|
/**
|
|
@@ -38,10 +81,28 @@ export declare function builtin_echo(args: string[]): Promise<CommandEnvelope>;
|
|
|
38
81
|
*/
|
|
39
82
|
export declare function printf_format(format: string, args: string[]): Formatted;
|
|
40
83
|
/**
|
|
41
|
-
* `printf
|
|
84
|
+
* `printf` over words already split: the declaration's parse and handler.
|
|
42
85
|
*
|
|
43
86
|
* @param args - The format, then its arguments.
|
|
44
|
-
* @returns The text, its line ended.
|
|
87
|
+
* @returns The text, its line ended, or the refusal of a bad line.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* (await builtin_printf(['%s-%03d', 'scan', '7'])).rendered; // 'scan-007\n'
|
|
92
|
+
* ```
|
|
45
93
|
*/
|
|
46
94
|
export declare function builtin_printf(args: string[]): Promise<CommandEnvelope>;
|
|
95
|
+
/**
|
|
96
|
+
* The arguments written under the format.
|
|
97
|
+
*
|
|
98
|
+
* @param format - The format.
|
|
99
|
+
* @param rest - Its arguments.
|
|
100
|
+
* @returns The text, its line ended, or the refusal of what printf here does not read.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* await printf_run('%s=%d', ['a', '1']);
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare function printf_run(format: string, rest: readonly string[]): Promise<CommandEnvelope>;
|
|
47
108
|
export {};
|
|
@@ -12,19 +12,83 @@
|
|
|
12
12
|
* Both answer with text and no model, as the text filters do, so
|
|
13
13
|
* `A=$(echo …)` holds what was written.
|
|
14
14
|
*
|
|
15
|
+
* Each is declared in one record (`echoCommand`, `printfCommand`). `printf`
|
|
16
|
+
* parses its line as every declared command does; `echo` declares its words
|
|
17
|
+
* its own (`grammar: 'expression'`), since a dash-word past the front is a
|
|
18
|
+
* word to it, never an option.
|
|
19
|
+
*
|
|
15
20
|
* @module
|
|
16
21
|
*/
|
|
17
22
|
import { envelope_error, envelope_ok } from '@fnndsc/menu';
|
|
18
23
|
import { exitCode_set } from '../../core/handlerRun.js';
|
|
24
|
+
import { command_declare } from '../../core/commandDeclaration.js';
|
|
25
|
+
import { declaredCommand_run } from '../../core/commandParse.js';
|
|
19
26
|
/** The options other echos take at the front of the line, which this one refuses so a word is never silently eaten. */
|
|
20
27
|
const ECHO_OPTIONS = new Set(['-n', '-e', '-E']);
|
|
21
28
|
/** A conversion: `%`, flags, width, precision, then the letter. */
|
|
22
29
|
const CONVERSION = /^%([-+ 0#]*)(\d*|\*)(?:\.(\d*|\*))?([a-zA-Z%])/;
|
|
30
|
+
/** What a `printf` line may hold. */
|
|
31
|
+
const PRINTF_GRAMMAR = {
|
|
32
|
+
operands: [
|
|
33
|
+
{ name: 'format', kind: 'word', summary: 'The format: %s, %d, %i and %% with flags, width and precision; the escapes \\n, \\t and \\\\' },
|
|
34
|
+
{ name: 'argument', kind: 'word', optional: true, repeat: true, summary: 'The values the format takes, in turn' },
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* `echo [WORD]…`: the declaration. Its grammar is its own: every word is a
|
|
39
|
+
* word, dashes and all, so the GNU option grammar would take `echo use -n
|
|
40
|
+
* here` for an option; only `-n`, `-e` or `-E` at the front is refused.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* commands_register({ declarations: [echoCommand] });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export const echoCommand = {
|
|
48
|
+
name: 'echo',
|
|
49
|
+
grammar: 'expression',
|
|
50
|
+
help: {
|
|
51
|
+
usage: 'echo [WORD]…',
|
|
52
|
+
summary: 'Write words on a line',
|
|
53
|
+
description: 'Writes its words joined by a space and ends the line. It takes no option and reads no escape, since the System V and BSD echos disagree on both; -n, -e or -E as the first word is refused by name rather than obeyed; later it is a word. A field of a variable is a word like any other: echo ${R.feedId}. It answers with text, so A=$(echo …) holds what it wrote. To see a variable whole, set NAME.',
|
|
54
|
+
category: 'General',
|
|
55
|
+
posix: { group: 'Text', differs: 'no options and no escapes: the words, joined by a space, on one line; printf writes anything else' },
|
|
56
|
+
examples: ['echo hello', 'echo feed ${R.feedId}', 'X=$(echo t1 cohort)'],
|
|
57
|
+
},
|
|
58
|
+
holds: [],
|
|
59
|
+
handler: (args) => builtin_echo(args),
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* `printf FORMAT [ARG]…`: the declaration.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* commands_register({ declarations: [printfCommand] });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export const printfCommand = command_declare({
|
|
70
|
+
name: 'printf',
|
|
71
|
+
grammar: PRINTF_GRAMMAR,
|
|
72
|
+
help: {
|
|
73
|
+
summary: 'Write arguments under a format',
|
|
74
|
+
description: 'Writes each argument under the format, as POSIX printf does: %s a word, %d and %i a whole number, %% a percent sign, each with the flags - 0 + and space, a width and a precision (%-12s, %05d, %.3s). With more arguments than the format takes, the format is written again until they run out; one missing is empty for %s and 0 for %d. The escapes are \\n, \\t and \\\\; a backslash in quotes reaches printf as written, so \'%s\\n\' or "%s\\n" writes a newline. Any other conversion or escape is refused by name. A session writes whole lines, so the text always ends its line. It answers with text, so A=$(printf …) holds what it wrote. An argument that starts with a dash (-5) follows --: printf -- \'%d\' -5.',
|
|
75
|
+
category: 'General',
|
|
76
|
+
posix: { group: 'Text', differs: 'POSIX\'s subset: %s, %d, %i, %%, flags, width and precision; the escapes \\n, \\t and \\\\; always ends the line' },
|
|
77
|
+
examples: ['printf "feed %s: %s" ${R.feedId} done', "printf '%-8s %5d\\n' a 1 bb 22", 'NAME=$(printf "%s-%03d" scan 7)'],
|
|
78
|
+
},
|
|
79
|
+
holds: [],
|
|
80
|
+
handler: async (args) => printf_run(args.operands.format, args.operands.argument),
|
|
81
|
+
});
|
|
23
82
|
/**
|
|
24
83
|
* `echo [WORD]…`: the words, joined by a space, on one line.
|
|
25
84
|
*
|
|
26
85
|
* @param args - The words after `echo`.
|
|
27
86
|
* @returns The line.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* (await builtin_echo(['feed', '5596'])).rendered; // 'feed 5596\n'
|
|
91
|
+
* ```
|
|
28
92
|
*/
|
|
29
93
|
export async function builtin_echo(args) {
|
|
30
94
|
const option = args[0];
|
|
@@ -161,18 +225,33 @@ export function printf_format(format, args) {
|
|
|
161
225
|
return { text };
|
|
162
226
|
}
|
|
163
227
|
/**
|
|
164
|
-
* `printf
|
|
228
|
+
* `printf` over words already split: the declaration's parse and handler.
|
|
165
229
|
*
|
|
166
230
|
* @param args - The format, then its arguments.
|
|
167
|
-
* @returns The text, its line ended.
|
|
231
|
+
* @returns The text, its line ended, or the refusal of a bad line.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```ts
|
|
235
|
+
* (await builtin_printf(['%s-%03d', 'scan', '7'])).rendered; // 'scan-007\n'
|
|
236
|
+
* ```
|
|
168
237
|
*/
|
|
169
238
|
export async function builtin_printf(args) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
239
|
+
return declaredCommand_run(printfCommand, args);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* The arguments written under the format.
|
|
243
|
+
*
|
|
244
|
+
* @param format - The format.
|
|
245
|
+
* @param rest - Its arguments.
|
|
246
|
+
* @returns The text, its line ended, or the refusal of what printf here does not read.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* await printf_run('%s=%d', ['a', '1']);
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
export async function printf_run(format, rest) {
|
|
254
|
+
const formatted = printf_format(format, [...rest]);
|
|
176
255
|
if ('refused' in formatted) {
|
|
177
256
|
exitCode_set(1);
|
|
178
257
|
return envelope_error('', undefined, `${formatted.refused}\n`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"echo.js","sourceRoot":"","sources":["../../../src/builtins/sys/echo.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"echo.js","sourceRoot":"","sources":["../../../src/builtins/sys/echo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,cAAc,EAAE,WAAW,EAAwB,MAAM,cAAc,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,eAAe,EAA0E,MAAM,kCAAkC,CAAC;AAC3I,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,uHAAuH;AACvH,MAAM,YAAY,GAAwB,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAEtE,mEAAmE;AACnE,MAAM,UAAU,GAAW,gDAAgD,CAAC;AAK5E,qCAAqC;AACrC,MAAM,cAAc,GAAG;IACrB,QAAQ,EAAE;QACR,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,8FAA8F,EAAE;QACzI,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAA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text (no trailing newline).
|
|
9
9
|
*/
|
|
10
10
|
export declare function fortune_random(maxLines?: number): string;
|
|
11
|
+
/**
|
|
12
|
+
* `fortune`: the declaration.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* commands_register({ declarations: [fortuneCommand] });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const fortuneCommand: import("../../core/commandDeclaration.js").CommandDeclaration<{}>;
|
|
20
|
+
/**
|
|
21
|
+
* `fortune` over words already split: the declaration's parse and handler.
|
|
22
|
+
*
|
|
23
|
+
* @param args - The words after `fortune`.
|
|
24
|
+
* @returns A fortune, or the refusal of a bad line.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* await builtin_fortune([]);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function builtin_fortune(args: string[]): Promise<CommandEnvelope>;
|
|
11
32
|
/**
|
|
12
33
|
* Reports a random fortune as a command envelope.
|
|
13
34
|
*
|
|
14
|
-
* @param _args - Unused.
|
|
15
35
|
* @returns An envelope carrying the chosen fortune and a typed model of it.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* await fortune_run();
|
|
40
|
+
* ```
|
|
16
41
|
*/
|
|
17
|
-
export declare function
|
|
42
|
+
export declare function fortune_run(): Promise<CommandEnvelope>;
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { FORTUNES } from './fortunes.data.js';
|
|
12
12
|
import { envelope_ok } from '@fnndsc/menu';
|
|
13
|
+
import { command_declare } from '../../core/commandDeclaration.js';
|
|
14
|
+
import { declaredCommand_run } from '../../core/commandParse.js';
|
|
13
15
|
/**
|
|
14
16
|
* Picks a random fortune from the bundled collection.
|
|
15
17
|
*
|
|
@@ -25,13 +27,53 @@ export function fortune_random(maxLines) {
|
|
|
25
27
|
const pool = bounded.length > 0 ? bounded : FORTUNES;
|
|
26
28
|
return pool[Math.floor(Math.random() * pool.length)];
|
|
27
29
|
}
|
|
30
|
+
/** What a `fortune` line may hold: nothing. */
|
|
31
|
+
const FORTUNE_GRAMMAR = {};
|
|
32
|
+
/**
|
|
33
|
+
* `fortune`: the declaration.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* commands_register({ declarations: [fortuneCommand] });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export const fortuneCommand = command_declare({
|
|
41
|
+
name: 'fortune',
|
|
42
|
+
grammar: FORTUNE_GRAMMAR,
|
|
43
|
+
help: {
|
|
44
|
+
summary: 'Print a random fortune cookie',
|
|
45
|
+
description: 'Prints a random fortune — the classic UNIX fortune cookie, bundled and self-contained.',
|
|
46
|
+
examples: ['fortune'],
|
|
47
|
+
category: 'Games',
|
|
48
|
+
},
|
|
49
|
+
holds: [],
|
|
50
|
+
handler: async (_args) => fortune_run(),
|
|
51
|
+
});
|
|
52
|
+
/**
|
|
53
|
+
* `fortune` over words already split: the declaration's parse and handler.
|
|
54
|
+
*
|
|
55
|
+
* @param args - The words after `fortune`.
|
|
56
|
+
* @returns A fortune, or the refusal of a bad line.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* await builtin_fortune([]);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export async function builtin_fortune(args) {
|
|
64
|
+
return declaredCommand_run(fortuneCommand, args);
|
|
65
|
+
}
|
|
28
66
|
/**
|
|
29
67
|
* Reports a random fortune as a command envelope.
|
|
30
68
|
*
|
|
31
|
-
* @param _args - Unused.
|
|
32
69
|
* @returns An envelope carrying the chosen fortune and a typed model of it.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* await fortune_run();
|
|
74
|
+
* ```
|
|
33
75
|
*/
|
|
34
|
-
export async function
|
|
76
|
+
export async function fortune_run() {
|
|
35
77
|
const fortune = fortune_random();
|
|
36
78
|
return envelope_ok(`${fortune}\n`, {
|
|
37
79
|
kind: 'sys.fortune',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fortune.js","sourceRoot":"","sources":["../../../src/builtins/sys/fortune.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAmB,WAAW,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"fortune.js","sourceRoot":"","sources":["../../../src/builtins/sys/fortune.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAmB,WAAW,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,eAAe,EAA8C,MAAM,kCAAkC,CAAC;AAC/G,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,QAAiB;IAC9C,MAAM,OAAO,GACX,QAAQ,KAAK,SAAS;QACpB,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAS,EAAW,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,QAAQ,CAAC;QAC3E,CAAC,CAAC,QAAQ,CAAC;IACf,MAAM,IAAI,GAAsB,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;IACxE,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AACvD,CAAC;AAED,+CAA+C;AAC/C,MAAM,eAAe,GAAG,EAAoC,CAAC;AAE7D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC;IAC5C,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,eAAe;IACxB,IAAI,EAAE;QACJ,OAAO,EAAE,+BAA+B;QACxC,WAAW,EAAE,wFAAwF;QACrG,QAAQ,EAAE,CAAC,SAAS,CAAC;QACrB,QAAQ,EAAE,OAAO;KAClB;IACD,KAAK,EAAE,EAAE;IACT,OAAO,EAAE,KAAK,EAAE,KAA+C,EAA4B,EAAE,CAAC,WAAW,EAAE;CAC5G,CAAC,CAAC;AAEH;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,IAAc;IAClD,OAAO,mBAAmB,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;AACnD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,MAAM,OAAO,GAAW,cAAc,EAAE,CAAC;IACzC,OAAO,WAAW,CAAC,GAAG,OAAO,IAAI,EAAE;QACjC,IAAI,EAAE,aAAa;QACnB,IAAI,EAAE,EAAE,OAAO,EAAE;KAClB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,29 +1,231 @@
|
|
|
1
|
-
import { CommandEnvelope } from '@fnndsc/menu';
|
|
1
|
+
import { type CommandEnvelope } from '@fnndsc/menu';
|
|
2
|
+
import { type FilterSource } from './textFilters.js';
|
|
2
3
|
import { type AnswerRow } from '../../session/answer.js';
|
|
3
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* What a grep line asks of a match: the flags that decide which lines (or
|
|
6
|
+
* rows) are kept, and the patterns.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const ask: GrepAsk = { insensitive: true, invert: false, word: false, extended: false, fixed: false, count: false, patterns: ['t1'] };
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
4
13
|
export interface GrepAsk {
|
|
14
|
+
/** -i: ignore case. */
|
|
5
15
|
insensitive: boolean;
|
|
16
|
+
/** -v: keep what does not match. */
|
|
6
17
|
invert: boolean;
|
|
18
|
+
/** -w: whole words. */
|
|
7
19
|
word: boolean;
|
|
20
|
+
/** -E: extended regular expressions. */
|
|
8
21
|
extended: boolean;
|
|
22
|
+
/** -F: fixed strings. */
|
|
9
23
|
fixed: boolean;
|
|
24
|
+
/** -c: count only. */
|
|
10
25
|
count: boolean;
|
|
26
|
+
/** The patterns: any of them matches. */
|
|
11
27
|
patterns: string[];
|
|
12
|
-
/** A flag or operand this grep does not take: the line is the system grep's. */
|
|
13
|
-
foreign: string | null;
|
|
14
28
|
}
|
|
15
29
|
/**
|
|
16
|
-
*
|
|
30
|
+
* How a grep line over text writes what it kept: the flags that mean
|
|
31
|
+
* something for lines and files, and nothing for a numbered listing.
|
|
17
32
|
*
|
|
18
|
-
* @
|
|
19
|
-
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const layout: GrepLayout = { ...GREP_LAYOUT_PLAIN, lineNumber: true, after: 2 };
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export interface GrepLayout {
|
|
39
|
+
/** -n: each line's number. */
|
|
40
|
+
lineNumber: boolean;
|
|
41
|
+
/** -l: only the names of files with a match. */
|
|
42
|
+
filesWithMatches: boolean;
|
|
43
|
+
/** -o: only the matching parts, one per line. */
|
|
44
|
+
onlyMatching: boolean;
|
|
45
|
+
/** -h: no file-name prefix. */
|
|
46
|
+
noFilename: boolean;
|
|
47
|
+
/** -H: the file-name prefix even for one file. */
|
|
48
|
+
withFilename: boolean;
|
|
49
|
+
/** --color[=WHEN], as given: the kernel writes no colour; the system grep is told. */
|
|
50
|
+
color: string | undefined;
|
|
51
|
+
/** -r: each folder operand walked for files. */
|
|
52
|
+
recursive: boolean;
|
|
53
|
+
/** -A N, as given. */
|
|
54
|
+
after: number | undefined;
|
|
55
|
+
/** -B N, as given. */
|
|
56
|
+
before: number | undefined;
|
|
57
|
+
/** -C N, as given. */
|
|
58
|
+
context: number | undefined;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The layout of a grep line that asks none: lines as they are.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const layout: GrepLayout = { ...GREP_LAYOUT_PLAIN, onlyMatching: true };
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare const GREP_LAYOUT_PLAIN: GrepLayout;
|
|
69
|
+
/**
|
|
70
|
+
* `grep [-ivwEFcnlohr] [-A N] [-B N] [-C N] [-e PATTERN]... [PATTERN] [FILE]...`: the declaration.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* commands_register({ declarations: [grepCommand] });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare const grepCommand: import("../../core/commandDeclaration.js").CommandDeclaration<{
|
|
78
|
+
readonly operands: readonly [{
|
|
79
|
+
readonly name: "pattern";
|
|
80
|
+
readonly kind: "word";
|
|
81
|
+
readonly optional: true;
|
|
82
|
+
readonly unless: "regexp";
|
|
83
|
+
readonly summary: "The pattern, unless -e gives it";
|
|
84
|
+
}, {
|
|
85
|
+
readonly name: "files";
|
|
86
|
+
readonly kind: "cfsPath";
|
|
87
|
+
readonly optional: true;
|
|
88
|
+
readonly repeat: true;
|
|
89
|
+
readonly glob: true;
|
|
90
|
+
readonly summary: "ChRIS files to read, in order (a wildcard matches paths; - is the pipe); the pipe when none is named";
|
|
91
|
+
}];
|
|
92
|
+
readonly options: {
|
|
93
|
+
readonly insensitive: {
|
|
94
|
+
readonly short: "i";
|
|
95
|
+
readonly long: "ignore-case";
|
|
96
|
+
readonly summary: "Ignore case";
|
|
97
|
+
};
|
|
98
|
+
readonly invert: {
|
|
99
|
+
readonly short: "v";
|
|
100
|
+
readonly long: "invert-match";
|
|
101
|
+
readonly summary: "Keep what does not match";
|
|
102
|
+
};
|
|
103
|
+
readonly word: {
|
|
104
|
+
readonly short: "w";
|
|
105
|
+
readonly long: "word-regexp";
|
|
106
|
+
readonly summary: "Whole words";
|
|
107
|
+
};
|
|
108
|
+
readonly extended: {
|
|
109
|
+
readonly short: "E";
|
|
110
|
+
readonly long: "extended-regexp";
|
|
111
|
+
readonly summary: "Extended regular expressions";
|
|
112
|
+
};
|
|
113
|
+
readonly fixed: {
|
|
114
|
+
readonly short: "F";
|
|
115
|
+
readonly long: "fixed-strings";
|
|
116
|
+
readonly summary: "Fixed strings";
|
|
117
|
+
};
|
|
118
|
+
readonly count: {
|
|
119
|
+
readonly short: "c";
|
|
120
|
+
readonly long: "count";
|
|
121
|
+
readonly summary: "Count only";
|
|
122
|
+
};
|
|
123
|
+
readonly regexp: {
|
|
124
|
+
readonly short: "e";
|
|
125
|
+
readonly long: "regexp";
|
|
126
|
+
readonly repeat: true;
|
|
127
|
+
readonly value: {
|
|
128
|
+
readonly name: "pattern";
|
|
129
|
+
readonly kind: "word";
|
|
130
|
+
};
|
|
131
|
+
readonly summary: "A pattern (repeatable: any of them matches)";
|
|
132
|
+
};
|
|
133
|
+
readonly lineNumber: {
|
|
134
|
+
readonly short: "n";
|
|
135
|
+
readonly long: "line-number";
|
|
136
|
+
readonly summary: "Each line's number (text and files)";
|
|
137
|
+
};
|
|
138
|
+
readonly filesWithMatches: {
|
|
139
|
+
readonly short: "l";
|
|
140
|
+
readonly long: "files-with-matches";
|
|
141
|
+
readonly summary: "Only the names of files with a match";
|
|
142
|
+
};
|
|
143
|
+
readonly onlyMatching: {
|
|
144
|
+
readonly short: "o";
|
|
145
|
+
readonly long: "only-matching";
|
|
146
|
+
readonly summary: "Only the matching parts, one per line";
|
|
147
|
+
};
|
|
148
|
+
readonly noFilename: {
|
|
149
|
+
readonly short: "h";
|
|
150
|
+
readonly long: "no-filename";
|
|
151
|
+
readonly summary: "No file-name prefix";
|
|
152
|
+
};
|
|
153
|
+
readonly withFilename: {
|
|
154
|
+
readonly short: "H";
|
|
155
|
+
readonly long: "with-filename";
|
|
156
|
+
readonly summary: "The file-name prefix, even for one file";
|
|
157
|
+
};
|
|
158
|
+
readonly color: {
|
|
159
|
+
readonly long: "color";
|
|
160
|
+
readonly value: {
|
|
161
|
+
readonly name: "when";
|
|
162
|
+
readonly kind: "word";
|
|
163
|
+
readonly optional: true;
|
|
164
|
+
};
|
|
165
|
+
readonly summary: "Colour the matches (always, never, auto): the system grep colours; the session's own grep writes plain text";
|
|
166
|
+
};
|
|
167
|
+
readonly recursive: {
|
|
168
|
+
readonly short: "r";
|
|
169
|
+
readonly long: "recursive";
|
|
170
|
+
readonly summary: "Walk each folder for files (. when none is named)";
|
|
171
|
+
};
|
|
172
|
+
readonly after: {
|
|
173
|
+
readonly short: "A";
|
|
174
|
+
readonly long: "after-context";
|
|
175
|
+
readonly value: {
|
|
176
|
+
readonly name: "N";
|
|
177
|
+
readonly kind: "int";
|
|
178
|
+
readonly min: 0;
|
|
179
|
+
};
|
|
180
|
+
readonly summary: "N lines after each match";
|
|
181
|
+
};
|
|
182
|
+
readonly before: {
|
|
183
|
+
readonly short: "B";
|
|
184
|
+
readonly long: "before-context";
|
|
185
|
+
readonly value: {
|
|
186
|
+
readonly name: "N";
|
|
187
|
+
readonly kind: "int";
|
|
188
|
+
readonly min: 0;
|
|
189
|
+
};
|
|
190
|
+
readonly summary: "N lines before each match";
|
|
191
|
+
};
|
|
192
|
+
readonly context: {
|
|
193
|
+
readonly short: "C";
|
|
194
|
+
readonly long: "context";
|
|
195
|
+
readonly value: {
|
|
196
|
+
readonly name: "N";
|
|
197
|
+
readonly kind: "int";
|
|
198
|
+
readonly min: 0;
|
|
199
|
+
};
|
|
200
|
+
readonly summary: "N lines around each match";
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
}>;
|
|
204
|
+
/**
|
|
205
|
+
* Builds the expression a line (or a row's text) is matched by: any of the
|
|
206
|
+
* patterns, read as grep reads them under -F, -E or neither, -w and -i.
|
|
207
|
+
*
|
|
208
|
+
* @param ask - What the grep line asks of a match.
|
|
209
|
+
* @returns The expression (not global), or a refusal when a pattern does not compile.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts
|
|
213
|
+
* grepExpression_build({ ...ask, patterns: ['t1\\|t2'] }); // /(?:t1|t2)/
|
|
214
|
+
* ```
|
|
20
215
|
*/
|
|
21
|
-
export declare function
|
|
216
|
+
export declare function grepExpression_build(ask: GrepAsk): RegExp | {
|
|
217
|
+
refused: string;
|
|
218
|
+
};
|
|
22
219
|
/**
|
|
23
220
|
* Builds the test a line (or a row's text) passes.
|
|
24
221
|
*
|
|
25
|
-
* @param ask - What the grep line asks.
|
|
222
|
+
* @param ask - What the grep line asks of a match.
|
|
26
223
|
* @returns The test, or a refusal when a pattern does not compile.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```ts
|
|
227
|
+
* const matches = grepMatcher_build({ ...ask, patterns: ['T1'], word: true });
|
|
228
|
+
* ```
|
|
27
229
|
*/
|
|
28
230
|
export declare function grepMatcher_build(ask: GrepAsk): ((text: string) => boolean) | {
|
|
29
231
|
refused: string;
|
|
@@ -39,10 +241,42 @@ export declare function grepMatcher_build(ask: GrepAsk): ((text: string) => bool
|
|
|
39
241
|
* @returns The kept rows, in order.
|
|
40
242
|
*/
|
|
41
243
|
export declare function listingRows_grep(rows: ReadonlyArray<AnswerRow>, matches: (text: string) => boolean, invert: boolean): AnswerRow[];
|
|
244
|
+
/** What a grep over text wrote, and how many lines it kept. */
|
|
245
|
+
interface GrepAnswer {
|
|
246
|
+
/** The output. */
|
|
247
|
+
readonly text: string;
|
|
248
|
+
/** Lines selected over every source, for the exit status. */
|
|
249
|
+
readonly selected: number;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* The lines a grep over text writes for its sources, as GNU grep writes
|
|
253
|
+
* them: `name:` before each line when named, `N:` under -n (`-` for a
|
|
254
|
+
* context line), `--` between groups apart under -A, -B or -C; -l the
|
|
255
|
+
* names with a match, -c a count each, -o the matching parts.
|
|
256
|
+
*
|
|
257
|
+
* @param expression - The match, compiled.
|
|
258
|
+
* @param ask - What the line asks of a match.
|
|
259
|
+
* @param layout - How it writes what it kept.
|
|
260
|
+
* @param sources - The texts, under the names shown.
|
|
261
|
+
* @param named - Whether each line is under its file's name.
|
|
262
|
+
* @returns The output and how many lines were kept.
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```ts
|
|
266
|
+
* textSources_grep(/b/, ask, GREP_LAYOUT_PLAIN, [{ name: null, text: 'a\nb\n' }], false).text; // 'b\n'
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
export declare function textSources_grep(expression: RegExp, ask: GrepAsk, layout: GrepLayout, sources: ReadonlyArray<FilterSource>, named: boolean): GrepAnswer;
|
|
42
270
|
/**
|
|
43
|
-
* `grep
|
|
271
|
+
* `grep` over words already split: the declaration's parse and handler.
|
|
44
272
|
*
|
|
45
273
|
* @param args - The words after `grep`.
|
|
46
|
-
* @returns The envelope.
|
|
274
|
+
* @returns The envelope, or the refusal of a bad line.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts
|
|
278
|
+
* await builtin_grep(['-i', 't1']);
|
|
279
|
+
* ```
|
|
47
280
|
*/
|
|
48
281
|
export declare function builtin_grep(args: string[]): Promise<CommandEnvelope>;
|
|
282
|
+
export {};
|