summaryrefslogtreecommitdiff
path: root/libstd
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-06-23 13:35:57 -0700
committerOri Bernstein <ori@eigenstate.org>2015-06-23 13:35:57 -0700
commit737f88e311ea62fbe476d59a2e4ea5bbe7889650 (patch)
tree6816ae7a613dbbd793f6ae47784853153f17c2d9 /libstd
parent620e64162eb58974757a4da00e070b90db41ef0c (diff)
downloadmc-737f88e311ea62fbe476d59a2e4ea5bbe7889650.tar.gz
Clean up output of options.
We don't want one '[-o]' for every argument.
Diffstat (limited to 'libstd')
-rw-r--r--libstd/optparse.myr27
1 files changed, 21 insertions, 6 deletions
diff --git a/libstd/optparse.myr b/libstd/optparse.myr
index 9d5cdbb..ae65b77 100644
--- a/libstd/optparse.myr
+++ b/libstd/optparse.myr
@@ -2,6 +2,7 @@ use "alloc.use"
use "die.use"
use "extremum.use"
use "fmt.use"
+use "strbuf.use"
use "option.use"
use "sleq.use"
use "slpush.use"
@@ -174,16 +175,30 @@ const next = {ctx
}
const optusage = {prog, def
- std.put("usage: {} [-h?] ", prog)
+ var sb, s
+
+ sb = mksb()
+ std.sbfmt(sb, "usage: {} [-h?", prog)
for o in def.opts
- std.put("[-{}{}{}] ", o.opt, sep(o.arg), o.arg)
+ if o.arg.len == 0
+ std.sbfmt(sb, "{}", o.opt)
+ ;;
+ ;;
+ std.sbfmt(sb, "] ")
+ for o in def.opts
+ if o.arg.len != 0
+ std.sbfmt(sb, "[-{} {}] ", o.opt, o.arg)
+ ;;
;;
- std.put("{}\n", def.argdesc)
- std.put("\t-h\tprint this help message\n")
- std.put("\t-?\tprint this help message\n")
+ std.sbfmt(sb, "{}\n", def.argdesc)
+ std.sbfmt(sb, "\t-h\tprint this help message\n")
+ std.sbfmt(sb, "\t-?\tprint this help message\n")
for o in def.opts
- std.put("\t-{}{}{}\t{}\n", o.opt, sep(o.arg), o.arg, o.desc)
+ std.sbfmt(sb, "\t-{}{}{}\t{}\n", o.opt, sep(o.arg), o.arg, o.desc)
;;
+ s = sbfin(sb)
+ write(1, s)
+ slfree(s)
}
const sep = {s