hautils

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 88a0384d03f43cc1def1d7a45b2db0bbb8e9697a
parent 20f3d97b4135a1a36878eb0ccc9f4fc6de36a377
Author: Byron Torres <b@torresjrjr.com>
Date:   Wed,  8 Dec 2021 17:57:04 +0000

nl: improve error messages

Diffstat:
Mnl.ha | 30+++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/nl.ha b/nl.ha @@ -87,7 +87,7 @@ export fn utilmain() (void | main::error) = { case "n" => yield style::NON; case => - usage(help); + usage(help, 'b'); }; case 'd' => delim = switch (len(opt.1)) { @@ -96,7 +96,7 @@ export fn utilmain() (void | main::error) = { case 2 => yield opt.1; case => - usage(help); + usage(help, 'd'); }; case 'f' => foot_style = switch (opt.1) { @@ -107,7 +107,7 @@ export fn utilmain() (void | main::error) = { case "n" => yield style::NON; case => - usage(help); + usage(help, 'f'); }; case 'h' => head_style = switch (opt.1) { @@ -118,21 +118,21 @@ export fn utilmain() (void | main::error) = { case "n" => yield style::NON; case => - usage(help); + usage(help, 'h'); }; case 'i' => ctx.incr = match (strconv::stoi(opt.1)) { case (strconv::invalid | strconv::overflow) => - usage(help); + usage(help, 'i'); case let incr: int => yield incr; }; case 'l' => ctx.maxblanks = match (strconv::stou(opt.1)) { case (strconv::invalid | strconv::overflow) => - usage(help); + usage(help, 'l'); case let maxblanks: uint => - yield if (maxblanks > 0) maxblanks else usage(help); + yield if (maxblanks > 0) maxblanks else usage(help, 'l'); }; case 'n' => ctx.mod.padding = switch (opt.1) { @@ -143,21 +143,21 @@ export fn utilmain() (void | main::error) = { case "rz" => yield fmt::padding::ZEROES; case => - usage(help); + usage(help, 'n'); }; case 's' => ctx.sep = opt.1; case 'w' => ctx.mod.width = match (strconv::stou(opt.1)) { case (strconv::invalid | strconv::overflow) => - usage(help); + usage(help, 'w'); case let width: uint => - yield if (width > 0) width else usage(help); + yield if (width > 0) width else usage(help, 'w'); }; case 'v' => startnum = match (strconv::stoi(opt.1)) { case (strconv::invalid | strconv::overflow) => - usage(help); + usage(help, 'v'); case let startnum: int => yield startnum; }; @@ -165,7 +165,7 @@ export fn utilmain() (void | main::error) = { }; if (len(cmd.args) > 1) { - usage(help); + usage(help, void); }; const use_file = len(cmd.args) == 1 && cmd.args[0] != "-"; @@ -278,7 +278,11 @@ fn isblank(line: str) bool = { return true; }; -@noreturn fn usage(help: []getopt::help) void = { +@noreturn fn usage(help: []getopt::help, flag: (rune | void)) void = { + if (flag is rune) { + fmt::errorfln("{}: invalid option parameter for -{}", + os::args[0], flag: rune)!; + }; getopt::printusage(os::stderr, os::args[0], help); os::exit(1); };