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] [dependencies]
bincode = { version = "1.3.3", default-features = false } 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-derive-util = { version = "0.1.0", path = "../keyfork-derive-util" }
keyfork-frame = { version = "0.1.0", path = "../keyfork-frame", default-features = false } keyfork-frame = { version = "0.1.0", path = "../keyfork-frame", default-features = false }
thiserror = "1.0.48" 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 keyfork_derive_util::{request::*, DerivationPath};
use crate::client::Client;
pub fn get_args() -> ArgMatches { #[derive(Parser, Clone, Debug)]
Command::new("keyfork-seed") pub struct Command {
.arg( #[arg(long)]
arg!(--path <PATH>) pub path: DerivationPath,
.required(true)
.help("string value of a DerivationPath") #[arg(long)]
.value_parser(value_parser!(DerivationPath)), pub algorithm: DerivationAlgorithm,
) }
.arg(
arg!(--algorithm <ALGO>) impl Command {
.required(true) pub fn handle(&self) -> super::Result<DerivationResponse> {
.help("string value of a DerivationAlgorithm") let mut client = Client::discover_socket()?;
.value_parser(value_parser!(DerivationAlgorithm)), let request = DerivationRequest::new(self.algorithm.clone(), self.path.clone());
) client.request(&request)
.get_matches() }
} }

View File

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