Skip to main content

sift_grep/
lib.rs

1pub mod cli;
2pub mod config;
3pub mod format;
4pub mod grep;
5pub mod index;
6pub mod update;
7
8// Stable paths for benchmarks and integration tests that import submodules directly.
9pub use grep::run::{Run, RunConfig, RunResult};
10pub use grep::{Argv, engine, filter, ignore, output, paths, pattern};
11
12use std::process::ExitCode;
13
14use clap::Parser;
15use cli::Cli;
16use config::ConfigArgs;
17
18#[must_use]
19pub fn main_entry() -> ExitCode {
20    let raw_args = Argv::from_env();
21
22    if let Ok(cli) = Cli::try_parse_from(&raw_args)
23        && cli.command.is_some()
24    {
25        let argv = Argv::new(&raw_args);
26        return cli.dispatch(&argv);
27    }
28
29    let config_args = match ConfigArgs::from_env(&raw_args) {
30        Ok(args) => args,
31        Err(err) => {
32            eprintln!("sift: {err}");
33            return ExitCode::from(1);
34        }
35    };
36    let argv_storage = config_args.apply(&raw_args);
37    let cli = Cli::parse_from(&argv_storage);
38    let argv = Argv::new(&argv_storage);
39    cli.dispatch(&argv)
40}