1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
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<String>,
},
#[command(about = "Build package from .mesk ")]
Build{
pkgname: String,
},
#[command(about = "Install package from remote or local sources")]
Install{
pkgname: String,
source: Option<String>,
#[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<String>,
cachedir: Option<String>,
buildir: Option<String>,
},
#[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(())
}
|