Skip to content

Commit

Permalink
cli: fix a panic and an infinite loop, when command flag descriptions…
Browse files Browse the repository at this point in the history
… have multiple lines (#17981)
  • Loading branch information
felipensp committed Apr 18, 2023
1 parent a84fddb commit 8445642
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 25 additions & 0 deletions vlib/cli/cli_test.v
@@ -0,0 +1,25 @@
module main

import cli { Command, Flag }

fn test_long_description() {
mut cmd := Command{
name: 'cli'
description: 'An example of the cli library.'
version: '1.0.0'
}
mut greet_cmd := Command{
name: 'greet'
description: 'Prints greeting in different languages.'
usage: '<name>'
required_args: 1
}
greet_cmd.add_flag(Flag{
flag: .string_array
name: 'fun'
description: '\'{"uri":"mqtt://broker.emqx.io:1883","topic":"test_emq/1","filters":[{"producer_id":0,"trace_group":2,"string_id":3001},{"string_id":3002}]}\''
})
cmd.add_command(greet_cmd)
cmd.setup()
cmd.parse(['cli', 'greet', '-help'])
}
4 changes: 2 additions & 2 deletions vlib/cli/help.v
Expand Up @@ -153,8 +153,8 @@ fn pretty_description(s string, indent_len int) string {
mut i := chars_per_line - 2
mut j := 0
for ; i < line.len; i += chars_per_line - 2 {
for line[i] != ` ` {
i--
for j > 0 && line[j] != ` ` {
j--
}
// indent was already done the first iteration
if j != 0 {
Expand Down

0 comments on commit 8445642

Please sign in to comment.