summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2023-11-13 15:21:25 +0100
committerFxQnLr <[email protected]>2023-11-13 15:21:25 +0100
commit93de8742961287cb9cfd08e68c8afa2347585a73 (patch)
tree8689660d75d0e45af460ed3d144b5a010289c0be /src/main.rs
parent9957da9b182ca209ff8caa8f670d3bd7eff154bb (diff)
downloadwebol-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.rs17
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 @@
1use std::{fmt::Display, time::Duration}; 1use std::{fmt::Display, time::Duration};
2 2
3use clap::{Parser, Subcommand}; 3use clap::{Parser, Command, CommandFactory, Subcommand};
4use clap_complete::{generate, Shell, Generator};
4use config::SETTINGS; 5use config::SETTINGS;
5use error::CliError; 6use error::CliError;
6use indicatif::{ProgressBar, ProgressStyle, MultiProgress}; 7use 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
99fn print_completions<G: Generator>(gen: G, cmd: &mut Command) {
100 generate(gen, cmd, cmd.get_name().to_string(), &mut std::io::stdout());
101}
102
90fn default_headers() -> Result<HeaderMap, CliError> { 103fn 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());