keyfork-seed: use clap::Parser

This commit is contained in:
Ryan Heywood 2023-09-12 00:58:08 -05:00
parent b7fd2ef8e5
commit 8ac682531b
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
3 changed files with 21 additions and 26 deletions

View File

@ -7,7 +7,7 @@ edition = "2021"
[dependencies]
bincode = { version = "1.3.3", default-features = false }
clap = { version = "4.4.2", default-features = false, features = ["std", "usage", "help"] }
clap = { version = "4.4.2", default-features = false, features = ["std", "usage", "help", "derive"] }
keyfork-derive-util = { version = "0.1.0", path = "../keyfork-derive-util" }
keyfork-frame = { version = "0.1.0", path = "../keyfork-frame", default-features = false }
thiserror = "1.0.48"

View File

@ -1,19 +1,20 @@
use clap::{arg, value_parser, ArgMatches, Command};
use clap::Parser;
use keyfork_derive_util::{request::*, DerivationPath};
use crate::client::Client;
pub fn get_args() -> ArgMatches {
Command::new("keyfork-seed")
.arg(
arg!(--path <PATH>)
.required(true)
.help("string value of a DerivationPath")
.value_parser(value_parser!(DerivationPath)),
)
.arg(
arg!(--algorithm <ALGO>)
.required(true)
.help("string value of a DerivationAlgorithm")
.value_parser(value_parser!(DerivationAlgorithm)),
)
.get_matches()
#[derive(Parser, Clone, Debug)]
pub struct Command {
#[arg(long)]
pub path: DerivationPath,
#[arg(long)]
pub algorithm: DerivationAlgorithm,
}
impl Command {
pub fn handle(&self) -> super::Result<DerivationResponse> {
let mut client = Client::discover_socket()?;
let request = DerivationRequest::new(self.algorithm.clone(), self.path.clone());
client.request(&request)
}
}

View File

@ -1,4 +1,4 @@
use keyfork_derive_util::{request::{DerivationRequest, DerivationAlgorithm}, DerivationPath};
use clap::Parser;
#[cfg(test)]
mod tests;
@ -6,14 +6,8 @@ mod tests;
use keyfork_seed::*;
fn main() -> Result<()> {
let args = cli::get_args();
let mut client = Client::discover_socket()?;
let path = args.get_one::<DerivationPath>("path").expect("required");
let algo = args
.get_one::<DerivationAlgorithm>("algorithm")
.expect("required");
let request = DerivationRequest::new(algo.clone(), path.clone());
let response = client.request(&request)?;
let args = cli::Command::parse();
let response = args.handle()?;
dbg!(&response);
Ok(())
}