init: initial commit of packager
This commit is contained in:
commit
36c782a564
25 changed files with 478 additions and 0 deletions
12
bootpkg/Cargo.toml
Normal file
12
bootpkg/Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "bootpkg"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
manifest = { path = "../manifest" }
|
||||
pkgfile = { path = "../pkgfile" }
|
||||
regex = "1.9.1"
|
||||
reqwest = { version = "0.11.18", features = ["blocking"] }
|
29
bootpkg/src/args.rs
Normal file
29
bootpkg/src/args.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
pub enum Command {
|
||||
Strap,
|
||||
Unpack,
|
||||
None
|
||||
}
|
||||
|
||||
impl From<String> for Command {
|
||||
fn from(value: String) -> Self {
|
||||
match value.to_lowercase().as_str() {
|
||||
"strap" => Command::Strap,
|
||||
"unpack" => Command::Unpack,
|
||||
_ => Command::None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Args {
|
||||
pub command: Command,
|
||||
pub args: Vec<String>,
|
||||
}
|
||||
|
||||
impl From<Vec<String>> for Args {
|
||||
fn from(value: Vec<String>) -> Self {
|
||||
Args {
|
||||
command: Command::from(value[0].to_owned()),
|
||||
args: value[1..].to_owned()
|
||||
}
|
||||
}
|
||||
}
|
51
bootpkg/src/main.rs
Normal file
51
bootpkg/src/main.rs
Normal file
|
@ -0,0 +1,51 @@
|
|||
use std::env;
|
||||
use std::process::exit;
|
||||
use pkgfile::PKGFile;
|
||||
use crate::args::{Args, Command};
|
||||
|
||||
mod prelude;
|
||||
mod args;
|
||||
|
||||
fn main() {
|
||||
let args = Args::from(env::args().collect::<Vec<String>>()[1..].to_owned());
|
||||
match args.command {
|
||||
Command::Strap => {
|
||||
if args.args.len() == 0 {
|
||||
println!("no path/uri");
|
||||
exit(0);
|
||||
}
|
||||
let uri = &args.args[0];
|
||||
println!("!! Got package: \"{}\"", uri);
|
||||
let re = r"[A-z]+://.+";
|
||||
let data = if regex::Regex::new(re).unwrap().is_match(uri) {
|
||||
println!("** detected uri.");
|
||||
reqwest::blocking::get(uri)
|
||||
.expect("Could not request file.")
|
||||
.bytes()
|
||||
.expect("Could not turn file into bytes.")
|
||||
.to_vec()
|
||||
} else {
|
||||
if let Ok(d) = std::fs::read(uri) {
|
||||
d
|
||||
} else {
|
||||
println!("Could not read file!");
|
||||
exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
let p = match PKGFile::try_from(data) {
|
||||
Ok(p) => p,
|
||||
Err(_) => {
|
||||
println!("!! Could not interpret PKGFile...");
|
||||
exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
},
|
||||
Command::Unpack => todo!(),
|
||||
_ => {
|
||||
println!("Unsupported command, allowed commands: strap/unpack.");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
22
bootpkg/src/prelude.rs
Normal file
22
bootpkg/src/prelude.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
use std::collections::HashMap;
|
||||
use manifest::Manifest;
|
||||
|
||||
pub struct PKGR {
|
||||
pub bootstrap: Option<Bootstrap>,
|
||||
}
|
||||
|
||||
pub struct Bootstrap {}
|
||||
|
||||
pub fn def_manifest() {
|
||||
Manifest::<Option<PKGR>> {
|
||||
package: manifest::package::Package::default(),
|
||||
bin: None,
|
||||
build: None,
|
||||
dependencies: HashMap::default(),
|
||||
fs: manifest::fs::FS {
|
||||
config: None,
|
||||
data: None,
|
||||
},
|
||||
pkgr: Some(PKGR { bootstrap: None }),
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue