From cd966c4cd26c45b061868cf85441cb1481b7472c Mon Sep 17 00:00:00 2001 From: "Raymond E. Pasco" Date: Thu, 1 Jun 2023 12:06:18 -0400 Subject: [PATCH 1/2] apps: add namadac utils default-base-dir Add a utility command to print the default base directory that would be used by the Namada command line if a base directory were not provided on the command line or in the environment. --- apps/src/bin/namada-client/cli.rs | 3 +++ apps/src/lib/cli.rs | 41 +++++++++++++++++++++++++++++++ apps/src/lib/client/utils.rs | 14 ++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/apps/src/bin/namada-client/cli.rs b/apps/src/bin/namada-client/cli.rs index 10316cb6bf0..d752dd01f19 100644 --- a/apps/src/bin/namada-client/cli.rs +++ b/apps/src/bin/namada-client/cli.rs @@ -319,6 +319,9 @@ pub async fn main() -> Result<()> { Utils::PkToTmAddress(PkToTmAddress(args)) => { utils::pk_to_tm_address(global_args, args) } + Utils::DefaultBaseDir(DefaultBaseDir(args)) => { + utils::default_base_dir(global_args, args) + } }, } Ok(()) diff --git a/apps/src/lib/cli.rs b/apps/src/lib/cli.rs index daecbf5eee1..2d13fdbf664 100644 --- a/apps/src/lib/cli.rs +++ b/apps/src/lib/cli.rs @@ -1506,6 +1506,7 @@ pub mod cmds { InitNetwork(InitNetwork), InitGenesisValidator(InitGenesisValidator), PkToTmAddress(PkToTmAddress), + DefaultBaseDir(DefaultBaseDir), } impl SubCmd for Utils { @@ -1522,11 +1523,14 @@ pub mod cmds { SubCmd::parse(matches).map(Self::InitGenesisValidator); let pk_to_tm_address = SubCmd::parse(matches).map(Self::PkToTmAddress); + let default_base_dir = + SubCmd::parse(matches).map(Self::DefaultBaseDir); join_network .or(fetch_wasms) .or(init_network) .or(init_genesis) .or(pk_to_tm_address) + .or(default_base_dir) }) } @@ -1538,6 +1542,7 @@ pub mod cmds { .subcommand(InitNetwork::def()) .subcommand(InitGenesisValidator::def()) .subcommand(PkToTmAddress::def()) + .subcommand(DefaultBaseDir::def()) .setting(AppSettings::SubcommandRequiredElseHelp) } } @@ -1643,6 +1648,29 @@ pub mod cmds { .add_args::() } } + + #[derive(Clone, Debug)] + pub struct DefaultBaseDir(pub args::DefaultBaseDir); + + impl SubCmd for DefaultBaseDir { + const CMD: &'static str = "default-base-dir"; + + fn parse(matches: &ArgMatches) -> Option { + matches + .subcommand_matches(Self::CMD) + .map(|matches| Self(args::DefaultBaseDir::parse(matches))) + } + + fn def() -> App { + App::new(Self::CMD) + .about( + "Print the default base directory that would be used if \ + --base-dir or NAMADA_BASE_DIR were not used to set the \ + base directory.", + ) + .add_args::() + } + } } pub mod args { @@ -3646,6 +3674,19 @@ pub mod args { } } + #[derive(Clone, Debug)] + pub struct DefaultBaseDir {} + + impl Args for DefaultBaseDir { + fn parse(_matches: &ArgMatches) -> Self { + Self {} + } + + fn def(app: App) -> App { + app + } + } + #[derive(Clone, Debug)] pub struct FetchWasms { pub chain_id: ChainId, diff --git a/apps/src/lib/client/utils.rs b/apps/src/lib/client/utils.rs index 107c5465ddf..f74ec7bcbc7 100644 --- a/apps/src/lib/client/utils.rs +++ b/apps/src/lib/client/utils.rs @@ -27,7 +27,7 @@ use crate::config::genesis::genesis_config::{ self, GenesisConfig, HexString, ValidatorPreGenesisConfig, }; use crate::config::global::GlobalConfig; -use crate::config::{self, Config, TendermintMode}; +use crate::config::{self, get_default_namada_folder, Config, TendermintMode}; use crate::facade::tendermint::node::Id as TendermintNodeId; use crate::facade::tendermint_config::net::Address as TendermintAddress; use crate::node::ledger::tendermint_node; @@ -901,6 +901,18 @@ pub fn pk_to_tm_address( println!("{tm_addr}"); } +pub fn default_base_dir( + _global_args: args::Global, + _args: args::DefaultBaseDir, +) { + println!( + "{}", + get_default_namada_folder().to_str().expect( + "expected a default namada folder to be possible to determine" + ) + ); +} + /// Initialize genesis validator's address, consensus key and validator account /// key and use it in the ledger's node. pub fn init_genesis_validator( From b49e5f8fcf3a278794942525afa5f297cd303f16 Mon Sep 17 00:00:00 2001 From: "Raymond E. Pasco" Date: Thu, 1 Jun 2023 12:08:28 -0400 Subject: [PATCH 2/2] changelog: add #1491 --- .changelog/unreleased/improvements/1491-utils-base-dir.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .changelog/unreleased/improvements/1491-utils-base-dir.md diff --git a/.changelog/unreleased/improvements/1491-utils-base-dir.md b/.changelog/unreleased/improvements/1491-utils-base-dir.md new file mode 100644 index 00000000000..6ec06cb49a8 --- /dev/null +++ b/.changelog/unreleased/improvements/1491-utils-base-dir.md @@ -0,0 +1,4 @@ +- Add a command, `namadac utils default-base-dir`, to + print the default base directory the command + line would use were one not provided by the user. + ([#1491](https://github.com/anoma/namada/pull/1491))