commit e310196c749ed183419d36214e42262703607838
parent 16941c46e1bb174670c85668cef6bbecd91e3f45
Author: Drew DeVault <sir@cmpwn.com>
Date: Sat, 27 Mar 2021 09:41:13 -0400
cmd/harec: print usage and exit if no inputs
Diffstat:
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/cmd/harec/main.ha b/cmd/harec/main.ha
@@ -8,29 +8,35 @@ use io;
use os;
export fn main() void = {
- let cmd = getopt::parse(os::args,
+ let usage: []getopt::help = [
"compiles Hare programs to an intermediate form",
('D', "ident:type=value", "defines a constant"),
- ('o', "path", "set the output file"),
('T', "tags...", "sets build tags"),
- ('t', "path", "write typedefs to a file"),
('N', "ident", "set the namespace for unit"),
- "files..."
- );
+ ('o', "path", "set the output file"),
+ ('t', "path", "write typedefs to a file"),
+ "files...",
+ ];
+ let cmd = getopt::parse(os::args, usage...);
defer getopt::finish(&cmd);
for (let i = 0z; i < len(cmd.opts); i += 1) {
let opt = cmd.opts[i];
switch (opt.0) {
'D' => abort(), // TODO
- 'o' => abort(), // TODO
+ 'N' => abort(), // TODO
'T' => abort(), // TODO
+ 'o' => abort(), // TODO
't' => abort(), // TODO
- 'N' => abort(), // TODO
* => abort(),
};
};
+ if (len(cmd.args) == 0) {
+ getopt::printusage(os::stderr, os::args[0], usage);
+ os::exit(1);
+ };
+
for (let i = 0z; i < len(cmd.args); i += 1) {
let input = match (os::open(cmd.args[i])) {
f: *io::stream => f,