Closed carenas closed 5 years ago
Great! Thanks for the suggestion.
I see one super minor issue: the usage message is
USAGE:
diffr reads from standard input and write to standard output.
(...)
which does not respect the template (compared to diffr -h
:
(...)
USAGE:
diffr reads from standard input and write to standard output.
(...)
Plus cargo fmt.
so I suggest the following:
diff --git a/src/main.rs b/src/main.rs
index f861c32..9ee480b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,4 @@
+use atty::{is, Stream};
use clap::{App, Arg};
use std::collections::hash_map::DefaultHasher;
use std::convert::TryFrom;
@@ -9,29 +10,18 @@ use termcolor::{
Color::{Green, Red},
ColorChoice, ColorSpec, StandardStream, WriteColor,
};
-use atty::{is, Stream};
const ABOUT: &str = "
diffr adds word-level diff on top of unified diffs.
word-level diff information is displayed using text attributes.";
-const USAGE: &str = "
+const USAGE: &str = "\
diffr reads from standard input and write to standard output.
Typical usage is for interactive use of diff:
diff -u <file1> <file2> | diffr
git show | diffr";
-const TEMPLATE: &str = "\
-{bin} {version}
-{author}
-{about}
-
-USAGE:{usage}
-
-OPTIONS:
-{unified}";
-
const FLAG_DEBUG: &str = "debug";
#[derive(Debug)]
@@ -45,7 +35,6 @@ fn main() {
.author("Nathan Moreau <nathan.moreau@m4x.org>")
.about(ABOUT)
.usage(USAGE)
- .template(TEMPLATE)
.arg(Arg::with_name(FLAG_DEBUG).long("debug").hidden(true))
.get_matches();
the application is designed to be run as a filter, but if called without data in stdin will seem to "hang".
detect if stdin is attached to a tty and abort instead printing usage() to stdout as is commonly done by other filters (ex: more, less)
Signed-off-by: Carlo Marcelo Arenas Belón carenas@gmail.com