summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs131
1 files changed, 64 insertions, 67 deletions
diff --git a/src/main.rs b/src/main.rs
index 463bd24..e295722 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,15 +3,15 @@ mod net;
mod pkgtoolkit;
use crate::cfg::config::Config;
+use crate::net::i2p_package::I2PPackage;
#[allow(unused_imports)]
use crate::pkgtoolkit::pkgtools::Package;
-use crate::net::i2p_package::I2PPackage;
-use clap::{Args, Command, Parser, Subcommand};
+use clap::{Args, Parser, Subcommand};
+use std::fs::File;
+use std::fs::create_dir_all;
use std::io::Write;
use std::path::Path;
-use std::fs::create_dir_all;
-use std::fs::File;
use tokio;
#[derive(Parser)]
@@ -23,54 +23,43 @@ struct Cli {
#[derive(Subcommand)]
enum Commands {
#[command(about = "Validate .mesk package archive")]
- Validate {
- path: String,
- },
+ Validate { path: String },
#[command(about = "Update all repositories index")]
- Update,
+ Update,
#[command(about = "Upgrade all packages or a specific package")]
- Upgrade {
- pkgname: Option<String>,
- },
+ Upgrade { pkgname: Option<String> },
#[command(about = "Build package from .mesk ")]
- Build{
- pkgname: String,
- },
+ Build { pkgname: String },
#[command(about = "Install package from remote or local sources")]
- Install{
- pkgname: String,
+ Install {
+ pkgname: String,
source: Option<String>,
#[command(flatten)]
- args: RemoteInstallArgs
-
+ args: RemoteInstallArgs,
},
#[command(about = "Uninstall package")]
- Uninstall{
- pkgname: String,
- },
+ Uninstall { pkgname: String },
#[command(about = "Get package source")]
- GetSource{
- pkgname: String
- },
+ GetSource { pkgname: String },
#[command(about = "Generator of config file")]
DefaultConfig {
- repo: Option<String>,
+ repo: Option<String>,
cachedir: Option<String>,
- buildir: Option<String>,
+ buildir: Option<String>,
},
#[command(about = "Maintaners, links, developers and more info")]
- Credits
+ Credits,
}
-#[derive(Args, Clone)]
+#[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
+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]
@@ -78,82 +67,90 @@ 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.
+ // 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(())
- },
+ return Ok(());
+ }
Commands::Build { pkgname } => {
println!("Building {}", pkgname);
- return Ok(())
- },
- Commands::Install { pkgname, source, args} => {
+ return Ok(());
+ }
+
+ Commands::Install {
+ pkgname,
+ source,
+ args,
+ } => {
println!("Installing {}", pkgname);
- return Ok(())
- },
+ return Ok(());
+ }
Commands::Uninstall { pkgname } => {
println!("Uninstalling {}", pkgname);
- return Ok(())
- },
+ return Ok(());
+ }
Commands::GetSource { pkgname } => {
println!("Getting source of {}", pkgname);
- return Ok(())
- },
- Commands::DefaultConfig { repo, cachedir, buildir } => {
+ 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!("{}", 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();
+ let config = Config::generate(repo, cachedir, buildir).unwrap();
println!("---- Start of generated config ----");
- println!("{:?}", 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(())
- },
+ 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?;
+ let _index = I2PPackage::fetch_index(&mut i2pd).await?;
println!("Index updated");
- return Ok(())
- },
+ return Ok(());
+ }
Commands::Upgrade { pkgname } => {
println!("Upgrading all packages");
- return Ok(())
- },
+ return Ok(());
+ }
Commands::Credits => {
- println!("CREATED BY: Asya and Namilsk as part of the Anthrill independent Global network distribution project");
+ 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(())
-
-} \ No newline at end of file
+}