cli: fix issue with long cmd and flag names
parent
051cc732bb
commit
7bfc3ef767
|
@ -42,10 +42,10 @@ fn help_func(help_cmd Command) {
|
||||||
for flag in cmd.flags {
|
for flag in cmd.flags {
|
||||||
mut flag_name := ''
|
mut flag_name := ''
|
||||||
if flag.abbrev != '' {
|
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}'
|
flag_name = '-${flag.abbrev}${abbrev_indent}--${flag.name}'
|
||||||
} else {
|
} 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}'
|
flag_name = '${abbrev_indent}--${flag.name}'
|
||||||
}
|
}
|
||||||
mut required := ''
|
mut required := ''
|
||||||
|
@ -54,7 +54,7 @@ fn help_func(help_cmd Command) {
|
||||||
}
|
}
|
||||||
|
|
||||||
base_indent := ' '.repeat(BASE_INDENT)
|
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 += '${base_indent}${flag_name}${description_indent}${flag.description}${required}\n'
|
||||||
}
|
}
|
||||||
help += '\n'
|
help += '\n'
|
||||||
|
@ -63,7 +63,7 @@ fn help_func(help_cmd Command) {
|
||||||
help += 'Commands:\n'
|
help += 'Commands:\n'
|
||||||
for command in cmd.commands {
|
for command in cmd.commands {
|
||||||
base_indent := ' '.repeat(BASE_INDENT)
|
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'
|
help += '${base_indent}${command.name}${description_indent}${command.description}\n'
|
||||||
}
|
}
|
||||||
|
@ -72,3 +72,7 @@ fn help_func(help_cmd Command) {
|
||||||
|
|
||||||
print(help)
|
print(help)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn max(a, b int) int {
|
||||||
|
return if a > b {a} else {b}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue