feat: works now
This commit is contained in:
@@ -1,14 +1,39 @@
|
||||
use clap::Args;
|
||||
use rust_util::XResult;
|
||||
use std::io::Write;
|
||||
use base58::{FromBase58, ToBase58};
|
||||
use crate::CmdExec;
|
||||
use clap::Args;
|
||||
use rust_util::{opt_result, simple_error, XResult};
|
||||
use crate::util::read_file_or_stdin;
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
pub struct CmdBase58 {
|
||||
|
||||
/// Encode
|
||||
#[arg(long, short = 'e')]
|
||||
pub encode: bool,
|
||||
/// Decode
|
||||
#[arg(long, short = 'd')]
|
||||
pub decode: bool,
|
||||
/// Input file
|
||||
#[arg(long, short = 'i')]
|
||||
pub r#in: Option<String>,
|
||||
}
|
||||
|
||||
impl CmdExec for CmdBase58 {
|
||||
fn exec(&self) -> XResult<()> {
|
||||
todo!()
|
||||
if self.encode && self.decode {
|
||||
return simple_error!("Encode and decode cannot both assigned.");
|
||||
}
|
||||
|
||||
let input = read_file_or_stdin(&self.r#in)?;
|
||||
|
||||
if self.decode {
|
||||
let s = opt_result!(String::from_utf8(input), "Decode UTF8 failed: {}");
|
||||
let decoded = opt_result!(s.from_base58(), "Decode base58 failed: {:?}");
|
||||
std::io::stdout().write_all(&decoded)?;
|
||||
} else {
|
||||
let encoded = input.to_base58();
|
||||
print!("{}", encoded);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user