making watch into a switch between run and test
This commit is contained in:
parent
6ef3993f8f
commit
c6baef23c2
2 changed files with 52 additions and 9 deletions
54
src/main.rs
54
src/main.rs
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,12 +24,9 @@ impl Repeater {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn main(files: Vec<String>, args: Vec<String>) {
|
||||
pub fn main(files: Vec<String>, op: impl Fn() + 'static) {
|
||||
log_process(&format!("watching files '{files:?}'"));
|
||||
let passed = files.clone();
|
||||
let repeater = Repeater::new(move || {
|
||||
crate::run::main(passed.clone(), args.clone());
|
||||
});
|
||||
let repeater = Repeater::new(op);
|
||||
repeater.repeat();
|
||||
|
||||
let (send, rec) = mpsc::channel();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue