Skip to content

Commit

Permalink
rename Command -> SubCommand, Args -> Command
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperFluffy committed Sep 30, 2024
1 parent 54c899a commit 5dfa949
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 96 deletions.
32 changes: 16 additions & 16 deletions crates/astria-cli/src/sequencer/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,35 @@ use color_eyre::eyre::{
use rand::rngs::OsRng;

#[derive(Debug, clap::Args)]
pub(super) struct Args {
pub(super) struct Command {
#[command(subcommand)]
command: Command,
command: SubCommand,
}

impl Args {
impl Command {
pub(super) async fn run(self) -> eyre::Result<()> {
match self.command {
Command::Create(create) => create.run(),
Command::Balance(balance) => balance.run().await,
Command::Nonce(nonce) => nonce.run().await,
SubCommand::Create(create) => create.run(),
SubCommand::Balance(balance) => balance.run().await,
SubCommand::Nonce(nonce) => nonce.run().await,
}
}
}

#[derive(Debug, Subcommand)]
enum Command {
enum SubCommand {
/// Generates a new ED25519 keypair.
Create(CreateArgs),
Create(Create),
/// Queries the Sequencer for the balances of an account.
Balance(BalanceArgs),
Balance(Balance),
/// Queries the Sequencer for the current nonce of an account.
Nonce(NonceArgs),
Nonce(Nonce),
}

#[derive(Debug, clap::Args)]
struct CreateArgs;
struct Create;

impl CreateArgs {
impl Create {
#[expect(
clippy::unused_self,
clippy::unnecessary_wraps,
Expand All @@ -65,12 +65,12 @@ impl CreateArgs {
}

#[derive(Debug, clap::Args)]
struct BalanceArgs {
struct Balance {
#[command(flatten)]
inner: ArgsInner,
}

impl BalanceArgs {
impl Balance {
async fn run(self) -> eyre::Result<()> {
let args = self.inner;
let sequencer_client = HttpClient::new(args.sequencer_url.as_str())
Expand All @@ -91,12 +91,12 @@ impl BalanceArgs {
}

#[derive(Debug, clap::Args)]
struct NonceArgs {
struct Nonce {
#[command(flatten)]
inner: ArgsInner,
}

impl NonceArgs {
impl Nonce {
async fn run(self) -> eyre::Result<()> {
let args = self.inner;
let sequencer_client = HttpClient::new(args.sequencer_url.as_str())
Expand Down
19 changes: 9 additions & 10 deletions crates/astria-cli/src/sequencer/address.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use astria_core::primitive::v1::{
Address,
Bech32m,
ADDRESS_LEN,
};
use color_eyre::eyre::{
Expand All @@ -9,26 +8,26 @@ use color_eyre::eyre::{
};

#[derive(Debug, clap::Args)]
pub(super) struct Args {
pub(super) struct Command {
#[command(subcommand)]
command: Command,
command: SubCommand,
}

impl Args {
impl Command {
pub(super) fn run(self) -> eyre::Result<()> {
let Command::Bech32m(bech32m) = self.command;
let SubCommand::Bech32m(bech32m) = self.command;
bech32m.run()
}
}

#[derive(Debug, clap::Subcommand)]
enum Command {
enum SubCommand {
/// Returns a bech32m sequencer address given a prefix and hex-encoded byte slice
Bech32m(Bech32mArgs),
Bech32m(Bech32m),
}

#[derive(Debug, clap::Args)]
struct Bech32mArgs {
struct Bech32m {
/// The hex formatted byte part of the bech32m address
#[arg(long)]
bytes: String,
Expand All @@ -37,12 +36,12 @@ struct Bech32mArgs {
prefix: String,
}

impl Bech32mArgs {
impl Bech32m {
fn run(self) -> eyre::Result<()> {
use hex::FromHex as _;
let bytes = <[u8; ADDRESS_LEN]>::from_hex(&self.bytes)
.wrap_err("failed decoding provided hex bytes")?;
let address = Address::<Bech32m>::builder()
let address = Address::<astria_core::primitive::v1::Bech32m>::builder()
.array(bytes)
.prefix(&self.prefix)
.try_build()
Expand Down
16 changes: 8 additions & 8 deletions crates/astria-cli/src/sequencer/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ use color_eyre::eyre::{
};

#[derive(Debug, clap::Args)]
pub(super) struct Args {
pub(super) struct Command {
#[command(subcommand)]
command: Command,
command: SubCommand,
}

impl Args {
impl Command {
pub(super) async fn run(self) -> eyre::Result<()> {
let Command::Get(get) = self.command;
let SubCommand::Get(get) = self.command;
get.run().await
}
}

#[derive(Debug, Subcommand)]
enum Command {
enum SubCommand {
/// Get the balance of a Sequencer account
Get(GetArgs),
Get(Get),
}

#[derive(clap::Args, Debug)]
struct GetArgs {
struct Get {
/// The url of the Sequencer node
#[arg(
long,
Expand All @@ -41,7 +41,7 @@ struct GetArgs {
address: Address,
}

impl GetArgs {
impl Get {
async fn run(self) -> eyre::Result<()> {
let sequencer_client = HttpClient::new(self.sequencer_url.as_str())
.wrap_err("failed constructing http sequencer client")?;
Expand Down
16 changes: 8 additions & 8 deletions crates/astria-cli/src/sequencer/block_height.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ use color_eyre::eyre::{
};

#[derive(Debug, clap::Args)]
pub(super) struct Args {
pub(super) struct Command {
#[command(subcommand)]
command: Command,
command: SubCommand,
}

impl Args {
impl Command {
pub(super) async fn run(self) -> eyre::Result<()> {
let Command::Get(get) = self.command;
let SubCommand::Get(get) = self.command;
get.run().await
}
}

#[derive(Debug, Subcommand)]
enum Command {
enum SubCommand {
/// Get the current block height of the Sequencer node
Get(GetArgs),
Get(Get),
}

#[derive(clap::Args, Debug)]
struct GetArgs {
struct Get {
/// The url of the Sequencer node
#[arg(
long,
Expand All @@ -45,7 +45,7 @@ struct GetArgs {
sequencer_chain_id: String,
}

impl GetArgs {
impl Get {
async fn run(self) -> eyre::Result<()> {
let sequencer_client = HttpClient::new(self.sequencer_url.as_str())
.wrap_err("failed constructing http sequencer client")?;
Expand Down
4 changes: 2 additions & 2 deletions crates/astria-cli/src/sequencer/bridge_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use color_eyre::eyre::{
use crate::utils::submit_transaction;

#[derive(clap::Args, Debug)]
pub(super) struct Args {
pub(super) struct Command {
/// The address of the Sequencer account to lock amount to
to_address: Address,
/// The amount being locked
Expand Down Expand Up @@ -55,7 +55,7 @@ pub(super) struct Args {
fee_asset: asset::Denom,
}

impl Args {
impl Command {
pub(super) async fn run(self) -> eyre::Result<()> {
let res = submit_transaction(
self.sequencer_url.as_str(),
Expand Down
4 changes: 2 additions & 2 deletions crates/astria-cli/src/sequencer/init_bridge_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use color_eyre::eyre::{
};

#[derive(clap::Args, Debug)]
pub(super) struct Args {
pub(super) struct Command {
/// The bech32m prefix that will be used for constructing addresses using the private key
#[arg(long, default_value = "astria")]
prefix: String,
Expand Down Expand Up @@ -47,7 +47,7 @@ pub(super) struct Args {
fee_asset: asset::Denom,
}

impl Args {
impl Command {
pub(super) async fn run(self) -> eyre::Result<()> {
use astria_core::primitive::v1::RollupId;

Expand Down
16 changes: 8 additions & 8 deletions crates/astria-cli/src/sequencer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ impl Args {
#[derive(Debug, Subcommand)]
enum Command {
/// Commands for interacting with Sequencer accounts
Account(account::Args),
Account(account::Command),
/// Utilities for constructing and inspecting sequencer addresses
Address(address::Args),
Address(address::Command),
/// Commands for interacting with Sequencer balances
Balance(balance::Args),
Balance(balance::Command),
/// Commands for interacting with Sequencer block heights
#[command(name = "blockheight")]
BlockHeight(block_height::Args),
BlockHeight(block_height::Command),
/// Command for transferring to a bridge account
BridgeLock(bridge_lock::Args),
BridgeLock(bridge_lock::Command),
/// Command for initializing a bridge account
InitBridgeAccount(init_bridge_account::Args),
InitBridgeAccount(init_bridge_account::Command),
/// Commands requiring authority for Sequencer
Sudo(sudo::Args),
Sudo(sudo::Command),
/// Command for sending balance between accounts
Transfer(transfer::Args),
Transfer(transfer::Command),
}
24 changes: 12 additions & 12 deletions crates/astria-cli/src/sequencer/sudo/fee_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,35 @@ use color_eyre::eyre::{
use crate::utils::submit_transaction;

#[derive(Debug, clap::Args)]
pub(super) struct Args {
pub(super) struct Command {
#[command(subcommand)]
command: Command,
command: SubCommand,
}

impl Args {
impl Command {
pub(super) async fn run(self) -> eyre::Result<()> {
match self.command {
Command::Add(add) => add.run().await,
Command::Remove(remove) => remove.run().await,
SubCommand::Add(add) => add.run().await,
SubCommand::Remove(remove) => remove.run().await,
}
}
}

#[derive(Debug, Subcommand)]
enum Command {
enum SubCommand {
/// Add Fee Asset
Add(AddArgs),
Add(Add),
/// Remove Fee Asset
Remove(RemoveArgs),
Remove(Remove),
}

#[derive(Clone, Debug, clap::Args)]
struct AddArgs {
struct Add {
#[command(flatten)]
inner: ArgsInner,
}

impl AddArgs {
impl Add {
async fn run(self) -> eyre::Result<()> {
let args = self.inner;
let res = submit_transaction(
Expand All @@ -62,12 +62,12 @@ impl AddArgs {
}

#[derive(Clone, Debug, clap::Args)]
struct RemoveArgs {
struct Remove {
#[command(flatten)]
inner: ArgsInner,
}

impl RemoveArgs {
impl Remove {
async fn run(self) -> eyre::Result<()> {
let args = self.inner;
let res = submit_transaction(
Expand Down
Loading

0 comments on commit 5dfa949

Please sign in to comment.