aboutsummaryrefslogtreecommitdiff
path: root/src/cmd.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd.rs')
-rw-r--r--src/cmd.rs22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/cmd.rs b/src/cmd.rs
index 63470a4..c10f834 100644
--- a/src/cmd.rs
+++ b/src/cmd.rs
@@ -3,11 +3,17 @@
pub mod address;
pub mod export;
pub mod hash;
+pub mod hex;
pub mod new;
pub mod sign;
use crate::{account::PrivateKey, hdk, mnemonic::Mnemonic};
use anyhow::Result;
+use std::{
+ fs,
+ io::{self, Read as _},
+ path::Path,
+};
use structopt::StructOpt;
/// Shared account options.
@@ -50,8 +56,22 @@ impl AccountOptions {
fn permissive_hex(s: &str) -> Result<Box<[u8]>> {
let trimmed = s.chars().filter(|c| !c.is_whitespace()).collect::<String>();
let hex_string = trimmed.strip_prefix("0x").unwrap_or(&trimmed);
- let bytes = hex::decode(&hex_string)?;
+ let bytes = ::hex::decode(&hex_string)?;
// NOTE: Use a boxed slice instead of a `Vec` as the former has special
// scemantics with `structopt`.
Ok(bytes.into_boxed_slice())
}
+
+/// Read input for the specified path with `-` used to signify standard in.
+fn read_input(input: &Path) -> Result<Vec<u8>> {
+ let data = match input.to_str() {
+ Some("-") => {
+ let mut buf = Vec::new();
+ io::stdin().read_to_end(&mut buf)?;
+ buf
+ }
+ _ => fs::read(&input)?,
+ };
+
+ Ok(data)
+}