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
34
35
36
37
38
39
40
41
|
use std::fs::File;
use std::io::{self, BufRead, BufReader, Read};
use std::path::PathBuf;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
#[structopt(name = "choose", about = "`choose` sections from each line of files")]
struct Opt {
/// Specify field separator other than whitespace
#[structopt(short, long, default_value = "")]
field_separator: String,
/// Use inclusive ranges
#[structopt(short, long)]
inclusive: bool,
/// Activate debug mode
#[structopt(short, long)]
debug: bool,
/// Input file
#[structopt(parse(from_os_str))]
input: Option<PathBuf>,
}
fn main() {
let opt = Opt::from_args();
let read = match &opt.input {
Some(f) => Box::new(File::open(f).expect("Could not open file")) as Box<Read>,
None => Box::new(io::stdin()) as Box<Read>,
};
let buf = BufReader::new(read);
for line in buf.lines() {
println!("{}", line.unwrap());
}
println!("Hello, world!");
}
|