Skip to content

Commit

Permalink
feat(zfctl): implement InstanceQuery::List reply (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hennzau authored Dec 11, 2024
1 parent 23bae3b commit 3f6b357
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions zfctl/src/instance_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@
// ZettaScale Zenoh Team, <zenoh@zettascale.tech>
//

use std::path::PathBuf;
use std::{collections::HashMap, path::PathBuf, sync::Arc};

use anyhow::{anyhow, bail};
use clap::Subcommand;
use comfy_table::Table;
use itertools::Itertools;
use uuid::Uuid;
use zenoh::prelude::r#async::*;
use zenoh_flow_commons::{parse_vars, Result, RuntimeId, Vars};
use zenoh_flow_commons::{parse_vars, InstanceId, Result, RuntimeId, Vars};
use zenoh_flow_daemon::queries::*;
use zenoh_flow_descriptors::{DataFlowDescriptor, FlattenedDataFlowDescriptor};
use zenoh_flow_runtime::InstanceState;

use super::ZENOH_FLOW_INTERNAL_ERROR;
use crate::row;
Expand Down Expand Up @@ -195,6 +196,34 @@ Caused by:

println!("{table}");
}
InstancesQuery::List => {
let mut table = Table::new();
table.set_width(80);
table.set_header(row!("Instance Name", "Instance ID", "Instance State"));
while let Ok(response) = reply.recv_async().await {
match response.sample {
Ok(sample) => {
match serde_json::from_slice::<
HashMap<InstanceId, (Arc<str>, InstanceState)>,
>(&sample.value.payload.contiguous())
{
Ok(list) => {
for (id, (name, state)) in list {
table.add_row(row!(name, id, state));
}
}
Err(e) => tracing::error!(
"Failed to parse 'list' reply from < {} >: {:?}",
response.replier_id,
e
),
}
}
Err(err) => tracing::error!("{:?}", err),
}
}
println!("{table}");
}
_ => {}
}

Expand Down

0 comments on commit 3f6b357

Please sign in to comment.