]>
git.proxmox.com Git - proxmox-backup.git/blob - examples/completion.rs
3 use proxmox
::api
::{*, cli::*}
;
10 description
: "Some text.",
15 /// Echo command. Print the passed text.
20 ) -> Result
<(), Error
> {
31 description
: "Verbose output.",
40 verbose
: Option
<bool
>,
41 ) -> Result
<(), Error
> {
42 if verbose
.unwrap_or(false) {
43 println
!("Hello, how are you!");
51 #[api(input: { properties: {} })]
52 /// Quit command. Exit the program.
55 fn quit_command() -> Result
<(), Error
> {
59 std
::process
::exit(0);
62 fn cli_definition() -> CommandLineInterface
{
63 let cmd_def
= CliCommandMap
::new()
64 .insert("quit", CliCommand
::new(&API_METHOD_QUIT_COMMAND
))
65 .insert("hello", CliCommand
::new(&API_METHOD_HELLO_COMMAND
))
66 .insert("echo", CliCommand
::new(&API_METHOD_ECHO_COMMAND
)
71 CommandLineInterface
::Nested(cmd_def
)
74 fn main() -> Result
<(), Error
> {
76 let helper
= CliHelper
::new(cli_definition());
78 let mut rl
= rustyline
::Editor
::<CliHelper
>::new();
79 rl
.set_helper(Some(helper
));
81 while let Ok(line
) = rl
.readline("# prompt: ") {
82 let helper
= rl
.helper().unwrap();
84 let args
= shellword_split(&line
)?
;
86 let rpcenv
= CliEnvironment
::new();
87 let _
= handle_command(helper
.cmd_def(), "", args
, rpcenv
, None
);
89 rl
.add_history_entry(line
);