Skip to content

Commit

Permalink
grep support added
Browse files Browse the repository at this point in the history
  • Loading branch information
legendary-acp committed Aug 30, 2024
1 parent e65ae44 commit b2c3172
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ version = "0.1.0"
edition = "2021"

[dependencies]
log = "0.4.22"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ cli_utils find /path/to/search -name "filename"
Searches for a pattern within files:

```bash
cli_utils grep "search_term" file.txt
cli_utils grep file.txt "search_term"
```

## Contributing
Expand Down
11 changes: 10 additions & 1 deletion src/commands/grep.rs
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
pub fn execute(_file_name: String, _text: String) {}
use std::fs::read_to_string;

pub fn execute(file_name: String, text: String) {
for line in read_to_string(file_name).unwrap().lines() {
let cur_line = line.to_string();
if cur_line.contains(text.as_str()) {
println!("{}", cur_line)
}
}
}
7 changes: 6 additions & 1 deletion src/commands/ls.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
pub fn execute(_dirs: &[String]) {}
pub fn execute(dirs: &[String]) {
for dir in dirs {
println!("{} contains following files:", dir);
list_dir(dir);
}
}

fn list_dir(_dir: &String) {}
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod commands;

use std::env;
use std::io::prelude::*;

fn main() {
let args: Vec<String> = env::args().collect();
Expand Down

0 comments on commit b2c3172

Please sign in to comment.