hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit f1a8178e59a55fb2c9fcf3b57964a73e69f2d84d
parent 8293b7f79076b9524ce1415a7d1fba653c9b5334
Author: Alexey Yerin <yyp@disroot.org>
Date:   Tue, 20 Apr 2021 11:57:40 +0300

haredoc: show usage if given not enough arguments

Diffstat:
Mcmd/haredoc/main.ha | 10+++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/cmd/haredoc/main.ha b/cmd/haredoc/main.ha @@ -31,12 +31,13 @@ export fn main() void = { // TODO: Use format::TTY by default if stdout is a tty let fmt = format::HARE; let template = true; - const cmd = getopt::parse(os::args, + const help: [_]getopt::help = [ "reads and formats Hare documentation", ('F', "format", "specify output format (hare, tty, html, or gemtext)"), ('t', "disable HTML template (requries postprocessing)"), "[identifiers...]", - ); + ]; + const cmd = getopt::parse(os::args, help...); defer getopt::finish(&cmd); for (let i = 0z; i < len(cmd.opts); i += 1) { @@ -62,7 +63,10 @@ export fn main() void = { let ctx = module::context_init(tags, [], default_harepath()); defer module::context_finish(&ctx); - assert(len(cmd.args) == 1); // TODO: Something more sophisticated here + if (len(cmd.args) < 1) { + getopt::printusage(os::stderr, os::args[0], help); + os::exit(1); + }; const id = match (parse::identstr(cmd.args[0])) { err: parse::error => fmt::fatal(parse::strerror(err)),