Skip to content

Commit

Permalink
CLI auto-completions (informalsystems#1789)
Browse files Browse the repository at this point in the history
cli: Add completions command using clap_complete
  • Loading branch information
mzabaluev committed Jan 19, 2022
1 parent 0e6cf72 commit c112255
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add `completions` CLI command to generate shell auto-completion scripts.
([#1789](https://github.com/informalsystems/ibc-rs/pull/1789))
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions relayer-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
37 changes: 21 additions & 16 deletions relayer-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<PathBuf> {
dirs_next::home_dir().map(|home| home.join(DEFAULT_CONFIG_PATH))
Expand Down Expand Up @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions relayer-cli/src/commands/completions.rs
Original file line number Diff line number Diff line change
@@ -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());
}
}
1 change: 0 additions & 1 deletion relayer/src/chain.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down

0 comments on commit c112255

Please sign in to comment.