raz / commit 90cd0ae0

commit
90cd0ae0e3628a82c433cc44d974b6f7c9798b40
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
8ed26889
Opt.at: where the operands are

patch · log

2 files changed, +21 -7

lib/Opt.raz (history) modified +16 -7

@@ -347,6 +347,15 @@
347347 return Files.arg(p^.at - 1), true;
348348 end;
349349
350+(* The number of the argument operand would give next, after what
351+ options are left: the operands from there on are Files.arg(i), for
352+ i up to ARGC() - 1, as an interpreter hands them to its script. *)
353+proc at*(p: ^Parser): INT;
354+begin
355+ while next(p) do end;
356+ return p^.at;
357+end;
358+
350359 (* The options of the subcommand name, from the word after its own,
351360 which operand has given. *)
352361 proc scope*(p: ^Parser; name: []U8);
@@ -387,7 +396,7 @@
387396 no synopsis lines; and holds each to what it writes, and its status. *)
388397 proc keep;
389398 const wait = 1;
390-var p: Parser; verbose, ok: BOOL; secs: I64; bar, job, w: []U8; b: Buf.Buf;
399+var p: Parser; verbose, ok: BOOL; secs: I64; bar, job, w: []U8; b: Buf.Buf; i: INT;
391400 begin
392401 secs := 10;
393402 init(ADR(p), "keep", [
@@ -414,16 +423,15 @@
414423 if p.letter = 'b' then bar := p.value; end;
415424 end;
416425 job, ok := operand(ADR(p));
417- w, ok := operand(ADR(p));
418- if not ok then fail(ADR(p), "start needs a name and a command; see keep start -h"); end;
426+ (* the command and its arguments, as they are, by at *)
427+ if not ok or (at(ADR(p)) >= ARGC()) then
428+ fail(ADR(p), "start needs a name and a command; see keep start -h");
429+ end;
419430 if verbose then Fmt.print("waiting {}s\n", [Fmt.int(secs)]); end;
420431 Fmt.print("job {}", [Fmt.str(job)]);
421432 if LEN(bar) > 0 then Fmt.print(" [{}]", [Fmt.str(bar)]); end;
422433 Fmt.print(":", []);
423- while ok do
424- Fmt.print(" {}", [Fmt.str(w)]);
425- w, ok := operand(ADR(p));
426- end;
434+ for i := at(ADR(p)) to ARGC() - 1 do Fmt.print(" {}", [Fmt.str(Files.arg(i))]); end;
427435 Fmt.print("\n", []);
428436 end;
429437
@@ -512,6 +520,7 @@
512520 {mode: k, args: ["keep", "start", "-", "c", "--", "-h"], out: "job -: c -- -h\n"},
513521 {mode: k, args: ["keep", "start", "n", "c", "-b", "x"], out: "job n: c -b x\n"},
514522 {mode: k, args: ["keep", "start", "-bh", "n", "c"], out: "job n [h]: c\n"},
523+ {mode: k, args: ["keep", "start", "-b", "x", "n"], err: "keep: start needs a name and a command; see keep start -h\n", status: 2},
515524 {mode: k, args: ["keep", "-h"], out: keepHelp},
516525 {mode: k, args: ["keep", "-v", "--help", "-x"], out: keepHelp},
517526 {mode: k, args: ["keep", "-vh"], out: keepHelp},

test/doc/Opt.expect (history) modified +5 -0

@@ -43,6 +43,11 @@
4343 The next operand, after what options are left; false when there are
4444 no more.
4545
46+proc at*(p: ^Parser): INT;
47+ The number of the argument operand would give next, after what
48+ options are left: the operands from there on are Files.arg(i), for
49+ i up to ARGC() - 1, as an interpreter hands them to its script.
50+
4651 proc scope*(p: ^Parser; name: []U8);
4752 The options of the subcommand name, from the word after its own,
4853 which operand has given.