add index to display
This commit is contained in:
parent
f75d03c570
commit
92e60b00d2
@ -28,7 +28,8 @@ pub struct Args {
|
|||||||
long,
|
long,
|
||||||
default_value_t = true,
|
default_value_t = true,
|
||||||
default_value_if("number", ArgPredicate::IsPresent, "false"),
|
default_value_if("number", ArgPredicate::IsPresent, "false"),
|
||||||
conflicts_with = "number"
|
conflicts_with = "number",
|
||||||
|
conflicts_with = "list"
|
||||||
)]
|
)]
|
||||||
all: bool,
|
all: bool,
|
||||||
|
|
||||||
@ -69,6 +70,17 @@ fn maestro_scores_filter<T: Topology + std::fmt::Debug + Send + Sync + 'static>(
|
|||||||
return scores_vec;
|
return scores_vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn list_scores_with_index<T: Topology + std::fmt::Debug + Send + Sync + 'static>(
|
||||||
|
scores_vec: &Vec<Box<dyn Score<T>>>,
|
||||||
|
) -> String {
|
||||||
|
let mut display_str = String::new();
|
||||||
|
for (i, s) in scores_vec.iter().enumerate() {
|
||||||
|
let name = s.name();
|
||||||
|
display_str.push_str(&format!("\n{i}: {name}"));
|
||||||
|
}
|
||||||
|
return display_str;
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn init<T: Topology + std::fmt::Debug + Send + Sync + 'static>(
|
pub async fn init<T: Topology + std::fmt::Debug + Send + Sync + 'static>(
|
||||||
maestro: harmony::maestro::Maestro<T>,
|
maestro: harmony::maestro::Maestro<T>,
|
||||||
args_struct: Option<Args>,
|
args_struct: Option<Args>,
|
||||||
@ -94,25 +106,31 @@ pub async fn init<T: Topology + std::fmt::Debug + Send + Sync + 'static>(
|
|||||||
return Err("No score found".into());
|
return Err("No score found".into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if list option is specified, print filtered list and exit
|
||||||
|
if args.list {
|
||||||
|
println!("Available scores:");
|
||||||
|
println!("{}", list_scores_with_index(&scores_vec));
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
// if no score to run provided, and list isn't specified, print help
|
// if no score to run provided, and list isn't specified, print help
|
||||||
if !args.yes {
|
if !args.yes {
|
||||||
let confirmation =
|
let confirmation = Confirm::new(
|
||||||
Confirm::new(format!("This will run the following scores: {:#?}", scores_vec).as_str())
|
format!(
|
||||||
.with_default(true)
|
"This will run the following scores: {}\n",
|
||||||
.prompt()
|
list_scores_with_index(&scores_vec)
|
||||||
.expect("Unexpected prompt error");
|
)
|
||||||
|
.as_str(),
|
||||||
|
)
|
||||||
|
.with_default(true)
|
||||||
|
.prompt()
|
||||||
|
.expect("Unexpected prompt error");
|
||||||
|
|
||||||
if !confirmation {
|
if !confirmation {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if list option is specified, print filtered list and exit
|
|
||||||
if args.list {
|
|
||||||
println!("Available scores: {:#?}", scores_vec);
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
// if all is specified, run all. Otherwise, run the first match or specified index
|
// if all is specified, run all. Otherwise, run the first match or specified index
|
||||||
for s in scores_vec {
|
for s in scores_vec {
|
||||||
println!("Running: {}", s.name());
|
println!("Running: {}", s.name());
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user