Created
June 2, 2020 17:47
-
-
Save gabrieledarrigo/069ac7e60fef5f8007c863e8a5cd1ce4 to your computer and use it in GitHub Desktop.
Grass command line utility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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