diff options
author | FxQnLr <[email protected]> | 2023-11-13 15:21:25 +0100 |
---|---|---|
committer | FxQnLr <[email protected]> | 2023-11-13 15:21:25 +0100 |
commit | 93de8742961287cb9cfd08e68c8afa2347585a73 (patch) | |
tree | 8689660d75d0e45af460ed3d144b5a010289c0be /src/main.rs | |
parent | 9957da9b182ca209ff8caa8f670d3bd7eff154bb (diff) | |
download | webol-cli-93de8742961287cb9cfd08e68c8afa2347585a73.tar webol-cli-93de8742961287cb9cfd08e68c8afa2347585a73.tar.gz webol-cli-93de8742961287cb9cfd08e68c8afa2347585a73.zip |
add completion and cargo update
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 204e671..afe6fac 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,6 +1,7 @@ | |||
1 | use std::{fmt::Display, time::Duration}; | 1 | use std::{fmt::Display, time::Duration}; |
2 | 2 | ||
3 | use clap::{Parser, Subcommand}; | 3 | use clap::{Parser, Command, CommandFactory, Subcommand}; |
4 | use clap_complete::{generate, Shell, Generator}; | ||
4 | use config::SETTINGS; | 5 | use config::SETTINGS; |
5 | use error::CliError; | 6 | use error::CliError; |
6 | use indicatif::{ProgressBar, ProgressStyle, MultiProgress}; | 7 | use indicatif::{ProgressBar, ProgressStyle, MultiProgress}; |
@@ -39,7 +40,10 @@ enum Commands { | |||
39 | Device { | 40 | Device { |
40 | #[command(subcommand)] | 41 | #[command(subcommand)] |
41 | devicecmd: DeviceCmd, | 42 | devicecmd: DeviceCmd, |
42 | } | 43 | }, |
44 | CliGen { | ||
45 | id: Shell, | ||
46 | }, | ||
43 | } | 47 | } |
44 | 48 | ||
45 | #[derive(Subcommand)] | 49 | #[derive(Subcommand)] |
@@ -81,12 +85,21 @@ async fn main() -> Result<(), CliError> { | |||
81 | device::post(id, mac, broadcast_addr, ip).await?; | 85 | device::post(id, mac, broadcast_addr, ip).await?; |
82 | }, | 86 | }, |
83 | } | 87 | } |
88 | }, | ||
89 | Commands::CliGen { id } => { | ||
90 | eprintln!("Generating completion file for {id:?}..."); | ||
91 | let mut cmd = Args::command(); | ||
92 | print_completions(id, &mut cmd) | ||
84 | } | 93 | } |
85 | } | 94 | } |
86 | 95 | ||
87 | Ok(()) | 96 | Ok(()) |
88 | } | 97 | } |
89 | 98 | ||
99 | fn print_completions<G: Generator>(gen: G, cmd: &mut Command) { | ||
100 | generate(gen, cmd, cmd.get_name().to_string(), &mut std::io::stdout()); | ||
101 | } | ||
102 | |||
90 | fn default_headers() -> Result<HeaderMap, CliError> { | 103 | fn default_headers() -> Result<HeaderMap, CliError> { |
91 | let mut map = HeaderMap::new(); | 104 | let mut map = HeaderMap::new(); |
92 | map.append("Accept-Content", HeaderValue::from_str("application/json").unwrap()); | 105 | map.append("Accept-Content", HeaderValue::from_str("application/json").unwrap()); |