feat: harmony-cli v0.1 #8 #9

Merged
taha merged 23 commits from harmony-cli into master 2025-04-19 01:13:40 +00:00
9 changed files with 1267 additions and 382 deletions
Showing only changes of commit 92e60b00d2 - Show all commits

View File

@@ -28,7 +28,8 @@ pub struct Args {
long,
default_value_t = true,
default_value_if("number", ArgPredicate::IsPresent, "false"),
conflicts_with = "number"
conflicts_with = "number",
conflicts_with = "list"
)]
all: bool,
@@ -69,6 +70,17 @@ fn maestro_scores_filter<T: Topology + std::fmt::Debug + Send + Sync + 'static>(
return scores_vec;
}
fn list_scores_with_index<T: Topology + std::fmt::Debug + Send + Sync + 'static>(

This function, though pretty simple, deserves a test. Could be a good place for a doctest. Not necessary though, just spilling my thoughts.

This function, though pretty simple, deserves a test. Could be a good place for a doctest. Not necessary though, just spilling my thoughts.
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>(
maestro: harmony::maestro::Maestro<T>,
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());
}
// 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

Either I don't understand it or it's an outdated comment, I think those types of comment explaining WHAT the code is doing are generally bad. Comments should explain WHY. If you need to express a WHAT, use a function.

https://news.ycombinator.com/item?id=8073620

Either I don't understand it or it's an outdated comment, I think those types of comment explaining WHAT the code is doing are generally bad. Comments should explain WHY. If you need to express a WHAT, use a function. https://news.ycombinator.com/item?id=8073620
if !args.yes {
let confirmation =
Confirm::new(format!("This will run the following scores: {:#?}", scores_vec).as_str())
.with_default(true)
.prompt()
.expect("Unexpected prompt error");
let confirmation = Confirm::new(
format!(
"This will run the following scores: {}\n",
list_scores_with_index(&scores_vec)
)
.as_str(),
)
.with_default(true)
.prompt()
.expect("Unexpected prompt error");
if !confirmation {
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

Weird comment here again, does not relate directly to the code block. I think I'd rather not have it.

Weird comment here again, does not relate directly to the code block. I think I'd rather not have it.
for s in scores_vec {
println!("Running: {}", s.name());