mod cfg; mod net; mod pkgtoolkit; use crate::cfg::config::Config; #[allow(unused_imports)] use crate::pkgtoolkit::pkgtools::Package; use crate::net::i2p_package::I2PPackage; use clap::{Args, Command, Parser, Subcommand}; use std::io::Write; use std::path::Path; use std::fs::create_dir_all; use std::fs::File; use tokio; #[derive(Parser)] struct Cli { #[command(subcommand)] command: Commands, } #[derive(Subcommand)] enum Commands { #[command(about = "Validate .mesk package archive")] Validate { path: String, }, #[command(about = "Update all repositories index")] Update, #[command(about = "Upgrade all packages or a specific package")] Upgrade { pkgname: Option, }, #[command(about = "Build package from .mesk ")] Build{ pkgname: String, }, #[command(about = "Install package from remote or local sources")] Install{ pkgname: String, source: Option, #[command(flatten)] args: RemoteInstallArgs }, #[command(about = "Uninstall package")] Uninstall{ pkgname: String, }, #[command(about = "Get package source")] GetSource{ pkgname: String }, #[command(about = "Generator of config file")] DefaultConfig { repo: Option, cachedir: Option, buildir: Option, }, #[command(about = "Maintaners, links, developers and more info")] Credits } #[derive(Args, Clone)] #[command(about = "Remote install arguments")] struct RemoteInstallArgs { #[arg(short = 'b', long = "bin" )] bin: bool, #[arg(short = 'h', long = "http" )] http: bool, #[arg(short = 'c', long = "clean" )] clean: bool } #[tokio::main] async fn main() -> Result<(), std::io::Error> { 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); return Ok(()) }, Commands::Build { pkgname } => { println!("Building {}", pkgname); return Ok(()) }, Commands::Install { pkgname, source, args} => { println!("Installing {}", pkgname); return Ok(()) }, Commands::Uninstall { pkgname } => { println!("Uninstalling {}", pkgname); return Ok(()) }, Commands::GetSource { pkgname } => { println!("Getting source of {}", pkgname); return Ok(()) }, Commands::DefaultConfig { repo, cachedir, buildir } => { println!("Generating config file"); if cachedir.is_none() && repo.is_none() && buildir.is_none() { let config = Config::default().unwrap(); println!("---- Start of generated config ----"); println!("{}", config); println!("---- End of generated config ----"); log::warn!("Writing the default config to /etc/mesk/mesk.toml"); 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())?; println!("Config tool ending work."); } else { let config = Config::generate(repo, cachedir, buildir).unwrap(); println!("---- Start of generated config ----"); println!("{:?}", config); println!("---- End of generated config ----"); log::warn!("Writing the default config to /etc/mesk/mesk.toml"); let path = Path::new("/etc/mesk/mesk.toml"); create_dir_all(path.parent().unwrap())?; let mut file = File::create(path)?; file.write_all(config.as_bytes())?; println!("Config tool ending work."); } return Ok(()) }, 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"); return Ok(()) }, Commands::Upgrade { pkgname } => { println!("Upgrading all packages"); return Ok(()) }, Commands::Credits => { println!("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"); } } Ok(()) }