Skip to content

Commit

Permalink
fix(httpd): fix clippy warnings and return error if exists
Browse files Browse the repository at this point in the history
Signed-off-by: Tarek <tareknaser360@gmail.com>
  • Loading branch information
tareknaser committed Jul 10, 2023
1 parent 44d3b7e commit 35a2032
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
2 changes: 1 addition & 1 deletion coffee_httpd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ actix-web = "4"
clap = "4.1.11"
tokio = { version = "1.22.0", features = ["sync"] }
coffee_core = { path = "../coffee_core" }
coffee_lib = { path = "../coffee_lib" }
coffee_lib = { path = "../coffee_lib", features = ["open-api"] }
paperclip = { version = "0.8.0", features = ["actix4"] }
log = "0.4.17"
env_logger = "0.9.3"
Expand Down
15 changes: 5 additions & 10 deletions coffee_httpd/src/httpd/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ async fn coffee_install(
let mut coffee = data.coffee.lock().await;
let result = coffee.install(plugin, false, try_dynamic).await;

let response = handle_httpd_response!(result, "Plugin '{plugin}' installed successfully");
response
handle_httpd_response!(result, "Plugin '{plugin}' installed successfully")
}

#[api_v2_operation]
Expand All @@ -105,8 +104,7 @@ async fn coffee_remove(
let mut coffee = data.coffee.lock().await;
let result = coffee.remove(plugin).await;

let response = handle_httpd_response!(result, "Plugin '{plugin}' removed successfully");
response
handle_httpd_response!(result, "Plugin '{plugin}' removed successfully")
}

#[api_v2_operation]
Expand Down Expand Up @@ -139,9 +137,7 @@ async fn coffee_remote_add(
let mut coffee = data.coffee.lock().await;
let result = coffee.add_remote(repository_name, repository_url).await;

let response =
handle_httpd_response!(result, "Repository '{repository_name}' added successfully");
response
handle_httpd_response!(result, "Repository '{repository_name}' added successfully")
}

#[api_v2_operation]
Expand All @@ -155,11 +151,10 @@ async fn coffee_remote_rm(
let mut coffee = data.coffee.lock().await;
let result = coffee.rm_remote(repository_name).await;

let response = handle_httpd_response!(
handle_httpd_response!(
result,
"Repository '{repository_name}' removed successfully"
);
response
)
}

#[api_v2_operation]
Expand Down
18 changes: 8 additions & 10 deletions coffee_httpd/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
use clap::Parser;

use coffee_core::coffee::CoffeeManager;
use coffee_lib::errors::CoffeeError;
use coffee_lib::macros::error;
use coffee_lib::plugin_manager::PluginManager;

mod cmd;
pub mod httpd;

#[actix_web::main]
async fn main() {
async fn main() -> Result<(), CoffeeError> {
env_logger::init();
let cmd = cmd::HttpdArgs::parse();
let coffee = CoffeeManager::new(&cmd).await;
if let Err(err) = &coffee {
println!("{err}");
}
let mut coffee = coffee.unwrap();
if let Err(err) = coffee.setup(&cmd.cln_path).await {
println!("{err}");
}
let mut coffee = CoffeeManager::new(&cmd).await?;
coffee.setup(&cmd.cln_path).await?;

let port = cmd.port.unwrap_or(8080) as u16;
log::info!("Running on port 127.0.0.1:{port}");
if let Err(err) = httpd::run_httpd(coffee, ("127.0.0.1", port)).await {
println!("{err}");
return Err(error!("Error while running the httpd: {err}"));
}

Ok(())
}
4 changes: 2 additions & 2 deletions coffee_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ git2 = "0.16.1"
log = "0.4.17"
env_logger = "0.9.3"
tokio = { version = "1.22.0", features = ["process"] }
paperclip = { version = "0.8.0", features = ["actix4"] }
paperclip = { version = "0.8.0", features = ["actix4"], optional = true }

[features]
httpd = ["paperclip/actix4"]
open-api = ["dep:paperclip"]

0 comments on commit 35a2032

Please sign in to comment.