raz / commit 9dfe9b61

commit
9dfe9b61c8f8ea8d99bbed2ed7c48dc6f8db3837
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
6e2a4e15
Opt.number with no top: from lo up

A number with no top is given the largest I64 for hi, and the message
read --budget wants a number from 0 to 9223372036854775807. It now
reads from 0 up; nothing else changes. Tested in Opt's own cases with
--jobs; its proposal is removed.

patch · log

3 files changed, +16 -12

PROPOSALS.md modified +0 -8

@@ -671,11 +671,3 @@
671671 value optional, given only as `--color=WHEN` (never as the next
672672 argument, as getopt's `::` has it), `""` when left out; for a letter,
673673 only joined, `-cWHEN`. It breaks no program.
674-
675-## `Opt.number` with no top
676-
677-`Opt.number(p, lo, hi)` refuses a value past `hi` and says so; a
678-number that has no top is given `hi` as `I64`'s largest, and the
679-message reads `--budget wants a number from 0 to
680-9223372036854775807`. The proposal: the message says `a number from
681-0 up` when `hi` is the largest `I64`; nothing else changes.

doc/raz-lib.md (history) modified +2 -1

@@ -918,7 +918,8 @@
918918
919919 The sentences are `unknown option -x` (or `--name`, up to its `=`),
920920 `-b needs a label`, `--follow takes no value` and `--wait wants a
921-number from 1 to 600, not '0'`. `fail` writes the program's own
921+number from 1 to 600, not '0'`; for a number with no top, given the
922+largest `I64` for `hi`, `--jobs wants a number from 1 up, not '0'`. `fail` writes the program's own
922923 mistakes the same way, but alone, so that the sentence can say where
923924 the help is: `keep: no command; see keep -h`.
924925

lib/Opt.raz (history) modified +14 -3

@@ -35,6 +35,8 @@
3535 (* What read makes of a word or a letter. *)
3636 const read1 = 1; readEnd = 0; readSkip = -1;
3737
38+const largest = 9223372036854775807; (* the largest I64, a number with no top *)
39+
3840 (* b written whole to fd, then freed. *)
3941 proc say(fd: INT; b: ^Buf.Buf);
4042 var s: []U8; n: INT;
@@ -367,12 +369,17 @@
367369 end;
368370
369371 (* The value of the option just read, as a whole number from lo to hi;
370- anything else is a mistake. *)
372+ anything else is a mistake. A number with no top is given the
373+ largest I64 for hi, and the mistake says "from lo up". *)
371374 proc number*(p: ^Parser; lo, hi: I64): I64;
372375 var n: I64; ok: BOOL;
373376 begin
374377 n, ok := Str.toInt(p^.value);
375378 if not ok or (n < lo) or (n > hi) then
379+ if hi = largest then
380+ refuse(p, "{}{} wants a number from {} up, not '{}'",
381+ [Fmt.str(dashes(p)), Fmt.str(p^.spelt), Fmt.int(lo), Fmt.str(p^.value)]);
382+ end;
376383 refuse(p, "{}{} wants a number from {} to {}, not '{}'",
377384 [Fmt.str(dashes(p)), Fmt.str(p^.spelt), Fmt.int(lo), Fmt.int(hi), Fmt.str(p^.value)]);
378385 end;
@@ -395,7 +402,7 @@
395402 program of getopt's page, or a program with a bad table, or one with
396403 no synopsis lines; and holds each to what it writes, and its status. *)
397404 proc keep;
398-const wait = 1;
405+const wait = 1; jobs = 2;
399406 var p: Parser; verbose, ok: BOOL; secs: I64; bar, job, w: []U8; b: Buf.Buf; i: INT;
400407 begin
401408 secs := 10;
@@ -404,11 +411,13 @@
404411 sub("", "start", "start a job"),
405412 option("", 'v', "verbose", "", "say more"),
406413 option("", wait, "wait", "secs", "give the job secs to start"),
414+ option("", jobs, "jobs", "n", "keep n jobs at most"),
407415 usage("start", "keep start [-b label] name command [argument ...]"),
408416 option("start", 'b', "bar", "label", "show the job in the bar as label")]);
409417 while next(ADR(p)) do
410418 if p.letter = 'v' then verbose := true;
411419 elsif p.letter = wait then secs := number(ADR(p), 1, 600);
420+ elsif p.letter = jobs then _ := number(ADR(p), 1, largest);
412421 end;
413422 end;
414423 w, ok := operand(ADR(p));
@@ -499,7 +508,7 @@
499508
500509 proc main*;
501510 const
502- keepHelp = "usage: keep [-v] [--wait secs] start ...\n\n start start a job\n -v, --verbose say more\n --wait secs give the job secs to start\n -h, --help print this and exit\n";
511+ keepHelp = "usage: keep [-v] [--wait secs] start ...\n\n start start a job\n -v, --verbose say more\n --wait secs give the job secs to start\n --jobs n keep n jobs at most\n -h, --help print this and exit\n";
503512 startHelp = "usage: keep start [-b label] name command [argument ...]\n\n -b, --bar label show the job in the bar as label\n -h, --help print this and exit\n";
504513 k = "OPTTEST=keep";
505514 var cases: []Case; i: INT; mode: []U8;
@@ -536,6 +545,8 @@
536545 {mode: k, args: ["keep", "--wait", "0", "start", "a", "b"],
537546 err: "keep: --wait wants a number from 1 to 600, not '0'\nusage: keep [-v] [--wait secs] start ...\n", status: 2},
538547 {mode: k, args: ["keep", "--wait=9x", "start"], err: "keep: --wait wants a number from 1 to 600, not '9x'\nusage: keep [-v] [--wait secs] start ...\n", status: 2},
548+ {mode: k, args: ["keep", "--jobs=0", "start"], err: "keep: --jobs wants a number from 1 up, not '0'\nusage: keep [-v] [--wait secs] start ...\n", status: 2},
549+ {mode: k, args: ["keep", "--jobs", "9223372036854775807", "start", "n", "c"], out: "job n: c\n"},
539550 {mode: "OPTTEST=bad", args: ["bad", "-v"], err: "bad: option table, row 2: the option is in the scope already\n", status: 1},
540551 {mode: "OPTTEST=plain", args: ["plain", "remote", "add", "-f", "--force"], out: "f\nf\n"},
541552 {mode: "OPTTEST=plain", args: ["plain", "remote", "add", "-x"], err: "plain: unknown option -x\nusage: plain remote add\n", status: 2},