Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI auto-completions #1789

Merged
merged 4 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
26 changes: 8 additions & 18 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