killercup / quicli

Quickly build cool CLI apps in Rust.
https://killercup.github.io/quicli/
Apache License 2.0
541 stars 31 forks source link

Unix pipes support out of the box #72

Open RazrFalcon opened 6 years ago

RazrFalcon commented 6 years ago

It will be great if I could just set some flag and callback to get an ability to read from stdin and write to stdout.

archaelus commented 6 years ago

A few times now I've written an option that I wanted to turn into a Box<Read> / Box<Write> depending on whether a filename or a "-" was passed on the command line. It'd be neat if StructOpt or something could detect that (I have no idea between quicli and structopt where that responsibility would lie).

#[derive(Debug, StructOpt)]
struct Cli {
    #[structopt(short="o")]
    output: Box<Write>,
}

And then have myprog, myprog -o - turn into a boxed Stdout writer, and myprog -o somefile turn into a boxed File writer. Similarly readers/reader-writers depending on what traits you ask for in the box.