mirror of
https://github.com/supleed2/sv-filelist-parser.git
synced 2024-12-22 21:35:49 +00:00
Just doodling around with basic main and lib file
This commit is contained in:
parent
f50981370f
commit
8d36a3a46d
34
src/lib.rs
Normal file
34
src/lib.rs
Normal file
|
@ -0,0 +1,34 @@
|
|||
#[derive(PartialEq, Debug)]
|
||||
pub enum LineType {
|
||||
File,
|
||||
Define,
|
||||
Filelist,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
pub fn parse_line(line: &str) -> LineType {
|
||||
if line.starts_with("-f ") {
|
||||
return LineType::Filelist;
|
||||
} else if line.starts_with("+define+") {
|
||||
return LineType::Define;
|
||||
} else {
|
||||
return LineType::Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn parse_line_filelist() {
|
||||
let line = "-f sample/files.f";
|
||||
assert_eq!(parse_line(line), LineType::Filelist);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_line_define() {
|
||||
let line = "+define+CONST1=const1+CONST2=const2";
|
||||
assert_eq!(parse_line(line), LineType::Define);
|
||||
}
|
||||
}
|
33
src/main.rs
Normal file
33
src/main.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
use std::fs;
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
// get .f file
|
||||
let dot_f_file = PathBuf::from(&args[1]);
|
||||
println!("pathbuf {:?}", dot_f_file);
|
||||
|
||||
// check if .f file exists
|
||||
if dot_f_file.is_file() {
|
||||
println!("File exists", )
|
||||
} else {
|
||||
println!("File does not exist", )
|
||||
}
|
||||
|
||||
// read .f file
|
||||
let contents = fs::read_to_string(&dot_f_file)
|
||||
.expect("Error while reading file");
|
||||
|
||||
println!("contents:\n{}", contents);
|
||||
// check if all the files exist
|
||||
for line in contents.lines() {
|
||||
if PathBuf::from(line).is_file() {
|
||||
println!("{} exists", line)
|
||||
}
|
||||
else {
|
||||
println!("{} does not exist", line)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue