diff options
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | TODO | 4 | ||||
-rw-r--r-- | src/lib.rs | 49 |
4 files changed, 39 insertions, 18 deletions
@@ -4,7 +4,7 @@ version = 3 [[package]] name = "s3g" -version = "0.1.0" +version = "1.0.0" dependencies = [ "toml", ] @@ -1,6 +1,6 @@ [package] name = "s3g" -version = "0.1.0" +version = "1.0.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -1,4 +0,0 @@ -"for s in v {" needs to push the surrounding text to the string - -In files -- NEED TO FOR LOOP ON COMMANDS AND FILES PREFIXES @@ -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 |