feature(kratactl): rework cli to use subcommands (#268)

This commit is contained in:
Alex Zenla
2024-07-18 23:13:29 -07:00
committed by GitHub
parent 04665ce690
commit 75901233b1
25 changed files with 418 additions and 249 deletions

View File

@ -0,0 +1,29 @@
use anyhow::Result;
use clap::Parser;
use krata::v1::control::{control_service_client::ControlServiceClient, ResolveZoneRequest};
use tonic::{transport::Channel, Request};
#[derive(Parser)]
#[command(about = "Resolve a zone name to a uuid")]
pub struct ZoneResolveCommand {
#[arg(help = "Zone name")]
zone: String,
}
impl ZoneResolveCommand {
pub async fn run(self, mut client: ControlServiceClient<Channel>) -> Result<()> {
let reply = client
.resolve_zone(Request::new(ResolveZoneRequest {
name: self.zone.clone(),
}))
.await?
.into_inner();
if let Some(zone) = reply.zone {
println!("{}", zone.id);
} else {
std::process::exit(1);
}
Ok(())
}
}