Skip to main content

nvrim/
cli.rs

1//! CLI flag generation helpers for search tools (`fd`, `rg`).
2//!
3//! Centralizes glob blacklist + base flags for Rust and plugin-facing helpers.
4
5mod fd;
6mod rg;
7
8/// A list of glob patterns to exclude from searches.
9pub const GLOB_BLACKLIST: [&str; 7] = [
10    "**/.git/*",
11    "**/target/*",
12    "**/target-*/*",
13    "**/_build/*",
14    "**/deps/*",
15    "**/.elixir_ls/*",
16    "**/node_modules/*",
17];
18
19/// Trait for generating CLI flags for search tools.
20pub trait CliFlags {
21    /// Returns the base flags for the CLI tool.
22    fn base_flags() -> Vec<&'static str>;
23
24    /// Converts a glob pattern to a CLI flag.
25    fn glob_flag(glob: &str) -> String;
26
27    /// Generates the complete list of CLI flags.
28    fn get((): ()) -> Vec<String> {
29        Self::base_flags()
30            .into_iter()
31            .map(Into::into)
32            .chain(GLOB_BLACKLIST.into_iter().map(Self::glob_flag))
33            .collect::<Vec<_>>()
34    }
35}
36
37/// Returns the `fd` flags used by `fzf-lua` file pickers.
38pub fn get_fd_flags((): ()) -> Vec<String> {
39    fd::FdCliFlags::get(())
40}
41
42/// Returns the `rg` flags used by `fzf-lua` grep pickers.
43pub fn get_rg_flags((): ()) -> Vec<String> {
44    rg::RgCliFlags::get(())
45}