Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apps: add namadac utils default-base-dir #1491

Merged
merged 2 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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(())
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 @@ -1506,6 +1506,7 @@ pub mod cmds {
InitNetwork(InitNetwork),
InitGenesisValidator(InitGenesisValidator),
PkToTmAddress(PkToTmAddress),
DefaultBaseDir(DefaultBaseDir),
}

impl SubCmd for Utils {
Expand All @@ -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)
})
}

Expand All @@ -1538,6 +1542,7 @@ pub mod cmds {
.subcommand(InitNetwork::def())
.subcommand(InitGenesisValidator::def())
.subcommand(PkToTmAddress::def())
.subcommand(DefaultBaseDir::def())
.setting(AppSettings::SubcommandRequiredElseHelp)
}
}
Expand Down Expand Up @@ -1643,6 +1648,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 @@ -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,
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 @@ -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"
Copy link

@gijswijs gijswijs Jun 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<pedantic>Error message is a bit cryptic</pedantic>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah +1 I'd like to see something else

)
);
}

/// 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