diff --git a/apps/cli/src/bin/unic-echo.rs b/apps/cli/src/bin/unic-echo.rs index d0939b02..4a416216 100644 --- a/apps/cli/src/bin/unic-echo.rs +++ b/apps/cli/src/bin/unic-echo.rs @@ -14,7 +14,8 @@ extern crate clap; #[macro_use] extern crate unic_cli; -use std::io::{self, Write}; +use std::env; +use std::io::{self, Read, Write}; use clap::{Arg, ErrorKind}; @@ -111,6 +112,7 @@ fn run() -> Result<()> { .arg( Arg::with_name("STRINGS") .multiple(true) + .required(false) .help("Input strings (expected valid Unicode)"), ) .arg( @@ -133,12 +135,21 @@ fn run() -> Result<()> { let matches = app.get_matches(); // == Read input == - let input: String = matches + let mut input: String = matches .values_of("STRINGS") .unwrap_or_default() .collect::>() .join(" "); + if input.len() == 0 { + if let Some(last_arg) = env::args().last() { + if last_arg == "--" { + input.clear(); + io::stdin().read_to_string(&mut input).unwrap(); + } + } + } + let input_format = value_t!(matches, "input_format", InputFormat).unwrap_or_else(|err| match err.kind { ErrorKind::ValueValidation => { diff --git a/apps/cli/src/bin/unic-inspector.rs b/apps/cli/src/bin/unic-inspector.rs index a75eb584..e9792232 100644 --- a/apps/cli/src/bin/unic-inspector.rs +++ b/apps/cli/src/bin/unic-inspector.rs @@ -21,6 +21,10 @@ use prettytable::Table; use unic::char::property::EnumeratedCharProperty; use unic::ucd::{name_aliases_of, GeneralCategory, Name, NameAliasType}; +use std::env; +use std::io::{self, Read}; + + fn main() { let app = app_from_crate!() .about(concat!( @@ -31,17 +35,27 @@ fn main() { .arg( Arg::with_name("STRINGS") .help("Input strings (expected valid Unicode)") + .required(false) .multiple(true), ); let matches = app.get_matches(); // == Read input == - let string: String = matches + let mut input: String = matches .values_of("STRINGS") .unwrap_or_default() .collect::>() .join(" "); + if input.len() == 0 { + if let Some(last_arg) = env::args().last() { + if last_arg == "--" { + input.clear(); + io::stdin().read_to_string(&mut input).unwrap(); + } + } + } + // == Write output == let mut table = Table::new(); let mut table_format = TableFormat::new(); @@ -58,7 +72,7 @@ fn main() { ]); */ - string.chars().for_each(|chr| { + input.chars().for_each(|chr| { let display_name = Name::of(chr).map(|n| n.to_string()).unwrap_or_else(|| { match name_aliases_of(chr, NameAliasType::NameAbbreviations) { Some(abbrs) => abbrs[0].to_owned(),