Template for interactive programs, which will be written in V.
Includes a small amount of built-in features:
- Help message printing (just
help
and alsohelp <command>
) - Aliases (for example you can use
q
instead ofquit
)
To create a new command follow the steps:
- Create structure based on
Command
interface like existing one:
struct CommandEcho {
mut:
name string = 'echo'
description string = 'Prints the given text to the console.'
aliases []string
cmdhandler &CommandHandler
}
-
Add
print_help
andrun
functions to your structure -
Add created structure to
CommandHandler
(init
function):
fn (mut c CommandHandler) init() {
// Put new commands here
c.add_command(CommandEcho{ cmdhandler: &c })
c.add_command(CommandQuit{ cmdhandler: &c })
c.add_command(CommandHelp{ cmdhandler: &c })
}