Bläddra i källkod

feat(cli): add --amount flag to send command (#1401)

* feat(cli): add --amount flag to send command

Problem:
The send command always prompted for the amount interactively,
making it difficult to use in scripts or one-line commands.

Solution:
Added an optional --amount (-a) flag that allows users to specify
the amount directly. When not provided, it falls back to the
interactive prompt, maintaining backward compatibility.

Usage:
  cdk-cli send --mint-url <URL> --amount 1000
  cdk-cli send --mint-url <URL>  # still prompts for amount

* feat(cli): add --amount flag to pay-request command
shroominic 1 månad sedan
förälder
incheckning
4f17dea72c
2 ändrade filer med 25 tillägg och 14 borttagningar
  1. 15 10
      crates/cdk-cli/src/sub_commands/pay_request.rs
  2. 10 4
      crates/cdk-cli/src/sub_commands/send.rs

+ 15 - 10
crates/cdk-cli/src/sub_commands/pay_request.rs

@@ -9,6 +9,9 @@ use clap::Args;
 #[derive(Args)]
 pub struct PayRequestSubCommand {
     payment_request: PaymentRequest,
+    /// Amount to pay (required for amountless requests)
+    #[arg(short, long)]
+    amount: Option<u64>,
 }
 
 pub async fn pay_request(
@@ -19,21 +22,23 @@ pub async fn pay_request(
 
     let unit = &payment_request.unit;
 
-    // Determine amount: use from request or prompt user
     let amount: Amount = match payment_request.amount {
         Some(amount) => amount,
-        None => {
-            println!("Enter the amount you would like to pay");
+        None => match sub_command_args.amount {
+            Some(amt) => amt.into(),
+            None => {
+                println!("Enter the amount you would like to pay");
 
-            let mut user_input = String::new();
-            let stdin = io::stdin();
-            io::stdout().flush()?;
-            stdin.read_line(&mut user_input)?;
+                let mut user_input = String::new();
+                let stdin = io::stdin();
+                io::stdout().flush()?;
+                stdin.read_line(&mut user_input)?;
 
-            let amount: u64 = user_input.trim().parse()?;
+                let amount: u64 = user_input.trim().parse()?;
 
-            amount.into()
-        }
+                amount.into()
+            }
+        },
     };
 
     let request_mints = &payment_request.mints;

+ 10 - 4
crates/cdk-cli/src/sub_commands/send.rs

@@ -58,6 +58,9 @@ pub struct SendSubCommand {
     /// Specific mints to exclude from transfers (can be specified multiple times)
     #[arg(long, action = clap::ArgAction::Append)]
     excluded_mints: Vec<String>,
+    /// Amount to send
+    #[arg(short, long)]
+    amount: Option<u64>,
 }
 
 pub async fn send(
@@ -112,10 +115,13 @@ pub async fn send(
         }
     };
 
-    let token_amount = Amount::from(get_number_input::<u64>(&format!(
-        "Enter value of token in {}",
-        multi_mint_wallet.unit()
-    ))?);
+    let token_amount = match sub_command_args.amount {
+        Some(amount) => Amount::from(amount),
+        None => Amount::from(get_number_input::<u64>(&format!(
+            "Enter value of token in {}",
+            multi_mint_wallet.unit()
+        ))?),
+    };
 
     // Check total balance across all wallets
     let total_balance = multi_mint_wallet.total_balance().await?;