fix(cli): simplify running the CLI by hiding the maestro inside the implemtation (#93)

Co-authored-by: Ian Letourneau <letourneau.ian@gmail.com>
Reviewed-on: NationTech/harmony#93
This commit is contained in:
2025-08-04 20:59:07 +00:00
parent 06aab1f57f
commit 54990cd1a5
10 changed files with 99 additions and 95 deletions

View File

@@ -1,8 +1,10 @@
use clap::Parser;
use clap::builder::ArgPredicate;
use harmony;
use harmony::inventory::Inventory;
use harmony::maestro::Maestro;
use harmony::{score::Score, topology::Topology};
use inquire::Confirm;
use log::debug;
pub mod cli_logger; // FIXME: Don't make me pub
pub mod progress;
@@ -10,7 +12,6 @@ pub mod theme;
#[cfg(feature = "tui")]
use harmony_tui;
use log::debug;
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
@@ -85,7 +86,24 @@ fn list_scores_with_index<T: Topology>(scores_vec: &Vec<Box<dyn Score<T>>>) -> S
return display_str;
}
pub async fn init<T: Topology + Send + Sync + 'static>(
pub async fn run<T: Topology + Send + Sync + 'static>(
inventory: Inventory,
topology: T,
scores: Vec<Box<dyn Score<T>>>,
args_struct: Option<Args>,
) -> Result<(), Box<dyn std::error::Error>> {
let cli_logger_handle = cli_logger::init();
let mut maestro = Maestro::initialize(inventory, topology).await.unwrap();
maestro.register_all(scores);
let result = init(maestro, args_struct).await;
let _ = tokio::try_join!(cli_logger_handle);
result
}
async fn init<T: Topology + Send + Sync + 'static>(
maestro: harmony::maestro::Maestro<T>,
args_struct: Option<Args>,
) -> Result<(), Box<dyn std::error::Error>> {