clap_file/
lib.rs

1//! Provides types for clap's derive interface, enabling easy handling of input/output with automatically opened files or standard input/output based on command-line arguments.
2//!
3//! # Usage
4//!
5//! Run `cargo add clap-file` or add this to your `Cargo.toml`:
6//!
7//! ```toml
8//! [dependencies]
9//! clap-file = "0.2.0"
10//! ```
11//!
12//! # Examples
13//!
14//! Example usage of [`Input`] ans [`Output`] types:
15//!
16//! ```rust,no_run
17//! use std::io::{self, BufRead as _, Write as _};
18//!
19//! use clap::Parser as _;
20//! use clap_file::{Input, Output};
21//!
22//! #[derive(Debug, clap::Parser)]
23//! struct Args {
24//!     /// Input file. If not provided, reads from standard input.
25//!     input: Input,
26//!     /// output file. If not provided, reads from standard output.
27//!     output: Output,
28//! }
29//!
30//! fn main() -> io::Result<()> {
31//!     let args = Args::parse();
32//!     let input = args.input.lock();
33//!     let mut output = args.output.lock();
34//!     for line in input.lines() {
35//!         let line = line?;
36//!         writeln!(&mut output, "{line}")?;
37//!     }
38//!     Ok(())
39//! }
40//! ```
41
42#![doc(html_root_url = "https://docs.rs/clap-file/0.2.0")]
43#![warn(missing_docs)]
44
45pub use self::{input::*, output::*};
46
47mod input;
48mod output;