Skip to content

Commit

Permalink
cli structure
Browse files Browse the repository at this point in the history
  • Loading branch information
hardyjosh committed Jan 8, 2024
1 parent 5d45b34 commit c9ec4e8
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 48 deletions.
33 changes: 33 additions & 0 deletions crates/cli/src/commands/deposit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use clap::Parser;
use anyhow::Result;
use clap::Args;

#[derive(Parser)]
pub struct Deposit {
#[clap(flatten)]
deposit_args: DepositArgs
}

impl Deposit {
pub async fn execute(self) -> Result<()> {
let DepositArgs {
token,
amount,
vault_id,
} = &self.deposit_args;
println!("Token: {}, Amount: {}, Vault ID: {}", token, amount, vault_id);
Ok(())
}
}

#[derive(Args)]
pub struct DepositArgs {
#[arg(short, long, help = "The token address in hex format")]
token: String,

#[arg(short, long, help = "The amount to deposit")]
amount: u64,

#[arg(short, long, help = "The ID of the vault")]
vault_id: u64,
}
4 changes: 4 additions & 0 deletions crates/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mod order;
mod deposit;

pub use self::{order::*, deposit::*};
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use clap::Subcommand;
use clap::Parser;
use anyhow::Result;

#[derive(Subcommand)]
#[command(about = "Interact with an order(s) onchain and offchain.")]
#[derive(Parser)]
pub enum Order {
#[command(about = "List all orders from the subgraph.")]
Ls,
}

pub async fn dispatch(order: Order) -> Result<()> {
match order {
impl Order {
pub async fn execute(self) -> Result<()> {
match self {
Order::Ls => ls().await,
}
}
}

Expand Down
22 changes: 22 additions & 0 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use anyhow::Result;
use clap::Subcommand;

use crate::commands::{Order, Deposit};

mod commands;

#[derive(Subcommand)]
pub enum Orderbook {
#[command(subcommand)]
Order(Order),
Deposit(Deposit),
}

impl Orderbook {
pub async fn execute(self) -> Result<()> {
match self {
Orderbook::Order(order) => order.execute().await,
Orderbook::Deposit(deposit) => deposit.execute().await,
}
}
}
7 changes: 3 additions & 4 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use clap::Parser;
use anyhow::Result;

mod orderbook;
use rain_orderbook_cli::Orderbook;

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
#[command(subcommand)]
orderbook: orderbook::Orderbook,
orderbook: Orderbook,
}
#[tokio::main]
async fn main() -> Result<()> {
tracing::subscriber::set_global_default(tracing_subscriber::fmt::Subscriber::new())?;

let cli = Cli::parse();
orderbook::dispatch(cli.orderbook).await
cli.orderbook.execute().await
}
19 changes: 0 additions & 19 deletions crates/cli/src/orderbook/deposit.rs

This file was deleted.

20 changes: 0 additions & 20 deletions crates/cli/src/orderbook/mod.rs

This file was deleted.

0 comments on commit c9ec4e8

Please sign in to comment.