diff --git a/ocular_cli/src/commands/chains.rs b/ocular_cli/src/commands/chains.rs index 6c3a4bf8..cd0c122c 100644 --- a/ocular_cli/src/commands/chains.rs +++ b/ocular_cli/src/commands/chains.rs @@ -12,6 +12,7 @@ use abscissa_core::{config, Command, FrameworkError, Runnable}; use clap::Parser; use self::list::ListCmd; +use self::registry_list::RegistryListCmd; use self::show::ShowCmd; use self::show_default::ShowDefaultCmd; @@ -26,6 +27,7 @@ use self::show_default::ShowDefaultCmd; pub enum ChainsCmd { Show(ShowCmd), List(ListCmd), + RegistryList(RegistryListCmd), ShowDefault(ShowDefaultCmd), } diff --git a/ocular_cli/src/commands/chains/registry_list.rs b/ocular_cli/src/commands/chains/registry_list.rs index 8b137891..8e5babe0 100644 --- a/ocular_cli/src/commands/chains/registry_list.rs +++ b/ocular_cli/src/commands/chains/registry_list.rs @@ -1 +1,34 @@ +use crate::prelude::*; +use abscissa_core::{Command, Runnable}; +use clap::Parser; +use serde::Serialize; +#[derive(Command, Debug, Parser)] +pub struct RegistryListCmd {} + +impl Runnable for RegistryListCmd { + /// List all chains in local config file + fn run(&self) { + abscissa_tokio::run(&APP, async { + match ocular::chain::registry::list_chains().await { + Ok(mut info) => { + info.drain(0..1); + for info in info { + let info = info.as_str(); + let buf = Vec::new(); + let formatter = serde_json::ser::PrettyFormatter::with_indent(b" "); + let mut serialize = serde_json::Serializer::with_formatter(buf, formatter); + info.serialize(&mut serialize).unwrap(); + + println!("{}", String::from_utf8(serialize.into_inner()).unwrap()); + } + } + Err(err) => error!("{}", err), + } + }) + .unwrap_or_else(|e| { + status_err!("executor exited with error: {}", e); + std::process::exit(1); + }); + } +}