Skip to main content

nvrim/
cli.rs

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