From 7bfc3ef7675bc27230180bfaabf62fe34457afe7 Mon Sep 17 00:00:00 2001 From: Major Taylor Date: Thu, 16 Apr 2020 17:01:04 -0400 Subject: [PATCH] cli: fix issue with long cmd and flag names --- vlib/cli/help.v | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/vlib/cli/help.v b/vlib/cli/help.v index 4e8c159b16..d1ec96e110 100644 --- a/vlib/cli/help.v +++ b/vlib/cli/help.v @@ -42,10 +42,10 @@ fn help_func(help_cmd Command) { for flag in cmd.flags { mut flag_name := '' if flag.abbrev != '' { - abbrev_indent := ' '.repeat(ABBREV_INDENT-(flag.abbrev.len+1)) + abbrev_indent := ' '.repeat(max(ABBREV_INDENT-(flag.abbrev.len+1), 1)) flag_name = '-${flag.abbrev}${abbrev_indent}--${flag.name}' } else { - abbrev_indent := ' '.repeat(ABBREV_INDENT-(flag.abbrev.len)) + abbrev_indent := ' '.repeat(max(ABBREV_INDENT-(flag.abbrev.len), 1)) flag_name = '${abbrev_indent}--${flag.name}' } mut required := '' @@ -54,7 +54,7 @@ fn help_func(help_cmd Command) { } base_indent := ' '.repeat(BASE_INDENT) - description_indent := ' '.repeat(DESCRIPTION_INDENT-flag_name.len) + description_indent := ' '.repeat(max(DESCRIPTION_INDENT-flag_name.len, 1)) help += '${base_indent}${flag_name}${description_indent}${flag.description}${required}\n' } help += '\n' @@ -63,7 +63,7 @@ fn help_func(help_cmd Command) { help += 'Commands:\n' for command in cmd.commands { base_indent := ' '.repeat(BASE_INDENT) - description_indent := ' '.repeat(DESCRIPTION_INDENT-command.name.len) + description_indent := ' '.repeat(max(DESCRIPTION_INDENT-command.name.len, 1)) help += '${base_indent}${command.name}${description_indent}${command.description}\n' } @@ -72,3 +72,7 @@ fn help_func(help_cmd Command) { print(help) } + +fn max(a, b int) int { + return if a > b {a} else {b} +}