diff --git a/.changelog/unreleased/improvements/ibc-relayer-cli/1789-cli-completions.md b/.changelog/unreleased/improvements/ibc-relayer-cli/1789-cli-completions.md new file mode 100644 index 0000000000..7d46b207e3 --- /dev/null +++ b/.changelog/unreleased/improvements/ibc-relayer-cli/1789-cli-completions.md @@ -0,0 +1,2 @@ +- Add `completions` CLI command to generate shell auto-completion scripts. + ([#1789](https://github.com/informalsystems/ibc-rs/pull/1789)) diff --git a/Cargo.lock b/Cargo.lock index 7fa9be5aa0..79c1a28c4e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1422,6 +1422,7 @@ dependencies = [ "abscissa_core", "atty", "clap", + "clap_complete", "color-eyre 0.6.0", "crossbeam-channel 0.5.2", "dirs-next", diff --git a/relayer-cli/Cargo.toml b/relayer-cli/Cargo.toml index f7fbaf7807..bd15e1c5cf 100644 --- a/relayer-cli/Cargo.toml +++ b/relayer-cli/Cargo.toml @@ -33,6 +33,7 @@ ibc-telemetry = { version = "0.10.0", path = "../telemetry", optional = true ibc-relayer-rest = { version = "0.10.0", path = "../relayer-rest", optional = true } clap = { version = "3.0", features = ["cargo"] } +clap_complete = "3.0" serde = { version = "1.0", features = ["serde_derive"] } tokio = { version = "1.0", features = ["full"] } tracing = "0.1.29" diff --git a/relayer-cli/src/commands.rs b/relayer-cli/src/commands.rs index d29760a0e5..48564c240f 100644 --- a/relayer-cli/src/commands.rs +++ b/relayer-cli/src/commands.rs @@ -5,22 +5,7 @@ //! See the `impl Configurable` below for how to specify the path to the //! application's configuration file. -use core::time::Duration; -use std::path::PathBuf; - -use abscissa_core::clap::Parser; -use abscissa_core::{config::Override, Command, Configurable, FrameworkError, Runnable}; -use tracing::{error, info}; - -use crate::DEFAULT_CONFIG_PATH; -use ibc_relayer::config::Config; - -use self::{ - config::ConfigCmd, create::CreateCmds, health::HealthCheckCmd, keys::KeysCmd, - listen::ListenCmd, misbehaviour::MisbehaviourCmd, query::QueryCmd, start::StartCmd, tx::TxCmd, - update::UpdateCmds, upgrade::UpgradeCmds, version::VersionCmd, -}; - +mod completions; mod config; mod create; mod health; @@ -34,6 +19,22 @@ mod update; mod upgrade; mod version; +use self::{ + completions::CompletionsCmd, config::ConfigCmd, create::CreateCmds, health::HealthCheckCmd, + keys::KeysCmd, listen::ListenCmd, misbehaviour::MisbehaviourCmd, query::QueryCmd, + start::StartCmd, tx::TxCmd, update::UpdateCmds, upgrade::UpgradeCmds, version::VersionCmd, +}; + +use core::time::Duration; +use std::path::PathBuf; + +use abscissa_core::clap::Parser; +use abscissa_core::{config::Override, Command, Configurable, FrameworkError, Runnable}; +use tracing::{error, info}; + +use crate::DEFAULT_CONFIG_PATH; +use ibc_relayer::config::Config; + /// Default configuration file path pub fn default_config_file() -> Option { dirs_next::home_dir().map(|home| home.join(DEFAULT_CONFIG_PATH)) @@ -86,6 +87,10 @@ pub enum CliCmd { /// Performs a health check of all chains in the the config HealthCheck(HealthCheckCmd), + + /// Generate auto-complete scripts for different shells. + #[clap(display_order = 1000)] + Completions(CompletionsCmd), } /// This trait allows you to define how application configuration is loaded. diff --git a/relayer-cli/src/commands/completions.rs b/relayer-cli/src/commands/completions.rs new file mode 100644 index 0000000000..0a58ba067f --- /dev/null +++ b/relayer-cli/src/commands/completions.rs @@ -0,0 +1,20 @@ +use crate::entry::EntryPoint; +use abscissa_core::clap::Parser; +use abscissa_core::Runnable; +use clap::IntoApp; +use clap_complete::Shell; +use std::io; + +#[derive(Debug, Parser)] +pub struct CompletionsCmd { + #[clap(arg_enum)] + shell: Shell, +} + +impl Runnable for CompletionsCmd { + fn run(&self) { + let mut app = EntryPoint::into_app(); + let app_name = app.get_name().to_owned(); + clap_complete::generate(self.shell, &mut app, app_name, &mut io::stdout()); + } +} diff --git a/relayer/src/chain.rs b/relayer/src/chain.rs index b5b4ee2724..ec3a87c923 100644 --- a/relayer/src/chain.rs +++ b/relayer/src/chain.rs @@ -1,7 +1,6 @@ use alloc::sync::Arc; use core::convert::TryFrom; -use prost_types::Any; use tendermint::block::Height; use tokio::runtime::Runtime as TokioRuntime;