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

Co-authored-by: tahahawa <tahahawa@gmail.com>
Reviewed-on: NationTech/harmony#9
Reviewed-by: johnride <jg@nationtech.io>
Co-authored-by: Taha Hawa <taha@taha.dev>
Co-committed-by: Taha Hawa <taha@taha.dev>
This commit is contained in:
2025-04-19 01:13:40 +00:00
committed by taha
parent 0ba7f2536c
commit abd20b96a2
8 changed files with 1205 additions and 385 deletions

19
examples/cli/Cargo.toml Normal file
View File

@@ -0,0 +1,19 @@
[package]
name = "example-cli"
edition = "2024"
version.workspace = true
readme.workspace = true
license.workspace = true
publish = false
[dependencies]
harmony = { path = "../../harmony" }
harmony_cli = { path = "../../harmony_cli" }
harmony_types = { path = "../../harmony_types" }
cidr = { workspace = true }
tokio = { workspace = true }
harmony_macros = { path = "../../harmony_macros" }
log = { workspace = true }
env_logger = { workspace = true }
url = { workspace = true }
assert_cmd = "2.0.16"

38
examples/cli/src/main.rs Normal file
View File

@@ -0,0 +1,38 @@
use harmony::{
inventory::Inventory,
maestro::Maestro,
modules::dummy::{ErrorScore, PanicScore, SuccessScore},
topology::HAClusterTopology,
};
#[tokio::main]
async fn main() {
let inventory = Inventory::autoload();
let topology = HAClusterTopology::autoload();
let mut maestro = Maestro::new(inventory, topology);
maestro.register_all(vec![
Box::new(SuccessScore {}),
Box::new(ErrorScore {}),
Box::new(PanicScore {}),
]);
harmony_cli::init(maestro, None).await.unwrap();
}
use assert_cmd::Command;
#[test]
fn test_example_success() {
let mut cmd = Command::cargo_bin("example-cli").unwrap();
let assert = cmd.args(&["--yes", "--filter", "SuccessScore"]).assert();
assert.success();
}
#[test]
fn test_example_fail() {
let mut cmd_fail = Command::cargo_bin("example-cli").unwrap();
let assert_fail = cmd_fail.args(&["--yes", "--filter", "ErrorScore"]).assert();
assert_fail.failure();
}