Skip to content

Commit

Permalink
feat(cli): add completions command to jstz
Browse files Browse the repository at this point in the history
  • Loading branch information
johnyob committed Feb 8, 2024
1 parent 6b37287 commit f844594
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
10 changes: 10 additions & 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 crates/jstz_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ crossterm = "0.27"
ansi_term = "0.12.1"
console = "0.15.8"
futures = "0.3"
clap_complete = "4.4.10"

[[bin]]
name = "jstz"
Expand Down
12 changes: 12 additions & 0 deletions crates/jstz_cli/src/completions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use std::io;

use clap::CommandFactory;
use clap_complete::Shell;

use crate::{error::Result, Command};

pub fn exec(shell: Shell) -> Result<()> {
let cmd = &mut Command::command();
clap_complete::generate(shell, cmd, "jstz", &mut io::stdout());
Ok(())
}
11 changes: 10 additions & 1 deletion crates/jstz_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use clap::Parser;

mod account;
mod bridge;
mod completions;
mod config;
mod deploy;
mod error;
Expand All @@ -14,14 +15,15 @@ mod sandbox;
mod term;
mod utils;

use clap_complete::Shell;
use config::Config;
use error::Result;
use run::DEFAULT_GAS_LIMIT;
use utils::AddressOrAlias;

#[derive(Parser)]
#[command(author, version)]
enum Command {
pub enum Command {
/// Commands related to the jstz sandbox.
#[command(subcommand)]
Sandbox(sandbox::Command),
Expand All @@ -31,6 +33,12 @@ enum Command {
/// Commands related to the account management
#[command(subcommand)]
Account(account::Command),
/// Generates shell completions
Completions {
/// The shell to generate completions for
#[arg(long, short)]
shell: Shell,
},
/// Deploys a smart function
Deploy {
/// Function code.
Expand Down Expand Up @@ -85,6 +93,7 @@ enum Command {

async fn exec(command: Command) -> Result<()> {
match command {
Command::Completions { shell } => completions::exec(shell),
Command::Sandbox(sandbox_command) => sandbox::exec(sandbox_command).await,
Command::Bridge(bridge_command) => bridge::exec(bridge_command),
Command::Account(account_command) => account::exec(account_command).await,
Expand Down

0 comments on commit f844594

Please sign in to comment.