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 9, 2024
1 parent 07c2d99 commit d206ac7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
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 @@ -56,6 +56,7 @@ env_logger = "0.11.1"
log = "0.4.20"
dialoguer = "0.11.0"
prettytable = "0.10.0"
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(())
}
9 changes: 9 additions & 0 deletions 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 docs;
Expand All @@ -15,6 +16,7 @@ mod sandbox;
mod term;
mod utils;

use clap_complete::Shell;
use config::Config;
use error::Result;
use log::debug;
Expand All @@ -38,6 +40,12 @@ enum Command {
/// 🔑 Interact with jstz's key-value store.
#[command(subcommand)]
Kv(kv::Command),
/// 🐚 Generates shell completions.
Completions {
/// The shell to generate completions for
#[arg(long, short)]
shell: Shell,
},
/// 🚀 Deploys a smart function to jstz.
Deploy {
/// Function code.
Expand Down Expand Up @@ -90,6 +98,7 @@ enum Command {
async fn exec(command: Command) -> Result<()> {
match command {
Command::Docs => docs::exec(),
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 d206ac7

Please sign in to comment.