Skip to content

Commit

Permalink
minimal grep on stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
bergey committed Apr 27, 2022
0 parents commit 03c8572
Show file tree
Hide file tree
Showing 4 changed files with 307 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
271 changes: 271 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "tsed"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "3.0.10", features = ["derive"] }
regex = "1"
25 changes: 25 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use clap::Parser;
use regex::Regex;
use std::io;

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Cli {
/// The pattern to find
#[clap()]
pattern: String
}

fn main() {
let args = Cli::parse();
let stdin = io::stdin();

let regex = Regex::new(&args.pattern).unwrap();
let mut buf = String::new();
while stdin.read_line(&mut buf).unwrap() != 0 {
if regex.is_match(&buf) {
print!("{}", buf);
}
buf.clear();
}
}

0 comments on commit 03c8572

Please sign in to comment.