summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs81
1 files changed, 74 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs
index 1630c66..a3f69dd 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,14 +2,19 @@ mod cfg;
mod i2impl;
mod pkgtoolkit;
-#[allow(unused_imports)]
use crate::cfg::config::Config;
#[allow(unused_imports)]
use crate::pkgtoolkit::pkgtools::Package;
#[allow(unused_imports)]
-use crate::i2impl::mi2p;
+use crate::i2impl::mi2p::I2P;
-use clap::{Parser, Subcommand, Args};
+use clap::{Args, Command, Parser, Subcommand};
+use yosemite::Stream;
+use std::io::Write;
+use std::path::Path;
+use std::fs::create_dir_all;
+use std::fs::File;
+use tokio;
#[derive(Parser)]
struct Cli {
@@ -23,6 +28,12 @@ enum Commands {
Validate {
pkgname: String,
},
+ #[command(about = "Update all repositories index")]
+ Update,
+ #[command(about = "Upgrade all packages or a specific package")]
+ Upgrade {
+ pkgname: Option<String>,
+ },
#[command(about = "Build package from .mesk ")]
Build{
pkgname: String,
@@ -30,6 +41,7 @@ enum Commands {
#[command(about = "Install package from remote or local sources")]
Install{
pkgname: String,
+ source: Option<String>,
},
#[command(about = "Uninstall package")]
Uninstall{
@@ -38,6 +50,12 @@ enum Commands {
#[command(about = "Get package source")]
GetSource{
pkgname: String
+ },
+ #[command(about = "Generator of config file")]
+ DefaultConfig {
+ repo: Option<String>,
+ cachedir: Option<String>,
+ buildir: Option<String>,
}
}
@@ -52,7 +70,8 @@ struct RemoteInstallArgs {
i2p: bool,
}
-fn main() -> Result<(), std::io::Error> {
+#[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)
@@ -66,7 +85,7 @@ fn main() -> Result<(), std::io::Error> {
println!("Building {}", pkgname);
return Ok(())
},
- Commands::Install { pkgname } => {
+ Commands::Install { pkgname, source} => {
println!("Installing {}", pkgname);
return Ok(())
},
@@ -77,8 +96,56 @@ fn main() -> Result<(), std::io::Error> {
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()).unwrap();
+ let mut file = File::create(path).unwrap();
+ file.write(config.as_bytes()).unwrap();
+ 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()).unwrap();
+ let mut file = File::create(path).unwrap();
+ file.write_all(config.as_bytes()).unwrap();
+ 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 = I2P::new(config);
+ let _index= I2P::fetch_index(&mut i2pd).await?;
+ println!("Index updated");
+ return Ok(())
+ },
+ Commands::Upgrade { pkgname } => {
+ println!("Upgrading all packages");
+ return Ok(())
+ },
+
+
}
Ok(())
} \ No newline at end of file