making watch into a switch between run and test

This commit is contained in:
matthieu.jolimaitre 2022-09-25 13:38:40 +02:00
parent 6ef3993f8f
commit c6baef23c2
2 changed files with 52 additions and 9 deletions

View file

@ -46,14 +46,38 @@ pub enum Commands {
/// Watches changes to source files and re run them
watch {
/// Files to run.
files: Vec<String>,
#[clap(subcommand)]
command: WatchSubcommand,
},
///
init { path: String },
}
#[allow(non_camel_case_types)]
#[derive(Subcommand)]
pub enum WatchSubcommand {
/// Runs a set of files or the default target.
run {
/// Files to run.
files: Vec<String>,
},
/// Runs tests contained within a particular test file or
test {
/// Wether to capture standard output or not.
#[clap(short, long)]
capture: bool,
/// Files to run tests from.
files: Vec<String>,
/// Specific tests to run.
#[clap(short, long)]
tests: Vec<String>,
},
}
fn append_includes(list: &mut Vec<String>) {
list.extend(
Config::get_current()
@ -81,6 +105,9 @@ fn main() {
match args.command {
Commands::check { files } => check::main(files),
Commands::run { mut files } => {
if files.is_empty() {
files.push(Config::get_current().main_file().to_string());
}
append_includes(&mut files);
let args = compilation_args();
run::main(files, args);
@ -95,11 +122,30 @@ fn main() {
let tests = (!tests.is_empty()).then_some(tests);
test::main(capture, files, tests)
}
Commands::watch { mut files } => {
Commands::watch {
command: WatchSubcommand::run { mut files },
} => {
append_includes(&mut files);
let args = compilation_args();
watch::main(files, args)
let files = files.clone();
watch::main(files, move || {
run::main(files.clone(), args.clone());
})
}
Commands::watch {
command: WatchSubcommand::test {
mut files,
tests,
capture,
},
} => {
append_includes(&mut files);
let args = compilation_args();
watch::main(files, move || {
run::main(files.clone(), args.clone());
})
}
Commands::init { path } => config::create(path),
}
}