Procházet zdrojové kódy

bin/drk: shell tab completions added

Dastan-glitch před 3 roky
rodič
revize
e972d3cfb4
3 změnil soubory, kde provedl 25 přidání a 1 odebrání
  1. 10 0
      Cargo.lock
  2. 1 0
      bin/drk/Cargo.toml
  3. 14 1
      bin/drk/src/main.rs

+ 10 - 0
Cargo.lock

@@ -612,6 +612,15 @@ dependencies = [
  "termcolor",
 ]
 
+[[package]]
+name = "clap_complete"
+version = "4.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bd125be87bf4c255ebc50de0b7f4d2a6201e8ac3dc86e39c0ad081dc5e7236fe"
+dependencies = [
+ "clap 4.1.4",
+]
+
 [[package]]
 name = "clap_derive"
 version = "4.1.0"
@@ -1528,6 +1537,7 @@ dependencies = [
  "blake3",
  "bs58",
  "clap 4.1.4",
+ "clap_complete",
  "darkfi",
  "darkfi-dao-contract",
  "darkfi-money-contract",

+ 1 - 0
bin/drk/Cargo.toml

@@ -17,6 +17,7 @@ async-std = {version = "1.12.0", features = ["attributes"]}
 blake3 = "1.3.3"
 bs58 = "0.4.0"
 clap = {version = "4.1.4", features = ["derive"]}
+clap_complete = "4.1.2"
 darkfi = {path = "../../", features = ["blockchain", "rpc", "util", "wallet"]}
 darkfi-sdk = {path = "../../src/sdk"}
 darkfi-serial = {path = "../../src/serial", features = ["derive", "crypto"]}

+ 14 - 1
bin/drk/src/main.rs

@@ -24,7 +24,8 @@ use std::{
 };
 
 use anyhow::{anyhow, Context, Result};
-use clap::{Parser, Subcommand};
+use clap::{CommandFactory, Parser, Subcommand};
+use clap_complete::{generate, Shell};
 use darkfi::{tx::Transaction, util::parse::decode_base10, zk::halo2::Field};
 use darkfi_money_contract::client::Coin;
 use darkfi_sdk::{
@@ -94,6 +95,12 @@ enum Subcmd {
     /// Send a ping request to the darkfid RPC endpoint
     Ping,
 
+    /// Generate a SHELL completion script and print to stdout
+    Completions {
+        /// The Shell you want to generate script for
+        shell: Shell,
+    },
+
     /// Wallet operations
     Wallet {
         #[arg(long)]
@@ -415,6 +422,12 @@ async fn main() -> Result<()> {
 
             Ok(())
         }
+        Subcmd::Completions { shell } => {
+            let mut cmd = Args::command();
+            generate(shell, &mut cmd, "./drk", &mut std::io::stdout());
+
+            Ok(())
+        }
 
         Subcmd::Wallet {
             initialize,