diff --git a/src/api/mod.rs b/src/api/mod.rs index 3f0428f..32e876e 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -187,7 +187,7 @@ impl APIClient { org_name: &str, env_name: &str, service: Service, - ) -> anyhow::Result { + ) -> anyhow::Result { let url = format!("{}/orgs/{}/envs/{}/svcs", self.base_url, org_name, env_name); let body = serde_json::to_string(&service)?; let response = self.post_str(&url, token, body)?; diff --git a/src/api/types.rs b/src/api/types.rs index 1339dcb..a73a657 100644 --- a/src/api/types.rs +++ b/src/api/types.rs @@ -51,7 +51,7 @@ pub struct Service { pub secrets: DisplayOption, } -/*#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] pub struct DeployServiceResponse { pub id: String, pub status: String, @@ -61,7 +61,7 @@ pub struct DeployServiceResponse { pub end_time: Option, pub error: Option, } -*/ + #[derive(Serialize, Deserialize, Debug)] pub struct ListSecretsResponse { pub secrets: Vec, diff --git a/src/commands/auth.rs b/src/commands/auth.rs index 2fbc725..40f9bed 100644 --- a/src/commands/auth.rs +++ b/src/commands/auth.rs @@ -108,8 +108,6 @@ impl Login { request.respond(Response::from_string("Success! You can close this tab now"))?; - return Ok(()); - Ok(()) } } diff --git a/src/commands/orgs.rs b/src/commands/orgs.rs index 08ee0ad..8d8bf98 100644 --- a/src/commands/orgs.rs +++ b/src/commands/orgs.rs @@ -5,8 +5,7 @@ use tabled::Table; use super::CommandBase; -#[derive(Parser)] -#[derive(Debug)] +#[derive(Parser, Debug)] #[command( author, version, @@ -22,16 +21,15 @@ pub struct Orgs { impl Orgs { pub fn execute(&self, base: &mut CommandBase) -> Result<()> { match &self.command { - Some(Commands::List(list)) => list.execute(&base), - Some(Commands::Create(create)) => create.execute(&base), + Some(Commands::List(list)) => list.execute(base), + Some(Commands::Create(create)) => create.execute(base), Some(Commands::Switch(switch)) => switch.execute(base), None => Ok(()), } } } -#[derive(Subcommand)] -#[derive(Debug)] +#[derive(Subcommand, Debug)] pub enum Commands { /// List your orgs List(List), @@ -41,8 +39,7 @@ pub enum Commands { Switch(Switch), } -#[derive(Parser)] -#[derive(Debug)] +#[derive(Parser, Debug)] pub struct List {} impl List { @@ -61,8 +58,7 @@ impl List { } } -#[derive(Parser)] -#[derive(Debug)] +#[derive(Parser, Debug)] pub struct Create { #[clap(short, long)] name: Option, @@ -123,11 +119,11 @@ impl CreatePlanBuilder { .unwrap(); self.name = input; - return self; } else { self.name = name.unwrap().to_string(); - return self; } + + self } pub fn billing_email(mut self, billing_email: Option<&str>) -> Self { @@ -143,7 +139,8 @@ impl CreatePlanBuilder { .unwrap(); self.billing_email = input; - return self; + + self } fn verify(&self) -> Result<()> { @@ -165,8 +162,7 @@ impl CreatePlan { } } -#[derive(Parser)] -#[derive(Debug)] +#[derive(Parser, Debug)] pub struct Switch { #[arg(help = "Name of the org to switch to")] org: Option, @@ -188,7 +184,10 @@ impl Switch { if org_names.contains(&arg_org.as_str()) { arg_org } else { - return Err(anyhow!("organization {} does not exist or you do not have access to it", arg_org)) + return Err(anyhow!( + "organization {} does not exist or you do not have access to it", + arg_org + )); } } else { let selection = FuzzySelect::with_theme(&dialoguer::theme::ColorfulTheme::default()) diff --git a/src/commands/secrets.rs b/src/commands/secrets.rs index c30d5bd..2a73a1e 100644 --- a/src/commands/secrets.rs +++ b/src/commands/secrets.rs @@ -1,7 +1,7 @@ +use super::CommandBase; use anyhow::{anyhow, Result}; use clap::{Parser, Subcommand}; use dialoguer::{FuzzySelect, Input}; -use super::CommandBase; use std::io::{self, BufRead}; use tabled::Table; @@ -25,7 +25,7 @@ impl Secrets { Some(Commands::Create(create)) => create.execute(base), Some(Commands::List(list)) => list.execute(base), Some(Commands::Delete(delete)) => delete.execute(base), - None => Ok(()) + None => Ok(()), } } } @@ -38,7 +38,7 @@ pub enum Commands { /// List secrets List(List), /// Delete a secret - Delete(Delete) + Delete(Delete), } #[derive(Debug, Parser)] @@ -68,31 +68,26 @@ impl Create { .expect("Failed to get user input") }; - base.api_client().create_secret( - token, - &org_name, - &self.env, - &self.name, - &value - )?; + base.api_client() + .create_secret(token, &org_name, &self.env, &self.name, &value)?; println!("Secret {} created", &self.name); Ok(()) } fn read_stdin(&self) -> Result { - let mut lines = io::stdin().lock().lines(); + let lines = io::stdin().lock().lines(); let mut user_input = String::new(); - while let Some(line) = lines.next() { + for line in lines { let last_input = line.unwrap(); - if last_input.len() == 0 { + if last_input.is_empty() { break; } - if user_input.len() > 0 { - user_input.push_str("\n"); + if !user_input.is_empty() { + user_input.push('\n'); } user_input.push_str(&last_input); @@ -116,11 +111,7 @@ impl List { .get_token() .ok_or_else(|| anyhow!("No token found. Please login first."))?; - let response = base.api_client().get_secrets( - token, - &org_name, - &self.env - )?; + let response = base.api_client().get_secrets(token, &org_name, &self.env)?; let table = Table::new(response.secrets).to_string(); println!("{}", table); @@ -157,12 +148,8 @@ impl Delete { .unwrap(); } - base.api_client().delete_secret( - token, - &org_name, - &self.env, - &self.name - )?; + base.api_client() + .delete_secret(token, &org_name, &self.env, &self.name)?; println!("Secret {} deleted", self.name); Ok(()) diff --git a/src/commands/services.rs b/src/commands/services.rs index 2e5cc7c..029629f 100644 --- a/src/commands/services.rs +++ b/src/commands/services.rs @@ -125,7 +125,7 @@ impl Deploy { } } - let result = base.api_client().deploy_service( + let _result = base.api_client().deploy_service( token, &org_name, &manifest.environment, @@ -154,8 +154,8 @@ impl Deploy { )) } }; - for i in 0..diffs.len() { - match diffs[i] { + for diff in &diffs { + match diff { Difference::Same(ref x) => { t.reset().unwrap(); writeln!(t, " {}", x)?; @@ -345,12 +345,12 @@ fn get_image_name( String::from_utf8_lossy(&git_output.stdout).to_string() }; - return Ok(format!( + Ok(format!( "register.molnett.org/{}/{}:{}", org_id, image_name, image_tag.trim() - )); + )) } #[derive(Parser, Debug)] diff --git a/src/main.rs b/src/main.rs index 812903f..dc1494e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,10 +4,9 @@ use camino::Utf8PathBuf; use clap::{Parser, Subcommand}; use commands::CommandBase; use dialoguer::console::style; +use reqwest::blocking::Client; use semver::Version; use serde_json::Value; -use reqwest::blocking::Client; - mod api; mod commands; @@ -74,7 +73,6 @@ enum Commands { } fn main() -> Result<()> { - let current_version = env!("CARGO_PKG_VERSION"); if let Ok(Some(new_version)) = check_newer_release(current_version) { let message = style(format!("A new version ({}) is available at https://github.com/molnett/molnctl - you are running {}\n", new_version, current_version)); @@ -93,8 +91,8 @@ fn main() -> Result<()> { match cli.command { Some(Commands::Auth(auth)) => auth.execute(&mut base), Some(Commands::Environments(environments)) => environments.execute(&mut base), - Some(Commands::Deploy(deploy)) => deploy.execute(&mut base), - Some(Commands::Logs(logs)) => logs.execute(&mut base), + Some(Commands::Deploy(deploy)) => deploy.execute(&base), + Some(Commands::Logs(logs)) => logs.execute(&base), Some(Commands::Initialize(init)) => init.execute(&mut base), Some(Commands::Orgs(orgs)) => orgs.execute(&mut base), Some(Commands::Secrets(secrets)) => secrets.execute(&mut base), @@ -106,14 +104,14 @@ fn main() -> Result<()> { pub fn check_newer_release(current_version: &str) -> Result> { let client = Client::new(); let url = "https://api.github.com/repos/molnett/molnctl/releases/latest"; - - let response = client - .get(url) - .header("User-Agent", "molnctl") - .send()?; + + let response = client.get(url).header("User-Agent", "molnctl").send()?; if !response.status().is_success() { - return Err(anyhow!("Failed to fetch release info: HTTP {}", response.status())); + return Err(anyhow!( + "Failed to fetch release info: HTTP {}", + response.status() + )); } let body: Value = response.json()?; @@ -130,4 +128,4 @@ pub fn check_newer_release(current_version: &str) -> Result> { } else { Ok(None) } -} \ No newline at end of file +}