mirror of
https://github.com/theryangeary/choose
synced 2024-11-23 03:13:04 +00:00
Start parsing command line and reading input file
This commit is contained in:
parent
76a6d3e53b
commit
b1baf8f9b3
1 changed files with 41 additions and 0 deletions
41
src/main.rs
Normal file
41
src/main.rs
Normal file
|
@ -0,0 +1,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!");
|
||||
}
|
Loading…
Reference in a new issue