Mercurial > public > mercurial-scm > hg
annotate 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 |
rev | line source |
---|---|
52557
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
1 use clap::Arg; |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
2 use hg::matchers::ReSyntax; |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
3 |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
4 use crate::error::CommandError; |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
5 |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
6 use super::debugignorerhg::WhichPatterns; |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
7 |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
8 pub const HELP_TEXT: &str = " |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
9 Show effective hgignore patterns used by rhg. |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
10 |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
11 This is a pure Rust version of `hg debugignore`. |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
12 |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
13 Some options might be missing, check the list below. |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
14 "; |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
15 |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
16 pub fn args() -> clap::Command { |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
17 clap::command!("script::hgignore") |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
18 .arg( |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
19 Arg::new("print-re") |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
20 .help("Print the regular expression that matches all ignored files.") |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
21 .action(clap::ArgAction::SetTrue) |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
22 .long("print-re"), |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
23 ).about(HELP_TEXT) |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
24 } |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
25 |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
26 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
27 let repo = invocation.repo?; |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
28 let args = invocation.subcommand_args; |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
29 let print_re = args.get_flag("print-re"); |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
30 if !print_re { |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
31 return Err(CommandError::unsupported( |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
32 "Unsupported invocation: flag --print-re is required", |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
33 )); |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
34 } |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
35 |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
36 crate::commands::debugignorerhg::work( |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
37 repo, |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
38 invocation.ui, |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
39 WhichPatterns::All, |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
40 ReSyntax::Tidy, |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
41 ) |
b89c934e6269
rust-hgignore: add a scripting command to print the hgignore regexp
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
diff
changeset
|
42 } |