Skip to content

Commit

Permalink
chore: restructure modules
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Oct 16, 2024
1 parent 0939446 commit a5abe31
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 81 deletions.
66 changes: 0 additions & 66 deletions bin/src/cli.rs

This file was deleted.

29 changes: 29 additions & 0 deletions bin/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#[cfg(feature = "rpc")]
mod rpc;
mod utils;

use clap::Parser;
use color_eyre::Result;
use rika_args::commands::utility;

#[derive(Parser, Debug)]
#[command(name = "rika", version, about, long_about = None)]
pub enum Cli {
#[command(flatten)]
Utilities(utility::UtilityCommands),

#[cfg(feature = "rpc")]
#[command(flatten)]
Rpc(rpc::RpcCommands),
}

impl Cli {
pub fn execute(self) -> Result<()> {
match self {
Cli::Utilities(cmd) => utils::execute(cmd)?,
#[cfg(feature = "rpc")]
Cli::Rpc(rpc) => rpc::execute(rpc)?,
}
Ok(())
}
}
25 changes: 25 additions & 0 deletions bin/src/cli/rpc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use color_eyre::Result;
pub use rika_args::commands::rpc::RpcCommands;
use rika_ops as ops;

pub fn execute(command: RpcCommands) -> Result<()> {
match command {
// RpcCommands::Call(args) => ops::rpc::call::call(args)?,
// RpcCommands::Balance(args) => ops::rpc::balance::get(args)?,
// RpcCommands::Tx(args) => ops::rpc::transaction::get(args)?,
// RpcCommands::TxCount(args) => ops::rpc::transaction::count(args)?,
// RpcCommands::TxStatus(args) => ops::rpc::transaction::status(args)?,
RpcCommands::Receipt(args) => ops::rpc::transaction::receipt(args)?,
// RpcCommands::Rpc(args) => ops::rpc::raw::send(args)?,
// RpcCommands::Block(args) => ops::rpc::block::get(args)?,
// RpcCommands::Age(args) => ops::rpc::block::age(args)?,
// RpcCommands::BlockNumber(args) => ops::rpc::block::number(args)?,
// RpcCommands::ChainId(args) => ops::rpc::chain::id(args)?,
// RpcCommands::Syncing(args) => ops::rpc::chain::syncing(args)?,
_ => {
unimplemented!("This command is not implemented yet")
}
}

Ok(())
}
12 changes: 12 additions & 0 deletions bin/src/cli/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use color_eyre::Result;
pub use rika_args::commands::utility::UtilityCommands;
use rika_ops as ops;

pub fn execute(command: UtilityCommands) -> Result<()> {
match command {
UtilityCommands::Index(args) => ops::utility::storage_address(args)?,
_ => unimplemented!("This command is not implemented yet"),
}

Ok(())
}
17 changes: 3 additions & 14 deletions bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,19 @@

mod cli;

use self::cli::App;
use clap::Parser;
use cli::Cli;
use color_eyre::Result;

fn main() -> Result<()> {
color_eyre::install()?;
let args = App::parse();
let cli = Cli::parse();

match execute(args) {
match cli.execute() {
Ok(()) => Ok(()),
Err(e) => {
eprintln!("{e}");
std::process::exit(1);
}
}
}

fn execute(commands: App) -> Result<()> {
match commands {
App::Utilities(cmd) => cli::utilities::execute(cmd)?,

#[cfg(feature = "rpc")]
App::Rpc(rpc) => cli::rpc::execute(rpc)?,
}

Ok(())
}
2 changes: 1 addition & 1 deletion crates/fmt/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use std::vec;
use alloy_primitives::U256;
use prettytable::format::Alignment;
use prettytable::{Cell, Row, Table};
use starknet::core::types::PendingTransactionReceipt;
use starknet::core::types::{
Event, ExecutionResources, ExecutionResult, FeePayment, MaybePendingTransactionReceipt,
MsgToL1, PriceUnit, TransactionFinalityStatus, TransactionReceipt,
};
use starknet::core::types::{FieldElement, PendingTransactionReceipt};

use crate::{utils, Pretty, Tabular};

Expand Down

0 comments on commit a5abe31

Please sign in to comment.