From 0c53d183ecbd599e6fc60e5454ae0eb6e146810e Mon Sep 17 00:00:00 2001 From: Alexandre Pasmantier Date: Sun, 21 Jul 2024 14:02:52 +0200 Subject: [PATCH] chore(docs): add basic README.md --- Cargo.toml | 14 +++++++- README.md | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/cli.rs | 10 +++--- 3 files changed, 113 insertions(+), 6 deletions(-) create mode 100644 README.md diff --git a/Cargo.toml b/Cargo.toml index 53c7a8e..69ae166 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,8 +2,20 @@ name = "grab" version = "0.1.0" edition = "2021" +authors = ["Alexandre Pasmantier "] +license = "Apache-2.0" +description = "A faster, more lightweight ripgrep alternative." +readme = "README.md" +homepage = "https://github.com/alexpasmantier/grab" +repository = "https://github.com/alexpasmantier/grab" +keywords = ["cli", "search", "grep", "ripgrep", "rust", "files"] +categories = [ + "command-line-utilities", + "command-line-interface", + "concurrency", + "development-tools", +] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] anyhow = "1.0.86" diff --git a/README.md b/README.md new file mode 100644 index 0000000..4ead2f0 --- /dev/null +++ b/README.md @@ -0,0 +1,95 @@ + +# Grab + +A faster, more lightweight, ripgrep alternative. + +## Installation +### Using Cargo +```bash +$ cargo install grab +``` + +## Usage +```sh +$ grab "some\s+pattern" . + +/somewhere/grab/src/cli.rs +9: pub struct Cli { +11: pub pattern: String, +14: pub path: PathBuf, +18: pub ignore_paths: Vec, +22: pub respect_gitignore: bool, +26: pub max_results: usize, +30: pub n_threads: usize, +34: pub multiline: bool, +38: pub json: bool, +42: pub file_paths_only: bool, +46: pub struct PostProcessedCli { +47: pub pattern: String, +48: pub path: PathBuf, +49: pub ignored_paths: Vec, +50: pub max_results: usize, +51: pub n_threads: usize, +52: pub respect_gitignore: bool, +53: pub multiline: bool, +54: pub print_mode: PrintMode, +57: pub fn process_cli_args(cli: Cli) -> anyhow::Result { + +/somewhere/grab/src/utils.rs +3: pub fn resolve_paths(paths: Vec) -> Vec { +7: pub fn resolve_path(path: PathBuf) -> PathBuf { + +/somewhere/grab/src/search.rs +12: pub struct SearchResult { +13: pub line_number: u64, +14: pub line: String, +18: pub struct FileResults { +19: pub path: PathBuf, +20: pub results: Vec, +34: pub fn is_empty(&self) -> bool { +38: pub fn len(&self) -> usize { +52: pub fn search_file<'a>( +82: pub fn build_matcher(pattern: &str) -> anyhow::Result { +87: pub fn build_searcher(multiline: bool) -> Searcher { + +/somewhere/grab/src/fs.rs +5: pub fn walk_builder( + +/somewhere/grab/src/main.rs +17: pub fn main() -> anyhow::Result<()> { + +/somewhere/grab/src/printer.rs +6: pub enum PrintMode { +12: pub struct Printer { +18: pub fn new(mode: PrintMode) -> Printer { +27: pub fn write(&mut self, results: FileResults) -> Result<()> { +39: pub fn print(&mut self) -> Result<()> { + +``` + +## Documentation +```sh +$ grab --help +``` + +```plaintext +A faster, more lightweight, ripgrep alternative. + +Usage: grab [OPTIONS] + +Arguments: + a regex pattern to search for + path in which to search recursively + +Options: + -I, --ignore-paths paths to ignore when recursively walking target directory + -G, --respect-gitignore respect .gitignore when recursively walking directory + -M, --max-results upper boundary for the number of results to expect (will panic if #results > max_results) [default: 1000] + -T, --n-threads number of threads to use [default: 4] + -U, --multiline enable multiline matching + --json output in JSON format + -f, --file-paths-only output file paths only + -h, --help Print help + -V, --version Print version + +``` diff --git a/src/cli.rs b/src/cli.rs index 58e46e2..36a41d2 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -5,19 +5,19 @@ use clap::Parser; #[derive(Parser, Debug)] #[command(name = "git")] -#[command(arg_required_else_help=true, version, about = "A grep-like utility", long_about = None)] +#[command(arg_required_else_help=true, version, about = "A faster, more lightweight, ripgrep alternative.", long_about = None)] pub struct Cli { - /// pattern to search for + /// a regex pattern to search for pub pattern: String, /// path in which to search recursively pub path: PathBuf, - /// paths to ignore when walking directory + /// paths to ignore when recursively walking target directory #[clap(short = 'I', long)] pub ignore_paths: Vec, - /// respect .gitignore when walking directory + /// respect .gitignore when recursively walking directory #[clap(short = 'G', long, default_value_t = true)] pub respect_gitignore: bool, @@ -29,7 +29,7 @@ pub struct Cli { #[clap(short = 'T', long, default_value_t = 4)] pub n_threads: usize, - /// enable multiline matching (off by default) + /// enable multiline matching #[clap(short = 'U', long, default_value_t = false)] pub multiline: bool,