diff options
author | curly <curlybryce@protonmail.com> | 2023-01-05 08:29:34 -0700 |
---|---|---|
committer | curly <curlybryce@protonmail.com> | 2023-01-05 08:29:34 -0700 |
commit | ee6aca2243458c44ddebd1fc141fa97b6922d9b3 (patch) | |
tree | a919558de64e1cc494fe6d40e92e5bda9d85fe3d /src | |
parent | 952b0ec05828116e228bdc71f65014f9be976ad3 (diff) | |
download | s3g-ee6aca2243458c44ddebd1fc141fa97b6922d9b3.tar.gz s3g-ee6aca2243458c44ddebd1fc141fa97b6922d9b3.tar.bz2 s3g-ee6aca2243458c44ddebd1fc141fa97b6922d9b3.zip |
completed!
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 49 |
1 files changed, 37 insertions, 12 deletions
@@ -62,8 +62,7 @@ impl Config { let mut commands_vec = vec![]; let commands = commands.as_table().unwrap(); for x in commands.keys() { - let x = commands.get(x); - commands_vec.push((String::from(x.unwrap().as_str().unwrap()), String::from(x.unwrap().as_str().unwrap()))) + commands_vec.push((String::from(x), String::from(commands.get(x).unwrap().as_str().unwrap()))) } let mut do_not_scan = vec![]; @@ -81,8 +80,8 @@ impl Config { build_dir: String::from(config["build_dir"].as_str().unwrap()), do_not_scan: do_not_scan, excludes: exclude, - file_delim: String::from(config["file_delim"].as_str().unwrap()), - command_delim: String::from(config["command_delim"].as_str().unwrap()), + file_delim: String::from(":?"), + command_delim: String::from(":!"), commands: commands_vec, } } @@ -179,7 +178,6 @@ impl S3G { } fn directory_scan(&self, path: path::PathBuf) { - // println!("Looking in: {:?}", &path); // Check the path match self.check_path(&path) { @@ -210,11 +208,9 @@ impl S3G { fn file_scan(&self, path: &path::PathBuf) -> Option<String> { // Check path match self.check_path(&path) { - // PathType::Okay => println!("Scanning: \"{}\"", &path.to_str().unwrap()), PathType::Okay => (), PathType::DoNotScan => { self.copy_file(&path); - // println!("Not scanning: \"{}\"", &path.to_str().unwrap()); return None }, PathType::Exclude => (), @@ -233,19 +229,48 @@ impl S3G { for line in string.lines() { - // NEED TO FOR LOOP ON COMMANDS AND FILES PREFIXES - if line.contains(":?") { - let v: Vec<&str> = line.trim().split(":?").collect(); + if line.contains(&self.config.file_delim) || line.contains(&self.config.command_delim) { + + // Parse lines for prefixes + let v: Vec<&str> = line.trim().split(':').collect(); for s in v { let s = match s { "" => String::from(""), - // Scan the file from the path - n => self.file_scan(&path::PathBuf::from(n)).unwrap_or(String::from("")), + n => { + let mut string = String::new(); + for x in n.split_ascii_whitespace() { + // Commands + for c in &self.config.commands { + let delim = String::new() + &self.config.command_delim.get(1..2).unwrap() + &c.0; + if x.contains(&delim) { + let x = x.replace(&delim, &c.1); + string.push_str(&x); + } + } + + // Files + if x.contains(&self.config.file_delim.get(1..2).unwrap()) { + let x: Vec<&str> = x.split(&self.config.file_delim.get(1..2).unwrap()).collect(); + for s in x { + let s = match s { + "" => String::from(""), + // Scan the file from the path + n => self.file_scan(&path::PathBuf::from(n)).unwrap_or(String::from("")), + }; + + string.push_str(&s); + } + + } + } + string + }, }; // Push matching and scanned string file_string.push_str(&s); file_string.push('\n'); + } } else { // Push unmatching line |