diff --git a/Cargo.lock b/Cargo.lock index 26a3032..0907264 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1257,6 +1257,15 @@ dependencies = [ "strsim", ] +[[package]] +name = "clap_complete" +version = "4.5.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c757a3b7e39161a4e56f9365141ada2a6c915a8622c408ab6bb4b5d047371031" +dependencies = [ + "clap", +] + [[package]] name = "clap_derive" version = "4.5.55" @@ -1798,7 +1807,7 @@ checksum = "0ce92ff622d6dadf7349484f42c93271a0d49b7cc4d466a936405bacbe10aa78" dependencies = [ "cfg-if", "rustix", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2973,6 +2982,7 @@ dependencies = [ "assert_cmd", "chrono", "clap", + "clap_complete", "dirs", "polymarket-client-sdk", "predicates", diff --git a/Cargo.toml b/Cargo.toml index a01bf05..b782457 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ path = "src/main.rs" polymarket-client-sdk = { version = "0.4", features = ["gamma", "data", "bridge", "clob", "ctf"] } alloy = { version = "1.6.3", default-features = false, features = ["providers", "sol-types", "contract", "reqwest", "reqwest-rustls-tls", "signer-local", "signers"] } clap = { version = "4", features = ["derive"] } +clap_complete = "4" tokio = { version = "1", features = ["rt-multi-thread", "macros"] } serde_json = "1" serde = { version = "1", features = ["derive"] } diff --git a/src/main.rs b/src/main.rs index 2abb55f..3cd206a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,8 @@ mod shell; use std::process::ExitCode; -use clap::{Parser, Subcommand}; +use clap::{CommandFactory, Parser, Subcommand}; +use clap_complete::Shell; use output::OutputFormat; #[derive(Parser)] @@ -64,6 +65,11 @@ enum Commands { Status, /// Update to the latest version Upgrade, + /// Generate shell completions + Completions { + /// Shell to generate completions for + shell: Shell, + }, } #[tokio::main] @@ -117,6 +123,15 @@ pub(crate) async fn run(cli: Cli) -> anyhow::Result<()> { commands::wallet::execute(args, cli.output, cli.private_key.as_deref()) } Commands::Upgrade => commands::upgrade::execute(), + Commands::Completions { shell } => { + clap_complete::generate( + shell, + &mut Cli::command(), + "polymarket", + &mut std::io::stdout(), + ); + Ok(()) + } Commands::Status => { let status = gamma.status().await?; match cli.output {