ref: 737f88e311ea62fbe476d59a2e4ea5bbe7889650
parent: 620e64162eb58974757a4da00e070b90db41ef0c
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Jun 23 09:35:57 EDT 2015
Clean up output of options. We don't want one '[-o]' for every argument.
--- a/libstd/optparse.myr
+++ b/libstd/optparse.myr
@@ -2,6 +2,7 @@
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 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.put("{}\n", def.argdesc)
- std.put("\t-h\tprint this help message\n")
- std.put("\t-?\tprint this help message\n")
+ std.sbfmt(sb, "] ")
for o in def.opts
- std.put("\t-{}{}{}\t{}\n", o.opt, sep(o.arg), o.arg, o.desc)
+ if o.arg.len != 0
+ std.sbfmt(sb, "[-{} {}] ", o.opt, o.arg)
+ ;;
;;
+ 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.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
--- a/mbld/parse.myr
+++ b/mbld/parse.myr
@@ -165,8 +165,8 @@
const target = {b, p
match word(p)
| `std.Some "bin": bintarget(b, p)
- | `std.Some "test": testtarget(b, p)
| `std.Some "lib": libtarget(b, p)
+ | `std.Some "test": testtarget(b, p)
| `std.Some "gen": cmdtarget(b, p, "gen", false)
| `std.Some "cmd": cmdtarget(b, p, "cmd", true)
| `std.Some "man": mantarget(b, p)