cli: show help for empty root command (#6636)

pull/6640/head
Lukas Neubert 2020-10-17 18:06:27 +02:00 committed by GitHub
parent 3c2202572b
commit dea8662d6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 3 deletions

View File

@ -185,6 +185,12 @@ fn (mut cmd Command) parse_commands() {
}
}
}
if cmd.is_root() && int(cmd.execute) == 0 {
if !cmd.disable_help {
cmd.execute_help()
return
}
}
// if no further command was found, execute current command
if cmd.required_args > 0 {
if cmd.required_args > cmd.args.len {

View File

@ -1,7 +1,11 @@
import os
import cli {Command}
fn main() {
mut cmd := Command {}
cmd.parse(os.args)
mut cmd := Command {
name: 'cmd'
}
cmd.add_command({
name: 'foo'
})
cmd.parse(['', 'cmd', 'foo'])
}

View File

@ -0,0 +1,7 @@
Usage: [flags] [commands]
Flags:
-help Prints help information.
Commands:
help Prints help information.

View File

@ -0,0 +1,7 @@
import cli {Command}
import os
fn main() {
mut cmd := Command {}
cmd.parse(os.args)
}