@amritk/nish-x86_64-linux 0.35.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/INSTALL.md +6 -1
- package/bin/nish +0 -0
- package/docs/AI.md +9 -2
- package/package.json +1 -1
- package/runtime/nish.d.ts +4612 -430
- package/runtime/vite.d.ts +30 -0
- package/runtime/vite.mjs +150 -0
- package/scripts/build.sh +108 -13
- package/std/base64.ts +34 -5
- package/std/bytes.ts +256 -40
- package/std/cli-args.ts +296 -70
- package/std/cli-flags.ts +184 -19
- package/std/cli.ts +475 -54
- package/std/collections.ts +121 -23
- package/std/compress/checksum.ts +44 -14
- package/std/compress/deflate.ts +224 -111
- package/std/compress/gzip.ts +217 -53
- package/std/compress/zlib.ts +63 -7
- package/std/crypto/aes.ts +80 -9
- package/std/crypto/base64url.ts +22 -0
- package/std/crypto/bcrypt-batch.ts +88 -21
- package/std/crypto/bcrypt.ts +60 -0
- package/std/crypto/chacha20poly1305.ts +53 -0
- package/std/crypto/ct.ts +32 -13
- package/std/crypto/ed25519.ts +47 -0
- package/std/crypto/hkdf.ts +198 -13
- package/std/crypto/hmac.ts +235 -31
- package/std/crypto/jwt.ts +192 -63
- package/std/crypto/p256.ts +159 -16
- package/std/crypto/p384.ts +28 -3
- package/std/crypto/pki-roots.ts +32 -2
- package/std/crypto/pki.ts +81 -15
- package/std/crypto/rsa.ts +33 -3
- package/std/crypto/sha1.ts +3 -0
- package/std/crypto/sha256.ts +24 -1
- package/std/crypto/sha512.ts +99 -14
- package/std/crypto/x25519.ts +152 -14
- package/std/crypto/x509-random.ts +10 -0
- package/std/crypto/x509.ts +67 -7
- package/std/json-equal.ts +19 -0
- package/std/json-format.ts +112 -13
- package/std/json-number.ts +64 -14
- package/std/json-pointer.ts +23 -1
- package/std/json-tokenizer.ts +100 -29
- package/std/json-typed.ts +713 -66
- package/std/json-value.ts +400 -124
- package/std/json.ts +138 -10
- package/std/map.ts +25 -7
- package/std/math.ts +36 -4
- package/std/net/buffer-pool.ts +42 -11
- package/std/net/dns-config.ts +109 -23
- package/std/net/dns-message.ts +62 -7
- package/std/net/dns-resolver.ts +247 -53
- package/std/net/dns.ts +203 -35
- package/std/net/fetch.ts +151 -61
- package/std/net/handler.ts +278 -80
- package/std/net/hpack.ts +262 -52
- package/std/net/http-compress.ts +125 -15
- package/std/net/http-fields.ts +85 -9
- package/std/net/http1-client-codec.ts +100 -19
- package/std/net/http1-codec.ts +235 -27
- package/std/net/http1-server.ts +343 -85
- package/std/net/http2-frame.ts +272 -35
- package/std/net/http2-tls.ts +135 -34
- package/std/net/http2.ts +247 -106
- package/std/net/http3-frame.ts +154 -17
- package/std/net/http3-server.ts +246 -96
- package/std/net/http3.ts +307 -115
- package/std/net/outbound.ts +37 -3
- package/std/net/postgres-carrier.ts +144 -8
- package/std/net/postgres.ts +723 -103
- package/std/net/prefork.ts +164 -31
- package/std/net/qpack.ts +105 -18
- package/std/net/quic-conn-ack.ts +59 -12
- package/std/net/quic-conn-cid.ts +124 -27
- package/std/net/quic-conn-params.ts +70 -10
- package/std/net/quic-datagram.ts +43 -3
- package/std/net/quic-frame.ts +286 -12
- package/std/net/quic-listener.ts +101 -32
- package/std/net/quic-packet.ts +302 -21
- package/std/net/quic-recovery.ts +228 -44
- package/std/net/quic-stream.ts +353 -91
- package/std/net/quic.ts +489 -171
- package/std/net/router.ts +87 -40
- package/std/net/tls/client.ts +166 -51
- package/std/net/tls/codec.ts +413 -56
- package/std/net/tls/record-client.ts +110 -55
- package/std/net/tls/record-server.ts +159 -59
- package/std/net/tls/record.ts +109 -12
- package/std/net/tls/schedule.ts +235 -26
- package/std/net/tls/ticket.ts +159 -40
- package/std/net/tls/verify.ts +49 -3
- package/std/net/tls-tcp.ts +250 -45
- package/std/net/tls.ts +221 -59
- package/std/net/upstream.ts +81 -45
- package/std/net/url.ts +97 -13
- package/std/net/websocket.ts +122 -12
- package/std/net/webtransport.ts +220 -89
- package/std/pair.ts +10 -2
- package/std/random.ts +34 -9
- package/std/regex.ts +352 -198
- package/std/region.ts +70 -15
- package/std/secret.ts +52 -11
- package/std/sort.ts +17 -2
- package/std/sqlite.ts +256 -35
- package/std/sync/ring.ts +205 -35
- package/std/sync/shm.ts +194 -16
- package/std/term-io.ts +137 -64
- package/std/term-pixels.ts +144 -19
- package/std/term-probe.ts +66 -25
- package/std/term-rate.ts +128 -57
- package/std/term.ts +332 -121
- package/std/testing.ts +130 -32
- package/std/text.ts +73 -7
- package/std/threads.ts +229 -41
- package/std/yaml-json.ts +94 -82
- package/std/yaml-lines.ts +47 -15
- package/std/yaml-write.ts +24 -16
- package/std/yaml.ts +764 -384
package/std/cli-flags.ts
CHANGED
|
@@ -75,11 +75,27 @@ export const FLAG_ERR_UNKNOWN_COMMAND: i32 = 6
|
|
|
75
75
|
|
|
76
76
|
/** One declared flag: its name without the `--`, its `FLAG_*` kind and its help. */
|
|
77
77
|
export class FlagSpec {
|
|
78
|
+
/** @internal Used by `FlagTable`. */
|
|
78
79
|
name: string
|
|
80
|
+
/** @internal Used by `FlagTable` and `ParsedFlags`. */
|
|
79
81
|
kind: i32
|
|
82
|
+
/** @internal Used by `FlagTable`. */
|
|
80
83
|
meta: string
|
|
84
|
+
/** @internal Used by `FlagTable`. */
|
|
81
85
|
description: string
|
|
82
86
|
|
|
87
|
+
/**
|
|
88
|
+
* A flag record as `FlagTable` stores it. A program declares flags through
|
|
89
|
+
* the table's `string`, `number`, `boolean` and `repeatable` instead, which
|
|
90
|
+
* check the name first; this constructor checks nothing.
|
|
91
|
+
*
|
|
92
|
+
* @param name what follows `--` on the command line, such as `"output"`
|
|
93
|
+
* @param kind which `FLAG_*` kind the flag is, deciding whether it takes a
|
|
94
|
+
* value and which reader returns it
|
|
95
|
+
* @param meta the placeholder the help row shows for its value, such as
|
|
96
|
+
* `"<file>"`; empty for a boolean
|
|
97
|
+
* @param description the flag's line of help
|
|
98
|
+
*/
|
|
83
99
|
constructor(name: string, kind: i32, meta: string, description: string) {
|
|
84
100
|
this.name = name
|
|
85
101
|
this.kind = kind
|
|
@@ -93,11 +109,27 @@ export class FlagSpec {
|
|
|
93
109
|
* split once so that matching does not split them per parse, and its help.
|
|
94
110
|
*/
|
|
95
111
|
export class CommandSpec {
|
|
112
|
+
/** @internal Used by `FlagTable` and `ParsedFlags`. */
|
|
96
113
|
path: string
|
|
114
|
+
/** @internal Used by `FlagTable`. */
|
|
97
115
|
words: string[]
|
|
116
|
+
/** @internal Used by `FlagTable` and `ParsedFlags`. */
|
|
98
117
|
shape: string
|
|
118
|
+
/** @internal Used by `FlagTable`. */
|
|
99
119
|
description: string
|
|
100
120
|
|
|
121
|
+
/**
|
|
122
|
+
* A command record as `FlagTable` stores it. A program declares commands
|
|
123
|
+
* through `FlagTable.command` instead, which splits and checks the path;
|
|
124
|
+
* this constructor checks nothing.
|
|
125
|
+
*
|
|
126
|
+
* @param path the command's words joined by single spaces, such as
|
|
127
|
+
* `"remote add"`
|
|
128
|
+
* @param words the same words one per element, kept as given, not copied
|
|
129
|
+
* @param shape what the help row shows after the path, such as
|
|
130
|
+
* `"<name> <url>"`; may be empty
|
|
131
|
+
* @param description the command's line of help
|
|
132
|
+
*/
|
|
101
133
|
constructor(path: string, words: string[], shape: string, description: string) {
|
|
102
134
|
this.path = path
|
|
103
135
|
this.words = words
|
|
@@ -174,17 +206,27 @@ const isFlagName = (name: string): boolean => {
|
|
|
174
206
|
* program's own text and a mistake there is a bug.
|
|
175
207
|
*/
|
|
176
208
|
export class FlagTable {
|
|
209
|
+
/** @internal Used by `ParsedFlags`. */
|
|
177
210
|
program: string
|
|
211
|
+
/** @internal Used by `ParsedFlags`. */
|
|
178
212
|
flags: FlagSpec[]
|
|
213
|
+
/** @internal Used by `ParsedFlags`. */
|
|
179
214
|
commands: CommandSpec[]
|
|
180
215
|
|
|
216
|
+
/**
|
|
217
|
+
* An empty table: no flags and no commands until the declaring methods add
|
|
218
|
+
* them.
|
|
219
|
+
*
|
|
220
|
+
* @param program the program's name as usage errors and their usage line
|
|
221
|
+
* show it, such as `"git-lite"`
|
|
222
|
+
*/
|
|
181
223
|
constructor(program: string) {
|
|
182
224
|
this.program = program
|
|
183
225
|
this.flags = []
|
|
184
226
|
this.commands = []
|
|
185
227
|
}
|
|
186
228
|
|
|
187
|
-
/** The index of the flag `name` (without `--`), or `-1`. */
|
|
229
|
+
/** @internal Called by `ParsedFlags`. The index of the flag `name` (without `--`), or `-1`. */
|
|
188
230
|
indexOf(name: string): i32 {
|
|
189
231
|
for (let i: i32 = 0; i < toI32(this.flags.length); i++) {
|
|
190
232
|
if (this.flags[i].name === name) {
|
|
@@ -195,7 +237,7 @@ export class FlagTable {
|
|
|
195
237
|
}
|
|
196
238
|
|
|
197
239
|
/** A flag of `kind`, after the checks every declaring method shares. */
|
|
198
|
-
declare(name: string, kind: i32, meta: string, description: string): void {
|
|
240
|
+
private declare(name: string, kind: i32, meta: string, description: string): void {
|
|
199
241
|
if (!isFlagName(name)) {
|
|
200
242
|
panic(
|
|
201
243
|
`nish/cli-flags: a flag name is not empty and has no leading '-', '=' or whitespace, got "${name}"`
|
|
@@ -219,6 +261,13 @@ export class FlagTable {
|
|
|
219
261
|
* A command: `path` is one or more words (`"remote add"`), `shape` what
|
|
220
262
|
* follows them in the help (`"<name> <url>"`, may be empty). Declaring any
|
|
221
263
|
* command makes leading words that spell none a usage error.
|
|
264
|
+
*
|
|
265
|
+
* @param path the words a person types to choose the command, separated by
|
|
266
|
+
* whitespace; runs of whitespace collapse to one space. Panics when it has
|
|
267
|
+
* no word, a word starts with `-`, or the path is already declared
|
|
268
|
+
* @param shape what the help and the usage hint show after the path, such
|
|
269
|
+
* as `"<name> <url>"`; empty for none
|
|
270
|
+
* @param description the command's line in the `Commands` help section
|
|
222
271
|
*/
|
|
223
272
|
command(path: string, shape: string, description: string): void {
|
|
224
273
|
const words = splitWhitespace(path)
|
|
@@ -239,7 +288,16 @@ export class FlagTable {
|
|
|
239
288
|
this.commands.push(new CommandSpec(joined, words, shape, description))
|
|
240
289
|
}
|
|
241
290
|
|
|
242
|
-
/**
|
|
291
|
+
/**
|
|
292
|
+
* A string flag: `--name value` or `--name=value`, once.
|
|
293
|
+
*
|
|
294
|
+
* @param name what follows `--`, such as `"output"`; panics on a name no
|
|
295
|
+
* command line could match, one already declared, or a `no-x` beside a
|
|
296
|
+
* declared boolean `x`
|
|
297
|
+
* @param meta the placeholder the help row and the missing-value message
|
|
298
|
+
* show, such as `"<file>"`; when empty the message says "a value"
|
|
299
|
+
* @param description the flag's line in the `Flags` help section
|
|
300
|
+
*/
|
|
243
301
|
string(name: string, meta: string, description: string): void {
|
|
244
302
|
this.declare(name, FLAG_STRING, meta, description)
|
|
245
303
|
}
|
|
@@ -248,17 +306,41 @@ export class FlagTable {
|
|
|
248
306
|
* A number flag, read as an `f64`: a finite decimal (`-2.5`, `1e3`, `.5`),
|
|
249
307
|
* the same on every target. Hex, binary, `Infinity`, padding and `""` are
|
|
250
308
|
* usage errors.
|
|
309
|
+
*
|
|
310
|
+
* @param name what follows `--`, such as `"jobs"`; panics on a name no
|
|
311
|
+
* command line could match, one already declared, or a `no-x` beside a
|
|
312
|
+
* declared boolean `x`
|
|
313
|
+
* @param meta the placeholder the help row and the missing-value message
|
|
314
|
+
* show, such as `"<n>"`; when empty the message says "a value"
|
|
315
|
+
* @param description the flag's line in the `Flags` help section
|
|
251
316
|
*/
|
|
252
317
|
number(name: string, meta: string, description: string): void {
|
|
253
318
|
this.declare(name, FLAG_NUMBER, meta, description)
|
|
254
319
|
}
|
|
255
320
|
|
|
256
|
-
/**
|
|
321
|
+
/**
|
|
322
|
+
* A boolean flag: `--name` sets it, `--no-name` clears it, once.
|
|
323
|
+
*
|
|
324
|
+
* @param name what follows `--`, such as `"verbose"`; panics on a name no
|
|
325
|
+
* command line could match, one already declared, one whose `no-`
|
|
326
|
+
* form is itself a declared flag, or a `no-x` beside a declared boolean
|
|
327
|
+
* `x`
|
|
328
|
+
* @param description the flag's line in the `Flags` help section
|
|
329
|
+
*/
|
|
257
330
|
boolean(name: string, description: string): void {
|
|
258
331
|
this.declare(name, FLAG_BOOLEAN, "", description)
|
|
259
332
|
}
|
|
260
333
|
|
|
261
|
-
/**
|
|
334
|
+
/**
|
|
335
|
+
* A flag given any number of times, each with a value.
|
|
336
|
+
*
|
|
337
|
+
* @param name what follows `--`, such as `"include"`; panics on a name no
|
|
338
|
+
* command line could match, one already declared, or a `no-x` beside a
|
|
339
|
+
* declared boolean `x`
|
|
340
|
+
* @param meta the placeholder the help row and the missing-value message
|
|
341
|
+
* show, such as `"<dir>"`; when empty the message says "a value"
|
|
342
|
+
* @param description the flag's line in the `Flags` help section
|
|
343
|
+
*/
|
|
262
344
|
repeatable(name: string, meta: string, description: string): void {
|
|
263
345
|
this.declare(name, FLAG_REPEATABLE, meta, description)
|
|
264
346
|
}
|
|
@@ -268,7 +350,7 @@ export class FlagTable {
|
|
|
268
350
|
* `-1`. A path spelled by a prefix of `words` counts; the words after it
|
|
269
351
|
* are the positionals.
|
|
270
352
|
*/
|
|
271
|
-
matchCommand(words: string[]): i32 {
|
|
353
|
+
private matchCommand(words: string[]): i32 {
|
|
272
354
|
let best: i32 = -1
|
|
273
355
|
let bestLength: i32 = 0
|
|
274
356
|
for (let i: i32 = 0; i < toI32(this.commands.length); i++) {
|
|
@@ -287,7 +369,7 @@ export class FlagTable {
|
|
|
287
369
|
* including the first that no declared path continues with, so
|
|
288
370
|
* `remote rename x` against `remote add` is `"remote rename"`.
|
|
289
371
|
*/
|
|
290
|
-
unknownCommand(words: string[]): string {
|
|
372
|
+
private unknownCommand(words: string[]): string {
|
|
291
373
|
let known: i32 = 0
|
|
292
374
|
for (const c of this.commands) {
|
|
293
375
|
let k: i32 = 0
|
|
@@ -305,7 +387,14 @@ export class FlagTable {
|
|
|
305
387
|
return shown.join(" ")
|
|
306
388
|
}
|
|
307
389
|
|
|
308
|
-
/**
|
|
390
|
+
/**
|
|
391
|
+
* `args` read against the table, every one of them an argument:
|
|
392
|
+
* `parseFrom(args, 0)`.
|
|
393
|
+
*
|
|
394
|
+
* @param args the command line's words, without the program's own path
|
|
395
|
+
* @returns a fresh answer the caller owns: the usage error, or every
|
|
396
|
+
* flag's value, the command and the positionals
|
|
397
|
+
*/
|
|
309
398
|
parse(args: string[]): ParsedFlags {
|
|
310
399
|
return this.parseFrom(args, toI32(0))
|
|
311
400
|
}
|
|
@@ -315,6 +404,12 @@ export class FlagTable {
|
|
|
315
404
|
* passes `process.argv` and `1` to skip its own path. Stops at the first
|
|
316
405
|
* usage error, which the answer then carries; the command is still matched
|
|
317
406
|
* on the words read before it, so the usage hint can name it.
|
|
407
|
+
*
|
|
408
|
+
* @param args the command line's words, such as `process.argv`
|
|
409
|
+
* @param first how many leading elements of `args` to skip unread; `0`
|
|
410
|
+
* reads them all, and one at or past the end reads none
|
|
411
|
+
* @returns a fresh answer the caller owns: the usage error, or every
|
|
412
|
+
* flag's value, the command and the positionals
|
|
318
413
|
*/
|
|
319
414
|
parseFrom(args: string[], first: i32): ParsedFlags {
|
|
320
415
|
const got = new ParsedFlags(this)
|
|
@@ -409,6 +504,9 @@ export class FlagTable {
|
|
|
409
504
|
* declared (its path, shape and description), then a `Flags` section, each
|
|
410
505
|
* in declaration order. The menu's header and usage lines are the caller's,
|
|
411
506
|
* written before this.
|
|
507
|
+
*
|
|
508
|
+
* @param menu the help being written, which gains the rows; nothing is
|
|
509
|
+
* written for an empty table
|
|
412
510
|
*/
|
|
413
511
|
writeHelp(menu: HelpMenu): void {
|
|
414
512
|
if (this.commands.length > 0) {
|
|
@@ -436,20 +534,47 @@ export class FlagTable {
|
|
|
436
534
|
* given as such.
|
|
437
535
|
*/
|
|
438
536
|
export class ParsedFlags {
|
|
439
|
-
table: FlagTable
|
|
537
|
+
private table: FlagTable
|
|
538
|
+
/** Whether the parse found no usage error; `false` means `code` names one. */
|
|
440
539
|
ok: boolean
|
|
540
|
+
/** `FLAG_OK`, or the `FLAG_ERR_*` kind of the first usage error. */
|
|
441
541
|
code: i32
|
|
542
|
+
/** The usage error in words, such as `unknown flag --x`; `""` when `ok`. */
|
|
442
543
|
message: string
|
|
544
|
+
/**
|
|
545
|
+
* The argument the error was found in, as given (`--x=1` whole), or for a
|
|
546
|
+
* number flag the bad value alone and for an unknown command the words
|
|
547
|
+
* shown in the message; `""` when `ok`.
|
|
548
|
+
*/
|
|
443
549
|
argument: string
|
|
550
|
+
/** The path of the command the leading words chose, or `""` for none. */
|
|
444
551
|
command: string
|
|
552
|
+
/** @internal Used by `FlagTable`. */
|
|
445
553
|
commandAt: i32
|
|
554
|
+
/**
|
|
555
|
+
* The words that are not flags, values or the command's path, in order,
|
|
556
|
+
* then every argument after `--`. On a usage error, only those among the
|
|
557
|
+
* arguments read before the parse stopped.
|
|
558
|
+
*/
|
|
446
559
|
positionals: string[]
|
|
560
|
+
/** How many times each flag was given, indexed like the table's `flags`. */
|
|
447
561
|
counts: i32[]
|
|
562
|
+
/** Each string or number flag's value as written, `""` when not given. */
|
|
448
563
|
texts: string[]
|
|
564
|
+
/** Each number flag's value, `0` when not given. */
|
|
449
565
|
numbers: f64[]
|
|
566
|
+
/** Each boolean flag's value, `false` when not given. */
|
|
450
567
|
bools: boolean[]
|
|
568
|
+
/** Each repeatable flag's values in the order given; empty when not given. */
|
|
451
569
|
lists: string[][]
|
|
452
570
|
|
|
571
|
+
/**
|
|
572
|
+
* An answer with no error and every flag unset, which `FlagTable.parseFrom`
|
|
573
|
+
* then fills in. A program gets one from `parse` rather than building it.
|
|
574
|
+
*
|
|
575
|
+
* @param table the table whose flags this answer holds a value for each
|
|
576
|
+
* of; it is kept, not copied, and should not gain flags afterwards
|
|
577
|
+
*/
|
|
453
578
|
constructor(table: FlagTable) {
|
|
454
579
|
this.table = table
|
|
455
580
|
this.ok = true
|
|
@@ -474,7 +599,7 @@ export class ParsedFlags {
|
|
|
474
599
|
}
|
|
475
600
|
}
|
|
476
601
|
|
|
477
|
-
/** Records the first usage error; a parse stops at it. */
|
|
602
|
+
/** @internal Called by `FlagTable`. Records the first usage error; a parse stops at it. */
|
|
478
603
|
fail(code: i32, message: string, argument: string): void {
|
|
479
604
|
this.ok = false
|
|
480
605
|
this.code = code
|
|
@@ -482,7 +607,7 @@ export class ParsedFlags {
|
|
|
482
607
|
this.argument = argument
|
|
483
608
|
}
|
|
484
609
|
|
|
485
|
-
/** Stores `value` for the flag at `at`, spelled `flag` in `arg`, or fails as its kind requires. */
|
|
610
|
+
/** @internal Called by `FlagTable`. Stores `value` for the flag at `at`, spelled `flag` in `arg`, or fails as its kind requires. */
|
|
486
611
|
take(at: i32, flag: string, value: string, arg: string): void {
|
|
487
612
|
const kind = this.table.flags[at].kind
|
|
488
613
|
if (kind === FLAG_REPEATABLE) {
|
|
@@ -510,7 +635,7 @@ export class ParsedFlags {
|
|
|
510
635
|
}
|
|
511
636
|
|
|
512
637
|
/** The index of the flag `name` of `kind`; a name the table does not declare so is a bug, and panics. */
|
|
513
|
-
slot(name: string, kind: i32): i32 {
|
|
638
|
+
private slot(name: string, kind: i32): i32 {
|
|
514
639
|
const at = this.table.indexOf(name)
|
|
515
640
|
if (at < 0 || this.table.flags[at].kind !== kind) {
|
|
516
641
|
panic(`nish/cli-flags: ${this.table.program} declares no such flag --${name} of that kind`)
|
|
@@ -518,22 +643,49 @@ export class ParsedFlags {
|
|
|
518
643
|
return at
|
|
519
644
|
}
|
|
520
645
|
|
|
521
|
-
/**
|
|
646
|
+
/**
|
|
647
|
+
* A string flag's value, or `""` when it was not given.
|
|
648
|
+
*
|
|
649
|
+
* @param name the flag as declared, without `--`; panics when the table
|
|
650
|
+
* declares no string flag of that name
|
|
651
|
+
* @returns the value as it appeared on the command line
|
|
652
|
+
*/
|
|
522
653
|
str(name: string): string {
|
|
523
654
|
return this.texts[this.slot(name, FLAG_STRING)]
|
|
524
655
|
}
|
|
525
656
|
|
|
526
|
-
/**
|
|
657
|
+
/**
|
|
658
|
+
* A number flag's value, or `0` when it was not given.
|
|
659
|
+
*
|
|
660
|
+
* @param name the flag as declared, without `--`; panics when the table
|
|
661
|
+
* declares no number flag of that name
|
|
662
|
+
* @returns the finite value the command line gave
|
|
663
|
+
*/
|
|
527
664
|
num(name: string): f64 {
|
|
528
665
|
return this.numbers[this.slot(name, FLAG_NUMBER)]
|
|
529
666
|
}
|
|
530
667
|
|
|
531
|
-
/**
|
|
668
|
+
/**
|
|
669
|
+
* A boolean flag's value: true for `--name`, false for `--no-name` or when
|
|
670
|
+
* it was not given.
|
|
671
|
+
*
|
|
672
|
+
* @param name the flag as declared, without `--` or `no-`; panics when the
|
|
673
|
+
* table declares no boolean flag of that name
|
|
674
|
+
* @returns whether the flag is set
|
|
675
|
+
*/
|
|
532
676
|
bool(name: string): boolean {
|
|
533
677
|
return this.bools[this.slot(name, FLAG_BOOLEAN)]
|
|
534
678
|
}
|
|
535
679
|
|
|
536
|
-
/**
|
|
680
|
+
/**
|
|
681
|
+
* Every value a repeatable flag was given, in order; empty when it was not
|
|
682
|
+
* given.
|
|
683
|
+
*
|
|
684
|
+
* @param name the flag as declared, without `--`; panics when the table
|
|
685
|
+
* declares no repeatable flag of that name
|
|
686
|
+
* @returns a fresh array the caller owns; changing it leaves the answer as
|
|
687
|
+
* it was
|
|
688
|
+
*/
|
|
537
689
|
all(name: string): string[] {
|
|
538
690
|
const out: string[] = []
|
|
539
691
|
for (const v of this.lists[this.slot(name, FLAG_REPEATABLE)]) {
|
|
@@ -542,7 +694,14 @@ export class ParsedFlags {
|
|
|
542
694
|
return out
|
|
543
695
|
}
|
|
544
696
|
|
|
545
|
-
/**
|
|
697
|
+
/**
|
|
698
|
+
* Whether the flag `name`, of any kind, was given at all (`--no-name`
|
|
699
|
+
* counts).
|
|
700
|
+
*
|
|
701
|
+
* @param name the flag as declared, without `--`; panics when the table
|
|
702
|
+
* declares no flag of that name
|
|
703
|
+
* @returns `true` when the command line gave it at least once
|
|
704
|
+
*/
|
|
546
705
|
has(name: string): boolean {
|
|
547
706
|
const at = this.table.indexOf(name)
|
|
548
707
|
if (at < 0) {
|
|
@@ -556,7 +715,7 @@ export class ParsedFlags {
|
|
|
556
715
|
* shape, or `<command>` when the table has commands and none matched, then
|
|
557
716
|
* `[flags]`.
|
|
558
717
|
*/
|
|
559
|
-
usageLine(): string {
|
|
718
|
+
private usageLine(): string {
|
|
560
719
|
const table = this.table
|
|
561
720
|
if (this.commandAt >= 0) {
|
|
562
721
|
const c = table.commands[this.commandAt]
|
|
@@ -569,7 +728,13 @@ export class ParsedFlags {
|
|
|
569
728
|
return `usage: ${table.program} [flags]`
|
|
570
729
|
}
|
|
571
730
|
|
|
572
|
-
/**
|
|
731
|
+
/**
|
|
732
|
+
* What `exitUsage` prints: `<program>: <message>` and the usage line, each
|
|
733
|
+
* ending in a newline.
|
|
734
|
+
*
|
|
735
|
+
* @returns a fresh string; on a parse that succeeded its message part is
|
|
736
|
+
* empty
|
|
737
|
+
*/
|
|
573
738
|
usageError(): string {
|
|
574
739
|
return `${this.table.program}: ${this.message}\n${this.usageLine()}\n`
|
|
575
740
|
}
|