Updates to address comments
This commit is contained in:
parent
508ca3352d
commit
0a5d3b531a
@ -15,13 +15,14 @@ This is the harmony CLI, a minimal implementation
|
|||||||
The current help text:
|
The current help text:
|
||||||
|
|
||||||
```
|
```
|
||||||
Usage: example-cli [OPTIONS] --run <RUN>
|
Usage: example-cli [OPTIONS]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-r, --run <RUN> Name of score to run
|
-r, --run <RUN> Name of score to run
|
||||||
-i, --interactive Run interactive or not
|
-i, --interactive Run interactive or not
|
||||||
-a, --all Run all or nth
|
-a, --all Run all or nth
|
||||||
-n, --number <NUMBER> Run nth matching, zero indexed [default: 0]
|
-n, --number <NUMBER> Run nth matching, zero indexed [default: 0]
|
||||||
|
-l, --list list scores, will also be affected by run filter
|
||||||
-h, --help Print help
|
-h, --help Print help
|
||||||
-V, --version Print version
|
-V, --version Print version
|
||||||
```
|
```
|
||||||
|
|||||||
@ -12,4 +12,5 @@ harmony_tui = { path = "../harmony_tui", optional = true }
|
|||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
default = ["tui"]
|
||||||
tui = ["dep:harmony_tui"]
|
tui = ["dep:harmony_tui"]
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use clap::Parser;
|
|
||||||
use clap::builder::ArgPredicate;
|
use clap::builder::ArgPredicate;
|
||||||
|
use clap::{Arg, CommandFactory, Parser};
|
||||||
use harmony;
|
use harmony;
|
||||||
use harmony::{score::Score, topology::Topology};
|
use harmony::{score::Score, topology::Topology};
|
||||||
|
|
||||||
@ -14,9 +14,9 @@ struct Args {
|
|||||||
#[arg(
|
#[arg(
|
||||||
short,
|
short,
|
||||||
long,
|
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
|
/// Name of score to run
|
||||||
#[cfg(not(feature = "tui"))]
|
#[cfg(not(feature = "tui"))]
|
||||||
@ -34,6 +34,10 @@ struct Args {
|
|||||||
/// Run nth matching, zero indexed
|
/// Run nth matching, zero indexed
|
||||||
#[arg(short, long, default_value_t = 0)]
|
#[arg(short, long, default_value_t = 0)]
|
||||||
number: u8,
|
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>(
|
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());
|
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 = maestro.scores();
|
||||||
let scores_read = scores.read().expect("Should be able to read scores");
|
let scores_read = scores.read().expect("Should be able to read scores");
|
||||||
let filtered: Vec<Box<dyn Score<T>>> = scores_read
|
let scores_vec: Vec<Box<dyn Score<T>>> = match args.run.clone() {
|
||||||
.iter()
|
Some(filter) => scores_read
|
||||||
.map(|s| s.clone_box())
|
.iter()
|
||||||
.filter(|s| s.name().contains(&args.run))
|
.map(|s| s.clone_box())
|
||||||
.collect();
|
.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());
|
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 {
|
if args.all {
|
||||||
for s in filtered {
|
for s in scores_vec {
|
||||||
println!("Running: {}", s.clone_box().name());
|
println!("Running: {}", s.clone_box().name());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let score = filtered.get(args.number as usize);
|
let score = scores_vec.get(args.number as usize);
|
||||||
match score {
|
match score {
|
||||||
Some(s) => println!("Running: {}", s.clone_box().name()),
|
Some(s) => println!("Running: {}", s.clone_box().name()),
|
||||||
None => return Err("Invalid index given".into()),
|
None => return Err("Invalid index given".into()),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user