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::>()[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); } } }