Skip to content

Commit

Permalink
Merge branch 'origin/ray/utils-base-dir' (#1491)
Browse files Browse the repository at this point in the history
* origin/ray/utils-base-dir:
  changelog: add #1491
  apps: add namadac utils default-base-dir
  • Loading branch information
Fraccaman committed Jun 9, 2023
2 parents 692a3fa + b49e5f8 commit 36d0fb4
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .changelog/unreleased/improvements/1491-utils-base-dir.md
Original file line number Diff line number Diff line change
@@ -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))
3 changes: 3 additions & 0 deletions apps/src/bin/namada-client/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,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(())
Expand Down
41 changes: 41 additions & 0 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,7 @@ pub mod cmds {
InitNetwork(InitNetwork),
InitGenesisValidator(InitGenesisValidator),
PkToTmAddress(PkToTmAddress),
DefaultBaseDir(DefaultBaseDir),
}

impl SubCmd for Utils {
Expand All @@ -1605,11 +1606,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)
})
}

Expand All @@ -1621,6 +1625,7 @@ pub mod cmds {
.subcommand(InitNetwork::def())
.subcommand(InitGenesisValidator::def())
.subcommand(PkToTmAddress::def())
.subcommand(DefaultBaseDir::def())
.setting(AppSettings::SubcommandRequiredElseHelp)
}
}
Expand Down Expand Up @@ -1726,6 +1731,29 @@ pub mod cmds {
.add_args::<args::PkToTmAddress>()
}
}

#[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<Self> {
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::<args::DefaultBaseDir>()
}
}
}

pub mod args {
Expand Down Expand Up @@ -3843,6 +3871,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,
Expand Down
14 changes: 13 additions & 1 deletion apps/src/lib/client/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -911,6 +911,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(
Expand Down

0 comments on commit 36d0fb4

Please sign in to comment.