|
|
|
|
@@ -1,5 +1,5 @@
|
|
|
|
|
use clap::Parser;
|
|
|
|
|
use clap::builder::ArgPredicate;
|
|
|
|
|
use clap::{Arg, CommandFactory, Parser};
|
|
|
|
|
use harmony;
|
|
|
|
|
use harmony::{score::Score, topology::Topology};
|
|
|
|
|
|
|
|
|
|
@@ -14,9 +14,9 @@ struct Args {
|
|
|
|
|
#[arg(
|
|
|
|
|
short,
|
|
|
|
|
long,
|
|
|
|
|
default_value_if("interactive", ArgPredicate::IsPresent, Some("unused"))
|
|
|
|
|
default_value_if("interactive", ArgPredicate::IsPresent, Some(""))
|
|
|
|
|
)]
|
|
|
|
|
run: String,
|
|
|
|
|
run: Option<String>,
|
|
|
|
|
|
|
|
|
|
/// Name of score to run
|
|
|
|
|
#[cfg(not(feature = "tui"))]
|
|
|
|
|
@@ -34,6 +34,10 @@ struct Args {
|
|
|
|
|
/// Run nth matching, zero indexed
|
|
|
|
|
#[arg(short, long, default_value_t = 0)]
|
|
|
|
|
number: u8,
|
|
|
|
|
|
|
|
|
|
/// list scores, will also be affected by run filter
|
|
|
|
|
#[arg(short, long, default_value_t = false)]
|
|
|
|
|
list: bool,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn init<T: Topology + std::fmt::Debug + Send + Sync + 'static>(
|
|
|
|
|
@@ -51,24 +55,40 @@ pub async fn init<T: Topology + std::fmt::Debug + Send + Sync + 'static>(
|
|
|
|
|
return Err("Not compiled with interactive support".into());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if no score to run provided, and list isn't specified, print help
|
|
|
|
|
if args.run.is_none() && !args.list {
|
|
|
|
|
Args::command().print_help();
|
|
|
|
|
return Ok(());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let scores = maestro.scores();
|
|
|
|
|
let scores_read = scores.read().expect("Should be able to read scores");
|
|
|
|
|
let filtered: Vec<Box<dyn Score<T>>> = scores_read
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|s| s.clone_box())
|
|
|
|
|
.filter(|s| s.name().contains(&args.run))
|
|
|
|
|
.collect();
|
|
|
|
|
let scores_vec: Vec<Box<dyn Score<T>>> = match args.run.clone() {
|
|
|
|
|
Some(filter) => scores_read
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|s| s.clone_box())
|
|
|
|
|
.filter(|s| s.name().contains(&filter))
|
|
|
|
|
.collect(),
|
|
|
|
|
None => scores_read.iter().map(|s| s.clone_box()).collect(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if filtered.len() == 0 {
|
|
|
|
|
// if list option is specified, print filtered list and exit
|
|
|
|
|
if args.list {
|
|
|
|
|
println!("Available scores: {:#?}", scores_vec);
|
|
|
|
|
return Ok(());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if scores_vec.len() == 0 {
|
|
|
|
|
return Err("No score containing query found".into());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if all is specified, run all. Otherwise, run the first match or specified index
|
|
|
|
|
if args.all {
|
|
|
|
|
for s in filtered {
|
|
|
|
|
for s in scores_vec {
|
|
|
|
|
println!("Running: {}", s.clone_box().name());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
let score = filtered.get(args.number as usize);
|
|
|
|
|
let score = scores_vec.get(args.number as usize);
|
|
|
|
|
match score {
|
|
|
|
|
Some(s) => println!("Running: {}", s.clone_box().name()),
|
|
|
|
|
None => return Err("Invalid index given".into()),
|
|
|
|
|
|