Skip to content

Instantly share code, notes, and snippets.

@gabrieledarrigo
Created June 2, 2020 17:47
Show Gist options
  • Save gabrieledarrigo/069ac7e60fef5f8007c863e8a5cd1ce4 to your computer and use it in GitHub Desktop.
Save gabrieledarrigo/069ac7e60fef5f8007c863e8a5cd1ce4 to your computer and use it in GitHub Desktop.
Grass command line utility
use structopt::StructOpt;
use std::io::Error;
#[derive(Debug, StructOpt)]
struct Cli {
pattern: String,
#[structopt(parse(from_os_str))]
path: std::path::PathBuf,
}
fn main() -> Result<(), Error> {
let args = Cli::from_args();
let content = std::fs::read_to_string(&args.path)?;
for line in content.lines() {
if line.contains(&args.pattern) {
println!("{}", line);
}
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment