From 46c32387b5289f4740142518550e7bf9bceb09cc Mon Sep 17 00:00:00 2001 From: Gleb Date: Fri, 27 Sep 2024 18:45:25 -0400 Subject: [PATCH] Add warning on no fund flag --- FULL_HELP_DOCS.md | 3 +++ cmd/soroban-cli/src/commands/keys/generate.rs | 16 +++++++++++++++- cmd/soroban-cli/src/commands/keys/mod.rs | 5 +++-- cmd/soroban-cli/src/commands/mod.rs | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/FULL_HELP_DOCS.md b/FULL_HELP_DOCS.md index 479ac6720..f86509507 100644 --- a/FULL_HELP_DOCS.md +++ b/FULL_HELP_DOCS.md @@ -983,6 +983,9 @@ Generate a new identity with a seed phrase, currently 12 words * `--rpc-url ` — RPC server endpoint * `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config +* `--fund` — Fund generated key pair + + Default value: `false` diff --git a/cmd/soroban-cli/src/commands/keys/generate.rs b/cmd/soroban-cli/src/commands/keys/generate.rs index 16e6a7fdb..225bb39d8 100644 --- a/cmd/soroban-cli/src/commands/keys/generate.rs +++ b/cmd/soroban-cli/src/commands/keys/generate.rs @@ -1,3 +1,5 @@ +use crate::commands::global; +use crate::print::Print; use clap::{arg, command}; use super::super::config::{ @@ -46,10 +48,22 @@ pub struct Cmd { #[command(flatten)] pub network: network::Args, + + /// Fund generated key pair + #[arg(long, default_value = "false")] + pub fund: bool, } impl Cmd { - pub async fn run(&self) -> Result<(), Error> { + pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> { + if !self.fund { + Print::new(global_args.quiet).warnln( + "Behavior of `generate` will change in the \ + future, and it will no longer fund by default. If you want to fund please \ + provide `--fund` flag. If you don't need to fund your keys in the future, ignore this \ + warning. It can be suppressed with -q flag.", + ) + } let seed_phrase = if self.default_seed { Secret::test_seed_phrase() } else { diff --git a/cmd/soroban-cli/src/commands/keys/mod.rs b/cmd/soroban-cli/src/commands/keys/mod.rs index 42814092f..30df5ccee 100644 --- a/cmd/soroban-cli/src/commands/keys/mod.rs +++ b/cmd/soroban-cli/src/commands/keys/mod.rs @@ -1,3 +1,4 @@ +use crate::commands::global; use clap::Parser; pub mod add; @@ -48,12 +49,12 @@ pub enum Error { } impl Cmd { - pub async fn run(&self) -> Result<(), Error> { + pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> { match self { Cmd::Add(cmd) => cmd.run()?, Cmd::Address(cmd) => cmd.run()?, Cmd::Fund(cmd) => cmd.run().await?, - Cmd::Generate(cmd) => cmd.run().await?, + Cmd::Generate(cmd) => cmd.run(global_args).await?, Cmd::Ls(cmd) => cmd.run()?, Cmd::Rm(cmd) => cmd.run()?, Cmd::Show(cmd) => cmd.run()?, diff --git a/cmd/soroban-cli/src/commands/mod.rs b/cmd/soroban-cli/src/commands/mod.rs index b2e431e6e..0a1d4629b 100644 --- a/cmd/soroban-cli/src/commands/mod.rs +++ b/cmd/soroban-cli/src/commands/mod.rs @@ -113,7 +113,7 @@ impl Root { Cmd::Network(network) => network.run(&self.global_args).await?, Cmd::Snapshot(snapshot) => snapshot.run(&self.global_args).await?, Cmd::Version(version) => version.run(), - Cmd::Keys(id) => id.run().await?, + Cmd::Keys(id) => id.run(&self.global_args).await?, Cmd::Tx(tx) => tx.run(&self.global_args).await?, Cmd::Cache(data) => data.run()?, };