summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorNamilskyy <alive6863@gmail.com>2025-11-30 17:16:54 +0300
committerNamilskyy <alive6863@gmail.com>2025-11-30 17:16:54 +0300
commitf8b9506be25332f8772fca44c1cf7106caeea3fe (patch)
treebb41c99ef61bc0c426aed880186d9bfa3447da62 /src/main.rs
parent078fafff3720f9cec38dd84ecc88b15e842e7be6 (diff)
Fixed all clippy warnings
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs87
1 files changed, 72 insertions, 15 deletions
diff --git a/src/main.rs b/src/main.rs
index 8677fdb..37bd70a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,9 +1,10 @@
mod cfg;
-mod net;
+mod net; // This should contain both i2p_package and http_package modules
mod pkgtoolkit;
use crate::cfg::config::Config;
-use crate::net::i2p_package::I2PPackage;
+use crate::net::{i2p_package::I2PPackage,
+ http_package::HTTPPackage};
#[allow(unused_imports)]
use crate::pkgtoolkit::pkgtools::Package;
@@ -12,7 +13,6 @@ use std::fs::File;
use std::fs::create_dir_all;
use std::io::Write;
use std::path::Path;
-use tokio;
#[derive(Parser)]
struct Cli {
@@ -55,19 +55,23 @@ enum Commands {
#[command(about = "Remote install arguments")]
struct RemoteInstallArgs {
#[arg(short = 'b', long = "bin")]
+ #[arg(help = "Install binary package")]
bin: bool,
+
#[arg(short = 'h', long = "http")]
+ #[arg(help = "Use non-i2p mirror")]
http: bool,
+
#[arg(short = 'c', long = "clean")]
+ #[arg(help = "Clean cache before install")]
clean: bool,
}
#[tokio::main]
-async fn main() -> Result<(), std::io::Error> {
+async fn main() -> Result<(), Box<dyn std::error::Error>> {
+ // Changed return type to be more general
let cli: Cli = Cli::parse();
- // Plug in these functions only until the backend is ready for testing (Aplha versions)
- // It is necessary for me to understand the I/O model of the future mesk.
match &cli.command {
Commands::Validate { path } => {
println!("Validating {}", path);
@@ -77,13 +81,58 @@ async fn main() -> Result<(), std::io::Error> {
println!("Building {}", pkgname);
return Ok(());
}
-
Commands::Install {
pkgname,
- source,
+ source: _,
args,
} => {
- println!("Installing {}", pkgname);
+ let config = Config::parse().unwrap();
+
+ if args.http {
+ println!("Installing {} via HTTP", pkgname);
+ let mut http_client = HTTPPackage::new(config);
+ match http_client.fetch_index_http().await {
+ Ok(_) => {
+ log::info!("Index fetched successfully.");
+ }
+ Err(e) => {
+ log::error!("Failed to fetch index: {}", e);
+ return Err(e);
+ }
+ }
+ match http_client.fetch_package_http(pkgname).await {
+ Ok(_) => {
+ log::info!("Package '{}' installed successfully.", pkgname);
+ }
+ Err(e) => {
+ log::error!("Failed to install package '{}': {}", pkgname, e);
+ return Err(e);
+ }
+ }
+ } else {
+ println!("Installing {} via I2P", pkgname);
+ let mut i2p_client = I2PPackage::new(config);
+
+ match i2p_client.fetch_index().await {
+ Ok(_) => {
+ log::info!("Index fetched successfully.");
+ }
+ Err(e) => {
+ log::error!("Failed to fetch index: {}", e);
+ return Err(e);
+ }
+ }
+ match i2p_client.fetch_package(pkgname).await {
+ Ok(_) => {
+ log::info!("Package '{}' installed successfully.", pkgname);
+ }
+ Err(e) => {
+ log::error!("Failed to install package '{}': {}", pkgname, e);
+ return Err(e);
+ }
+ }
+ }
+ // --- Integration ends here ---
return Ok(());
}
Commands::Uninstall { pkgname } => {
@@ -112,7 +161,7 @@ async fn main() -> Result<(), std::io::Error> {
let path = Path::new("/etc/mesk/mesk.toml");
create_dir_all(path.parent().unwrap())?;
let mut file = File::create(path)?;
- file.write(config.as_bytes())?;
+ file.write_all(config.as_bytes())?;
println!("Config tool ending work.");
} else {
let config = Config::generate(repo, cachedir, buildir).unwrap();
@@ -134,13 +183,21 @@ async fn main() -> Result<(), std::io::Error> {
Commands::Update => {
let config = Config::parse().unwrap();
println!("Updating index from {}", config.repo.repo_url);
- let mut i2pd = I2PPackage::new(config);
- let _index = I2PPackage::fetch_index(&mut i2pd).await;
- println!("Index updated");
+
+ let mut i2p_client = I2PPackage::new(config);
+ match i2p_client.fetch_index().await {
+ Ok(_) => {
+ println!("Index updated successfully.");
+ }
+ Err(e) => {
+ log::error!("Failed to update index: {}", e);
+ return Err(e);
+ }
+ }
return Ok(());
}
Commands::Upgrade { pkgname } => {
- println!("Upgrading all packages");
+ println!("Upgrading {}", pkgname.as_deref().unwrap_or("all packages"));
return Ok(());
}
Commands::Credits => {
@@ -148,7 +205,7 @@ async fn main() -> Result<(), std::io::Error> {
"CREATED BY: Asya and Namilsk as part of the Anthrill independent Global network distribution project"
);
println!(" ");
- println!("The Anthrill project repos: https://codeberg.org/NamelessTeam");
+ println!("The Anthrill project repos: https://codeberg.org/NamelessTeam ");
}
}