Skip to content

Commit

Permalink
fix: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
bittermandel committed Dec 7, 2024
1 parent c826543 commit 62abb07
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl APIClient {
org_name: &str,
env_name: &str,
service: Service,
) -> anyhow::Result<Service> {
) -> anyhow::Result<DeployServiceResponse> {
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)?;
Expand Down
4 changes: 2 additions & 2 deletions src/api/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub struct Service {
pub secrets: DisplayOption<DisplayHashMap>,
}

/*#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct DeployServiceResponse {
pub id: String,
pub status: String,
Expand All @@ -61,7 +61,7 @@ pub struct DeployServiceResponse {
pub end_time: Option<OffsetDateTime>,
pub error: Option<String>,
}
*/

#[derive(Serialize, Deserialize, Debug)]
pub struct ListSecretsResponse {
pub secrets: Vec<Secret>,
Expand Down
2 changes: 0 additions & 2 deletions src/commands/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ impl Login {

request.respond(Response::from_string("Success! You can close this tab now"))?;

return Ok(());

Ok(())
}
}
Expand Down
31 changes: 15 additions & 16 deletions src/commands/orgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use tabled::Table;

use super::CommandBase;

#[derive(Parser)]
#[derive(Debug)]
#[derive(Parser, Debug)]
#[command(
author,
version,
Expand All @@ -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),
Expand All @@ -41,8 +39,7 @@ pub enum Commands {
Switch(Switch),
}

#[derive(Parser)]
#[derive(Debug)]
#[derive(Parser, Debug)]
pub struct List {}

impl List {
Expand All @@ -61,8 +58,7 @@ impl List {
}
}

#[derive(Parser)]
#[derive(Debug)]
#[derive(Parser, Debug)]
pub struct Create {
#[clap(short, long)]
name: Option<String>,
Expand Down Expand Up @@ -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 {
Expand All @@ -143,7 +139,8 @@ impl CreatePlanBuilder {
.unwrap();

self.billing_email = input;
return self;

self
}

fn verify(&self) -> Result<()> {
Expand All @@ -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<String>,
Expand All @@ -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())
Expand Down
39 changes: 13 additions & 26 deletions src/commands/secrets.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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(()),
}
}
}
Expand All @@ -38,7 +38,7 @@ pub enum Commands {
/// List secrets
List(List),
/// Delete a secret
Delete(Delete)
Delete(Delete),
}

#[derive(Debug, Parser)]
Expand Down Expand Up @@ -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<String> {
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);
Expand All @@ -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);
Expand Down Expand Up @@ -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(())
Expand Down
10 changes: 5 additions & 5 deletions src/commands/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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)]
Expand Down
22 changes: 10 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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),
Expand All @@ -106,14 +104,14 @@ fn main() -> Result<()> {
pub fn check_newer_release(current_version: &str) -> Result<Option<String>> {
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()?;
Expand All @@ -130,4 +128,4 @@ pub fn check_newer_release(current_version: &str) -> Result<Option<String>> {
} else {
Ok(None)
}
}
}

0 comments on commit 62abb07

Please sign in to comment.