]>
Commit | Line | Data |
---|---|---|
ca60ac13 DM |
1 | use failure::*; |
2 | use serde_json::Value; | |
3 | ||
4 | use proxmox::{sortable, identity}; | |
5 | use proxmox::api::*; | |
6 | use proxmox::api::schema::*; | |
7 | ||
8 | use proxmox_backup::cli::*; | |
9 | ||
10 | #[sortable] | |
11 | const API_METHOD_TEST_COMMAND: ApiMethod = ApiMethod::new( | |
12 | &ApiHandler::Sync(&test_command), | |
13 | &ObjectSchema::new( | |
14 | "Test command.", | |
15 | &sorted!([ | |
16 | ( "verbose", true, &BooleanSchema::new("Verbose output.").schema() ), | |
17 | ]) | |
18 | ) | |
19 | ); | |
20 | ||
21 | fn test_command( | |
22 | _param: Value, | |
23 | _info: &ApiMethod, | |
24 | _rpcenv: &mut dyn RpcEnvironment, | |
25 | ) -> Result<Value, Error> { | |
26 | ||
27 | ||
28 | Ok(Value::Null) | |
29 | } | |
30 | ||
31 | fn command_map() -> CliCommandMap { | |
32 | let cmd_def = CliCommandMap::new() | |
33 | .insert("ls", CliCommand::new(&API_METHOD_TEST_COMMAND).into()) | |
34 | .insert("test", CliCommand::new(&API_METHOD_TEST_COMMAND).into()) | |
35 | .insert("help", help_command_def().into()); | |
36 | ||
37 | cmd_def | |
38 | } | |
39 | ||
40 | ||
41 | fn main() -> Result<(), Error> { | |
42 | ||
43 | let def = CommandLineInterface::Nested(command_map()); | |
44 | ||
45 | let helper = CliHelper::new(def); | |
46 | ||
47 | let config = rustyline::config::Builder::new() | |
48 | //.completion_type(rustyline::config::CompletionType::List) | |
49 | //.completion_prompt_limit(0) | |
50 | .build(); | |
51 | ||
52 | let mut rl = rustyline::Editor::<CliHelper>::with_config(config); | |
53 | rl.set_helper(Some(helper)); | |
54 | ||
55 | while let Ok(line) = rl.readline("# prompt: ") { | |
56 | let helper = rl.helper().unwrap(); | |
57 | // readline already handles tabs, so here we only split on spaces | |
58 | let args = shellword_split(&line)?; | |
59 | ||
60 | let def = helper.cmd_def(); | |
61 | let _ = match def { | |
62 | CommandLineInterface::Simple(ref cli_cmd) => { | |
63 | handle_simple_command(def, "", &cli_cmd, args) | |
64 | } | |
65 | CommandLineInterface::Nested(ref map) => { | |
66 | handle_nested_command(def, "", &map, args) | |
67 | } | |
68 | }; | |
69 | } | |
70 | ||
71 | Ok(()) | |
72 | } |