Maxime “pep” Buquet
4fdc467cf2
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is pending
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
63 lines
1.4 KiB
Rust
63 lines
1.4 KiB
Rust
//
|
|
// spec.rs
|
|
// Copyright (C) 2023 Maxime “pep” Buquet <pep@bouah.net>
|
|
// Distributed under terms of the GPLv3+ license.
|
|
//
|
|
|
|
use std::env::args;
|
|
use std::fs::File;
|
|
use std::io::{self, Read};
|
|
use std::path::{Path, PathBuf};
|
|
|
|
use scansion_dsl::parse_spec;
|
|
|
|
fn main() -> io::Result<()> {
|
|
let args: Vec<String> = args().collect();
|
|
if args.len() != 2 {
|
|
println!("Usage: {} <file-or-dir>", args[0]);
|
|
return Err(io::Error::new(
|
|
io::ErrorKind::Other,
|
|
"Invalid argument count",
|
|
));
|
|
}
|
|
|
|
let path = Path::new(&args[1]);
|
|
if !path.exists() {
|
|
return Err(io::Error::new(
|
|
io::ErrorKind::Other,
|
|
"Specified path doesn't exist",
|
|
));
|
|
}
|
|
let files: Vec<PathBuf> = if path.is_file() {
|
|
vec![path.to_path_buf()]
|
|
} else if path.is_dir() {
|
|
path.read_dir()?
|
|
.filter_map(|entry| {
|
|
let p = entry.unwrap().path();
|
|
match p.extension() {
|
|
Some(ext) if ext == "scs" => Some(p),
|
|
_ => None,
|
|
}
|
|
})
|
|
.collect::<Vec<_>>()
|
|
} else {
|
|
return Err(io::Error::new(
|
|
io::ErrorKind::Other,
|
|
"Only files and dirs are supported",
|
|
));
|
|
};
|
|
|
|
for path in files {
|
|
let mut file = File::open(path.clone())?;
|
|
let mut contents = String::new();
|
|
file.read_to_string(&mut contents)?;
|
|
|
|
print!("Path: {path:?}: ");
|
|
match parse_spec(&contents) {
|
|
Ok(_) => println!("\x1b[32m OK\x1b[0m"),
|
|
Err(err) => println!("\x1b[31mERR\x1b[0m\n{err:?}"),
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|