view rust/rhg/src/commands/script_hgignore.rs @ 52557:b89c934e6269

rust-hgignore: add a scripting command to print the hgignore regexp Add a command `script::hgignore --print-re` to print the hgignore regexp. One complication is that the `rootfilesin`-only matcher doesn't use a regular expression, and the existing converts it to something that's not a regular expression. We add code to handle that case. Since this command is now sufficient to generate a tidy-looking regexp for scripting, this frees up the "debug" command to report the internal regexp used by the regex engine, so we make that change too.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Fri, 13 Dec 2024 15:05:37 +0000
parents
children
line wrap: on
line source

use clap::Arg;
use hg::matchers::ReSyntax;

use crate::error::CommandError;

use super::debugignorerhg::WhichPatterns;

pub const HELP_TEXT: &str = "
Show effective hgignore patterns used by rhg.

This is a pure Rust version of `hg debugignore`.

Some options might be missing, check the list below.
";

pub fn args() -> clap::Command {
    clap::command!("script::hgignore")
    .arg(
        Arg::new("print-re")
            .help("Print the regular expression that matches all ignored files.")
            .action(clap::ArgAction::SetTrue)
            .long("print-re"),
    ).about(HELP_TEXT)
}

pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
    let repo = invocation.repo?;
    let args = invocation.subcommand_args;
    let print_re = args.get_flag("print-re");
    if !print_re {
        return Err(CommandError::unsupported(
            "Unsupported invocation: flag --print-re is required",
        ));
    }

    crate::commands::debugignorerhg::work(
        repo,
        invocation.ui,
        WhichPatterns::All,
        ReSyntax::Tidy,
    )
}