]>
git.proxmox.com Git - proxmox-backup.git/blob - examples/completion.rs
4 use proxmox_router
::cli
::*;
11 description
: "Some text.",
16 /// Echo command. Print the passed text.
21 ) -> Result
<(), Error
> {
32 description
: "Verbose output.",
41 verbose
: Option
<bool
>,
42 ) -> Result
<(), Error
> {
43 if verbose
.unwrap_or(false) {
44 println
!("Hello, how are you!");
52 #[api(input: { properties: {} })]
53 /// Quit command. Exit the program.
56 fn quit_command() -> Result
<(), Error
> {
60 std
::process
::exit(0);
63 fn cli_definition() -> CommandLineInterface
{
64 let cmd_def
= CliCommandMap
::new()
65 .insert("quit", CliCommand
::new(&API_METHOD_QUIT_COMMAND
))
66 .insert("hello", CliCommand
::new(&API_METHOD_HELLO_COMMAND
))
67 .insert("echo", CliCommand
::new(&API_METHOD_ECHO_COMMAND
)
72 CommandLineInterface
::Nested(cmd_def
)
75 fn main() -> Result
<(), Error
> {
77 let helper
= CliHelper
::new(cli_definition());
79 let mut rl
= rustyline
::Editor
::<CliHelper
>::new();
80 rl
.set_helper(Some(helper
));
82 while let Ok(line
) = rl
.readline("# prompt: ") {
83 let helper
= rl
.helper().unwrap();
85 let args
= shellword_split(&line
)?
;
87 let rpcenv
= CliEnvironment
::new();
88 let _
= handle_command(helper
.cmd_def(), "", args
, rpcenv
, None
);
90 rl
.add_history_entry(line
);