File: cat.rs

package info (click to toggle)
rust-clio 0.3.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 280 kB
  • sloc: sh: 20; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 774 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use clio::*;

#[cfg(feature = "clap-parse")]
use clap::Parser;
#[cfg(feature = "clap-parse")]
#[derive(Parser)]
#[clap(name = "cat")]
struct Opt {
    /// Input file, use '-' for stdin
    #[arg(default_values_t = vec![Input::std()])]
    inputs: Vec<Input>,

    /// Output file '-' for stdout
    #[clap(long, short, value_parser, default_value = "-")]
    output: Output,
}

#[cfg(feature = "clap-parse")]
fn main() {
    let mut opt = Opt::parse();

    for mut input in opt.inputs {
        std::io::copy(&mut input, &mut opt.output).unwrap();
    }
}

#[cfg(not(feature = "clap-parse"))]
fn main() {
    for arg in std::env::args_os().skip(1) {
        let mut input = Input::new(&arg).unwrap();
        std::io::copy(&mut input, &mut Output::std()).unwrap();
    }
}