diff options
| author | Namilskyy <alive6863@gmail.com> | 2025-12-07 19:14:35 +0300 |
|---|---|---|
| committer | Namilskyy <alive6863@gmail.com> | 2025-12-07 19:14:35 +0300 |
| commit | b55537c7d2652d1f5b389cce503cc176d1f970ec (patch) | |
| tree | a2d99e08b55dcf499c2cb4ffc2061cc981308eb8 /src/main.rs | |
| parent | 778a979e2e774e1b2e91227fa2db2e56d41927c1 (diff) | |
Code refactors, minor fixes
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 102 |
1 files changed, 77 insertions, 25 deletions
diff --git a/src/main.rs b/src/main.rs index 068a8fb..4de9e55 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,11 +10,11 @@ use crate::pkgtoolkit::archive::ArchiveOperations; use crate::pkgtoolkit::build::BuildOperations; use crate::pkgtoolkit::git_source::GitSource; use crate::pkgtoolkit::index::IndexOperations; +use crate::pkgtoolkit::install::InstallOperations; use clap::{Args, Parser, Subcommand}; use std::io::Write; use std::path::Path; -use toml; #[derive(Parser)] struct Cli { @@ -34,8 +34,12 @@ enum Commands { Build { pkgname: String }, #[command(about = "Install package from remote or local sources")] Install { + #[arg(help = "Package name or path to local .mesk file")] pkgname: String, source: Option<String>, + #[arg(short = 'p', long = "path")] + #[arg(help = "Install from local .mesk file")] + path: bool, #[command(flatten)] args: RemoteInstallArgs, }, @@ -74,6 +78,7 @@ struct RemoteInstallArgs { #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { + let cli: Cli = Cli::parse(); match &cli.command { @@ -114,11 +119,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { } println!("Extracting archive..."); - Package::extract_archive(&pkgname)?; + Package::extract_archive(pkgname)?; let config = Config::parse().unwrap(); let cache_dir = &config.paths.cache_dir; - + // Find the package directory (should be name-version format) let mut pkg_dir_name = None; for entry in std::fs::read_dir(cache_dir)? { @@ -135,17 +140,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { } } } - - let pkg_dir_name = pkg_dir_name.ok_or_else(|| { - std::io::Error::other("Package directory not found in cache") - })?; - + + let pkg_dir_name = pkg_dir_name + .ok_or_else(|| std::io::Error::other("Package directory not found in cache"))?; + let install_toml_path = Path::new(cache_dir).join(format!("{}/INSTALL", pkg_dir_name)); - + if !install_toml_path.exists() { - return Err(std::io::Error::other("INSTALL file not found in package directory").into()); + return Err( + std::io::Error::other("INSTALL file not found in package directory").into(), + ); } - + let install_content = std::fs::read_to_string(&install_toml_path)?; let install_data: crate::pkgtoolkit::types::Install = toml::from_str(&install_content)?; @@ -159,23 +165,69 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { Commands::Install { pkgname, source: _, + path, args, } => { - let config = Config::parse().unwrap(); - if args.http { - println!("Installing {} via HTTP", pkgname); - let mut http_client = HTTPPackage::new(config); - http_client.fetch_index_http().await?; - log::info!("Index fetched successfully."); - http_client.fetch_package_http(pkgname).await?; - log::info!("Package '{}' installed successfully.", pkgname); + if *path { + println!("Installing package from local file: {}", pkgname); + + println!("Extracting archive..."); + Package::extract_archive(pkgname)?; + + let config = Config::parse().unwrap(); + let cache_dir = &config.paths.cache_dir; + + let mut pkg_dir_name = None; + for entry in std::fs::read_dir(cache_dir)? { + let entry = entry?; + let path = entry.path(); + if path.is_dir() { + let dir_name = path.file_name().unwrap().to_string_lossy(); + if dir_name.contains('-') && dir_name != "temp_extract" { + let install_path = path.join("INSTALL"); + if install_path.exists() { + pkg_dir_name = Some(dir_name.to_string()); + break; + } + } + } + } + + let pkg_dir_name = pkg_dir_name + .ok_or_else(|| std::io::Error::other("Package directory not found in cache"))?; + + let install_toml_path = + Path::new(cache_dir).join(format!("{}/INSTALL", pkg_dir_name)); + let install_content = std::fs::read_to_string(&install_toml_path)?; + let install_data: crate::pkgtoolkit::types::Install = + toml::from_str(&install_content)?; + + let mut pkg = install_data.package; + + println!("Building package '{}'...", pkg.name); + pkg.build()?; + + println!("Installing package '{}'...", pkg.name); + pkg.install()?; + println!("Package '{}' installed successfully.", pkg.name); } else { - println!("Installing {} via I2P", pkgname); - let mut i2p_client = I2PPackage::new(config); - i2p_client.fetch_index().await?; - log::info!("Index fetched successfully."); - i2p_client.fetch_package(pkgname).await?; - log::info!("Package '{}' installed successfully.", pkgname); + + let config = Config::parse().unwrap(); + if args.http { + println!("Installing {} via HTTP", pkgname); + let mut http_client = HTTPPackage::new(config); + http_client.fetch_index_http().await?; + log::info!("Index fetched successfully."); + http_client.fetch_package_http(pkgname).await?; + log::info!("Package '{}' installed successfully.", pkgname); + } else { + println!("Installing {} via I2P", pkgname); + let mut i2p_client = I2PPackage::new(config); + i2p_client.fetch_index().await?; + log::info!("Index fetched successfully."); + i2p_client.fetch_package(pkgname).await?; + log::info!("Package '{}' installed successfully.", pkgname); + } } return Ok(()); } |
