Skip to content

Commit

Permalink
cli/client: fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Aug 15, 2024
1 parent d5863fa commit b810840
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 75 deletions.
9 changes: 6 additions & 3 deletions crates/apps_lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8335,9 +8335,9 @@ pub fn namada_node_cli() -> Result<NamadaNode> {
}
}

#[allow(clippy::large_enum_variant)]
/// Namada client commands with loaded [`Context`] where required
pub enum NamadaClient {
WithoutContext(cmds::ClientUtils, args::Global),
WithoutContext(Box<(cmds::ClientUtils, args::Global)>),
WithContext(Box<(cmds::NamadaClientWithContext, Context)>),
}

Expand All @@ -8353,7 +8353,10 @@ pub fn namada_client_cli() -> Result<NamadaClient> {
Ok(NamadaClient::WithContext(Box::new((sub_cmd, context))))
}
cmds::NamadaClient::WithoutContext(sub_cmd) => {
Ok(NamadaClient::WithoutContext(sub_cmd, global_args))
Ok(NamadaClient::WithoutContext(Box::new((
sub_cmd,
global_args,
))))
}
}
}
Expand Down
151 changes: 80 additions & 71 deletions crates/apps_lib/src/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,80 +774,89 @@ impl CliApi {
}
}
}
cli::NamadaClient::WithoutContext(cmd, global_args) => match cmd {
// Utils cmds
ClientUtils::JoinNetwork(JoinNetwork(args)) => {
utils::join_network(global_args, args).await
}
ClientUtils::ValidateWasm(ValidateWasm(args)) => {
utils::validate_wasm(args)
}
ClientUtils::InitNetwork(InitNetwork(args)) => {
utils::init_network(global_args, args);
}
ClientUtils::GenesisBond(GenesisBond(args)) => {
utils::genesis_bond(global_args, args)
}
ClientUtils::DeriveGenesisAddresses(
DeriveGenesisAddresses(args),
) => utils::derive_genesis_addresses(global_args, args),
ClientUtils::InitGenesisEstablishedAccount(
InitGenesisEstablishedAccount(args),
) => utils::init_genesis_established_account(global_args, args),
ClientUtils::InitGenesisValidator(InitGenesisValidator(
args,
)) => utils::init_genesis_validator(global_args, args),
ClientUtils::PkToTmAddress(PkToTmAddress(args)) => {
utils::pk_to_tm_address(global_args, args)
}
ClientUtils::DefaultBaseDir(DefaultBaseDir(args)) => {
utils::default_base_dir(global_args, args)
}
ClientUtils::EpochSleep(EpochSleep(args)) => {
let mut ctx = cli::Context::new::<IO>(global_args)
.expect("expected to construct a context");
let chain_ctx = ctx.borrow_mut_chain_or_exit();
let ledger_address = chain_ctx.get(&args.ledger_address);
let client = C::from_tendermint_address(&ledger_address);
client.wait_until_node_is_synced(&io).await?;
let args = args.to_sdk(&mut ctx)?;
let namada = ctx.to_sdk(client, io);
rpc::epoch_sleep(&namada, args).await;
}
ClientUtils::ValidateGenesisTemplates(
ValidateGenesisTemplates(args),
) => utils::validate_genesis_templates(global_args, args),
ClientUtils::SignGenesisTxs(SignGenesisTxs(args)) => {
utils::sign_genesis_tx(global_args, args).await
}
ClientUtils::ParseMigrationJson(MigrationJson(args)) => {
#[cfg(feature = "migrations")]
{
let mut update_json = String::new();
let mut file = std::fs::File::open(args.path).expect(
"Could not fine updates file at the specified \
path.",
);
file.read_to_string(&mut update_json)
.expect("Unable to read the updates json file");
let updates: namada_sdk::migrations::DbChanges =
serde_json::from_str(&update_json).expect(
"Could not parse the updates file as json",
);
for change in updates.changes {
display_line!(io, "{}", change);
}
cli::NamadaClient::WithoutContext(cmd_box) => {
let (cmd, global_args) = *cmd_box;
match cmd {
// Utils cmds
ClientUtils::JoinNetwork(JoinNetwork(args)) => {
utils::join_network(global_args, args).await
}
ClientUtils::ValidateWasm(ValidateWasm(args)) => {
utils::validate_wasm(args)
}
ClientUtils::InitNetwork(InitNetwork(args)) => {
utils::init_network(global_args, args);
}
ClientUtils::GenesisBond(GenesisBond(args)) => {
utils::genesis_bond(global_args, args)
}
ClientUtils::DeriveGenesisAddresses(
DeriveGenesisAddresses(args),
) => utils::derive_genesis_addresses(global_args, args),
ClientUtils::InitGenesisEstablishedAccount(
InitGenesisEstablishedAccount(args),
) => utils::init_genesis_established_account(
global_args,
args,
),
ClientUtils::InitGenesisValidator(
InitGenesisValidator(args),
) => utils::init_genesis_validator(global_args, args),
ClientUtils::PkToTmAddress(PkToTmAddress(args)) => {
utils::pk_to_tm_address(global_args, args)
}
#[cfg(not(feature = "migrations"))]
{
display_line!(
io,
"Can only use this function if compiled with \
feature \"migrations\" enabled."
)
ClientUtils::DefaultBaseDir(DefaultBaseDir(args)) => {
utils::default_base_dir(global_args, args)
}
ClientUtils::EpochSleep(EpochSleep(args)) => {
let mut ctx = cli::Context::new::<IO>(global_args)
.expect("expected to construct a context");
let chain_ctx = ctx.borrow_mut_chain_or_exit();
let ledger_address =
chain_ctx.get(&args.ledger_address);
let client =
C::from_tendermint_address(&ledger_address);
client.wait_until_node_is_synced(&io).await?;
let args = args.to_sdk(&mut ctx)?;
let namada = ctx.to_sdk(client, io);
rpc::epoch_sleep(&namada, args).await;
}
ClientUtils::ValidateGenesisTemplates(
ValidateGenesisTemplates(args),
) => utils::validate_genesis_templates(global_args, args),
ClientUtils::SignGenesisTxs(SignGenesisTxs(args)) => {
utils::sign_genesis_tx(global_args, args).await
}
ClientUtils::ParseMigrationJson(MigrationJson(args)) => {
#[cfg(feature = "migrations")]
{
let mut update_json = String::new();
let mut file = std::fs::File::open(args.path)
.expect(
"Could not fine updates file at the \
specified path.",
);
file.read_to_string(&mut update_json)
.expect("Unable to read the updates json file");
let updates: namada_sdk::migrations::DbChanges =
serde_json::from_str(&update_json).expect(
"Could not parse the updates file as json",
);
for change in updates.changes {
display_line!(io, "{}", change);
}
}
#[cfg(not(feature = "migrations"))]
{
display_line!(
io,
"Can only use this function if compiled with \
feature \"migrations\" enabled."
)
}
}
}
},
}
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/node/src/shell/testing/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn run(
NamadaClient::WithContext(Box::new((sub_cmd, ctx)))
}
cmds::NamadaClient::WithoutContext(sub_cmd) => {
NamadaClient::WithoutContext(sub_cmd, global)
NamadaClient::WithoutContext(Box::new((sub_cmd, global)))
}
};
rt.block_on(CliApi::handle_client_command(
Expand Down

0 comments on commit b810840

Please sign in to comment.