mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
@ -186,33 +186,29 @@ fn (mut cmd Command) parse_commands() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if no further command was found, execute current command
|
// if no further command was found, execute current command
|
||||||
if int(cmd.execute) == 0 {
|
if cmd.required_args > 0 {
|
||||||
if !cmd.disable_help {
|
if cmd.required_args > cmd.args.len {
|
||||||
cmd.execute_help()
|
eprintln('Command `$cmd.name` needs at least $cmd.required_args arguments')
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if cmd.required_args > 0 {
|
|
||||||
if cmd.required_args > cmd.args.len {
|
|
||||||
println('Command `$cmd.name` needs at least $cmd.required_args arguments')
|
|
||||||
exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cmd.check_required_flags()
|
|
||||||
if int(cmd.pre_execute) > 0 {
|
|
||||||
cmd.pre_execute(*cmd) or {
|
|
||||||
println('cli preexecution error: $err')
|
|
||||||
exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cmd.execute(*cmd) or {
|
|
||||||
println('cli execution error: $err')
|
|
||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
if int(cmd.post_execute) > 0 {
|
}
|
||||||
cmd.post_execute(*cmd) or {
|
cmd.check_required_flags()
|
||||||
println('cli postexecution error: $err')
|
if int(cmd.pre_execute) > 0 {
|
||||||
exit(1)
|
cmd.pre_execute(*cmd) or {
|
||||||
}
|
eprintln('cli preexecution error: $err')
|
||||||
|
exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if int(cmd.execute) > 0 {
|
||||||
|
cmd.execute(*cmd) or {
|
||||||
|
eprintln('cli execution error: $err')
|
||||||
|
exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if int(cmd.post_execute) > 0 {
|
||||||
|
cmd.post_execute(*cmd) or {
|
||||||
|
eprintln('cli postexecution error: $err')
|
||||||
|
exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
0
vlib/v/tests/inout/cli_command_no_execute.out
Normal file
0
vlib/v/tests/inout/cli_command_no_execute.out
Normal file
7
vlib/v/tests/inout/cli_command_no_execute.vv
Normal file
7
vlib/v/tests/inout/cli_command_no_execute.vv
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import os
|
||||||
|
import cli {Command}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
mut cmd := Command {}
|
||||||
|
cmd.parse(os.args)
|
||||||
|
}
|
Reference in New Issue
Block a user