Expand description
Add optional --input and --output flags to a clap command. If --input is not specified,
it defaults to (locked) stdin. If --output is not specified, it defaults to (locked) stdout.
§Examples
Add get --input and --output flags to your program:
use clap::Parser;
use clap_io::InputOutput;
#[derive(Parser)]
struct Cli {
#[clap(flatten)]
io: InputOutput,
}
let cli = Cli::parse();
let mut input = cli.io.input.open().unwrap();
let mut output = cli.io.output.open().unwrap();
std::io::copy(&mut input, &mut output).unwrap();Add just one:
use clap::Parser;
use clap_io::Input;
#[derive(Parser)]
struct Cli {
#[clap(long = "in")]
input: Input,
}
let cli = Cli::parse();
eprintln!("is tty? {}", cli.input.is_tty());
eprintln!("path? {:?}", cli.input.path());Structs§
- Input
- Either a file or stdin.
- Input
Output - Combined input and output options.
- Output
- Either a file or stdout.