option for multiple inputs
This commit is contained in:
parent
cbd6eb52b1
commit
a2868c8783
10 changed files with 78 additions and 44 deletions
|
@ -1,3 +1,3 @@
|
|||
pub fn main(_file: String) {
|
||||
pub fn main(_files: Vec<String>) {
|
||||
todo!()
|
||||
}
|
||||
|
|
31
src/main.rs
31
src/main.rs
|
@ -22,16 +22,13 @@ pub enum Commands {
|
|||
/// Checks a source file for conformance with piscine limitations.
|
||||
check {
|
||||
/// File to check.
|
||||
/// Supports globing
|
||||
#[clap(default_value_t = String::from("*"))]
|
||||
file: String,
|
||||
files: Vec<String>,
|
||||
},
|
||||
|
||||
/// Runs a file
|
||||
run {
|
||||
/// File to run.
|
||||
#[clap(default_value_t = String::from("./main.c"))]
|
||||
file: String,
|
||||
/// Files to run.
|
||||
files: Vec<String>,
|
||||
},
|
||||
|
||||
/// Runs tests contained within a particular test file or
|
||||
|
@ -40,9 +37,8 @@ pub enum Commands {
|
|||
#[clap(short, long)]
|
||||
capture: bool,
|
||||
|
||||
/// File to run tests from.
|
||||
#[clap(default_value_t = String::from("./test.c"))]
|
||||
file: String,
|
||||
/// Files to run tests from.
|
||||
files: Vec<String>,
|
||||
|
||||
/// Specific test to run.
|
||||
test: Option<String>,
|
||||
|
@ -50,9 +46,8 @@ pub enum Commands {
|
|||
|
||||
/// Watches changes to source files and re run them
|
||||
watch {
|
||||
/// File to run.
|
||||
#[clap(default_value_t = String::from("./main.c"))]
|
||||
file: String,
|
||||
/// Files to run.
|
||||
files: Vec<String>,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -60,15 +55,15 @@ fn main() {
|
|||
let args: Arguments = Parser::parse();
|
||||
|
||||
match args.command {
|
||||
Commands::check { file } => check::main(file),
|
||||
Commands::run { file } => {
|
||||
run::main(file);
|
||||
Commands::check { files } => check::main(files),
|
||||
Commands::run { files } => {
|
||||
run::main(files);
|
||||
}
|
||||
Commands::test {
|
||||
capture,
|
||||
file,
|
||||
files,
|
||||
test,
|
||||
} => test::main(capture, file, test),
|
||||
Commands::watch { file } => watch::main(file),
|
||||
} => test::main(capture, files, test),
|
||||
Commands::watch { files } => watch::main(files),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@ use crate::{
|
|||
utils::{log_failure, log_success},
|
||||
};
|
||||
|
||||
pub fn main(file: String) -> Option<()> {
|
||||
let source_file = file.into();
|
||||
pub fn main(files: Vec<String>) -> Option<()> {
|
||||
let source_file = files.into_iter().map(|f| f.into()).collect();
|
||||
let compiled = CompileTask::new(source_file)
|
||||
.with_flag("-Wall")
|
||||
.with_flag("-Wextra")
|
||||
|
|
21
src/tasks.rs
21
src/tasks.rs
|
@ -4,10 +4,12 @@ use std::{
|
|||
process::{Command, ExitStatus},
|
||||
};
|
||||
|
||||
use crate::utils::{log_command_run, log_separator, tmp_file_path, Apply};
|
||||
use crate::utils::{
|
||||
log_command_run, log_separator, log_separator_bottom, log_separator_top, tmp_file_path, Apply,
|
||||
};
|
||||
|
||||
pub struct CompileTask {
|
||||
file: PathBuf,
|
||||
files: Vec<PathBuf>,
|
||||
addition: Vec<String>,
|
||||
flags: Vec<String>,
|
||||
}
|
||||
|
@ -15,9 +17,9 @@ pub struct CompileTask {
|
|||
// TODO: split compile & compile raw
|
||||
|
||||
impl CompileTask {
|
||||
pub fn new(file: PathBuf) -> Self {
|
||||
pub fn new(files: Vec<PathBuf>) -> Self {
|
||||
Self {
|
||||
file,
|
||||
files,
|
||||
addition: vec![],
|
||||
flags: vec![],
|
||||
}
|
||||
|
@ -35,7 +37,8 @@ impl CompileTask {
|
|||
|
||||
pub fn run(self) -> Result<PathBuf, ExitStatus> {
|
||||
let proc_source = self.gen_source();
|
||||
let sources = vec![proc_source, self.file.clone()];
|
||||
let mut sources = self.files.clone();
|
||||
sources.push(proc_source);
|
||||
self.compile(sources)
|
||||
}
|
||||
|
||||
|
@ -56,9 +59,9 @@ impl CompileTask {
|
|||
.args(self.flags.clone())
|
||||
.args(sources.iter().map(|s| s.to_str().unwrap()));
|
||||
log_command_run(&command);
|
||||
log_separator();
|
||||
log_separator_top();
|
||||
let status = command.status().unwrap();
|
||||
log_separator();
|
||||
log_separator_bottom();
|
||||
status.success().then_some(output_path).ok_or(status)
|
||||
}
|
||||
}
|
||||
|
@ -75,9 +78,9 @@ impl RunTask {
|
|||
pub fn run(self) -> Result<(), ExitStatus> {
|
||||
let mut command = Command::new(self.file);
|
||||
log_command_run(&command);
|
||||
log_separator();
|
||||
log_separator_top();
|
||||
let status = command.status().unwrap();
|
||||
log_separator();
|
||||
log_separator_bottom();
|
||||
if status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
pub fn main(_capture: bool, _file: String, _test: Option<String>) {
|
||||
pub fn main(_capture: bool, _files: Vec<String>, _test: Option<String>) {
|
||||
let content = todo!();
|
||||
let tests = find_tests(content);
|
||||
for test in tests {
|
||||
|
|
|
@ -42,6 +42,14 @@ pub fn log_separator() {
|
|||
println!("────────────────")
|
||||
}
|
||||
|
||||
pub fn log_separator_top() {
|
||||
println!("───────────────┐")
|
||||
}
|
||||
|
||||
pub fn log_separator_bottom() {
|
||||
println!("───────────────┘")
|
||||
}
|
||||
|
||||
pub fn log_failure(text: &str) {
|
||||
log_pi_prefix();
|
||||
let text = format!("{}{text}{}", color::Fg(color::Red), color::Fg(color::Reset));
|
||||
|
|
27
src/watch.rs
27
src/watch.rs
|
@ -1,6 +1,5 @@
|
|||
use std::{path::Path, sync::mpsc, time::Duration};
|
||||
|
||||
use notify::{Error, Event, Watcher};
|
||||
use notify_debouncer_mini::new_debouncer;
|
||||
|
||||
use crate::{
|
||||
|
@ -9,16 +8,16 @@ use crate::{
|
|||
};
|
||||
|
||||
pub struct Repeater {
|
||||
file: String,
|
||||
files: Vec<String>,
|
||||
}
|
||||
|
||||
impl Repeater {
|
||||
pub fn new(file: String) -> Self {
|
||||
Self { file }
|
||||
pub fn new(files: Vec<String>) -> Self {
|
||||
Self { files }
|
||||
}
|
||||
|
||||
pub fn repeat(&self) -> Option<()> {
|
||||
let source = CompileTask::new(self.file.clone().into())
|
||||
let binary = CompileTask::new(self.files.clone().into_iter().map(|f| f.into()).collect())
|
||||
.run()
|
||||
.map(Option::from)
|
||||
.unwrap_or_else(|_| {
|
||||
|
@ -27,7 +26,7 @@ impl Repeater {
|
|||
})?;
|
||||
|
||||
log_success("compilation successful");
|
||||
RunTask::new(source)
|
||||
RunTask::new(binary)
|
||||
.run()
|
||||
.map(Option::from)
|
||||
.unwrap_or_else(|_| {
|
||||
|
@ -41,18 +40,20 @@ impl Repeater {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn main(file: String) {
|
||||
log_process(&format!("watching file '{file}'"));
|
||||
let repeater = Repeater::new(file.clone());
|
||||
pub fn main(files: Vec<String>) {
|
||||
log_process(&format!("watching files '{files:?}'"));
|
||||
let repeater = Repeater::new(files.clone());
|
||||
repeater.repeat();
|
||||
|
||||
let (send, rec) = mpsc::channel();
|
||||
let mut debouncer = new_debouncer(Duration::from_millis(100), None, send).unwrap();
|
||||
|
||||
debouncer
|
||||
.watcher()
|
||||
.watch(Path::new(&file), notify::RecursiveMode::Recursive)
|
||||
.unwrap();
|
||||
for file in files {
|
||||
debouncer
|
||||
.watcher()
|
||||
.watch(Path::new(&file), notify::RecursiveMode::Recursive)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
for events in rec {
|
||||
for _ in events.unwrap() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue