Skip to content

Commit

Permalink
Remove ClientCommand trait.
Browse files Browse the repository at this point in the history
  • Loading branch information
koxu1996 committed Feb 6, 2024
1 parent 0dafb64 commit c63d8d3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 36 deletions.
11 changes: 5 additions & 6 deletions kairos-cli/bin/commands/deposit.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
use crate::commands::{ClientCommand, Output};
use crate::common::{amount, private_key};
use crate::crypto::signer::CasperSigner;
use crate::error::CliError;
use clap::{ArgMatches, Command};

pub struct Deposit;

impl ClientCommand for Deposit {
const NAME: &'static str = "deposit";
const ABOUT: &'static str = "Deposits funds into your account";
impl Deposit {
pub const NAME: &'static str = "deposit";
pub const ABOUT: &'static str = "Deposits funds into your account";

fn new_cmd() -> Command {
pub fn new_cmd() -> Command {
Command::new(Self::NAME)
.about(Self::ABOUT)
.arg(amount::arg())
.arg(private_key::arg())
}

fn run(matches: &ArgMatches) -> Result<Output, CliError> {
pub fn run(matches: &ArgMatches) -> Result<String, CliError> {
let _amount = amount::get(matches)?;
let private_key = private_key::get(matches)?;

Expand Down
17 changes: 0 additions & 17 deletions kairos-cli/bin/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,3 @@ mod withdraw;
pub use deposit::Deposit;
pub use transfer::Transfer;
pub use withdraw::Withdraw;

use crate::error::CliError;
use clap::{ArgMatches, Command};

// NOTE: Temporarily we use plain output.
pub type Output = String;

pub trait ClientCommand {
const NAME: &'static str;
const ABOUT: &'static str;

/// Constructs the clap subcommand.
fn new_cmd() -> Command;

/// Parses the arg matches and runs the subcommand.
fn run(matches: &ArgMatches) -> Result<Output, CliError>;
}
11 changes: 5 additions & 6 deletions kairos-cli/bin/commands/transfer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::commands::{ClientCommand, Output};
use crate::common::{amount, private_key};
use crate::crypto::public_key::CasperPublicKey;
use crate::crypto::signer::CasperSigner;
Expand Down Expand Up @@ -32,19 +31,19 @@ pub mod recipient {
}
}

impl ClientCommand for Transfer {
const NAME: &'static str = "transfer";
const ABOUT: &'static str = "Transfers funds to another account";
impl Transfer {
pub const NAME: &'static str = "transfer";
pub const ABOUT: &'static str = "Transfers funds to another account";

fn new_cmd() -> Command {
pub fn new_cmd() -> Command {
Command::new(Self::NAME)
.about(Self::ABOUT)
.arg(recipient::arg())
.arg(amount::arg())
.arg(private_key::arg())
}

fn run(matches: &ArgMatches) -> Result<Output, CliError> {
pub fn run(matches: &ArgMatches) -> Result<String, CliError> {
let _recipient = recipient::get(matches)?;
let _amount = amount::get(matches)?;
let private_key = private_key::get(matches)?;
Expand Down
11 changes: 5 additions & 6 deletions kairos-cli/bin/commands/withdraw.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
use crate::commands::{ClientCommand, Output};
use crate::common::{amount, private_key};
use crate::crypto::signer::CasperSigner;
use crate::error::CliError;
use clap::{ArgMatches, Command};

pub struct Withdraw;

impl ClientCommand for Withdraw {
const NAME: &'static str = "withdraw";
const ABOUT: &'static str = "Withdraws funds from your account";
impl Withdraw {
pub const NAME: &'static str = "withdraw";
pub const ABOUT: &'static str = "Withdraws funds from your account";

fn new_cmd() -> Command {
pub fn new_cmd() -> Command {
Command::new(Self::NAME)
.about(Self::ABOUT)
.arg(amount::arg())
.arg(private_key::arg())
}

fn run(matches: &ArgMatches) -> Result<Output, CliError> {
pub fn run(matches: &ArgMatches) -> Result<String, CliError> {
let _amount = amount::get(matches)?;
let private_key = private_key::get(matches)?;

Expand Down
2 changes: 1 addition & 1 deletion kairos-cli/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod crypto;
mod error;

use clap::Command;
use commands::{ClientCommand, Deposit, Transfer, Withdraw};
use commands::{Deposit, Transfer, Withdraw};
use std::process;

fn cli() -> Command {
Expand Down

0 comments on commit c63d8d3

Please sign in to comment.