commit 656d84fd2c5ac764fbcfd0b2fd5132f85b528096
parent 5a4ab37b3f0efd141fc3929400b88b04b5aa8c40
Author: Alexey Yerin <yyp@disroot.org>
Date: Mon, 23 Aug 2021 18:03:02 +0300
getopt: do not add newline when there are no arguments
This prevents an empty line being printed when there are a lot of
options but no arguments.
For example:
const cmd = getopt::parse(os::args,
('a', "val", "..."),
('b', "val", "..."),
('c', "val", "..."),
('d', "val", "..."),
('e', "val", "..."),
);
Signed-off-by: Alexey Yerin <yyp@disroot.org>
Diffstat:
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/getopt/getopts.ha b/getopt/getopts.ha
@@ -200,10 +200,14 @@ fn _printusage(s: *io::stream, name: str, indent: bool, help: []help) size = {
};
z += fmt::fprintf(s, " [-{} <{}>]", help.0: rune, help.1) as size;
};
- if (indent) {
- z += fmt::fprintf(s, "\n\t") as size;
- };
+ let first_arg = true;
for (let i = 1z; i < len(help); i += 1) if (help[i] is cmd_help) {
+ if (first_arg) {
+ if (indent) {
+ z += fmt::fprintf(s, "\n\t") as size;
+ };
+ first_arg = false;
+ };
z += fmt::fprintf(s, " {}", help[i] as cmd_help: str) as size;
};