1 use std::os::unix::prelude::OsStrExt; |
1 use std::{ |
|
2 ffi::{OsStr, OsString}, |
|
3 os::unix::prelude::OsStrExt, |
|
4 }; |
2 |
5 |
3 use crate::error::CommandError; |
6 use crate::error::CommandError; |
4 use clap::SubCommand; |
|
5 use hg::{self, utils::hg_path::HgPath}; |
7 use hg::{self, utils::hg_path::HgPath}; |
6 |
8 |
7 pub const HELP_TEXT: &str = ""; |
9 pub const HELP_TEXT: &str = ""; |
8 |
10 |
9 pub fn args() -> clap::App<'static, 'static> { |
11 pub fn args() -> clap::Command { |
10 SubCommand::with_name("debugrhgsparse") |
12 clap::command!("debugrhgsparse") |
11 .arg( |
13 .arg( |
12 clap::Arg::with_name("files") |
14 clap::Arg::new("files") |
|
15 .value_name("FILES") |
13 .required(true) |
16 .required(true) |
14 .multiple(true) |
17 .num_args(1..) |
15 .empty_values(false) |
18 .value_parser(clap::value_parser!(std::ffi::OsString)) |
16 .value_name("FILES") |
|
17 .help("Files to check against sparse profile"), |
19 .help("Files to check against sparse profile"), |
18 ) |
20 ) |
19 .about(HELP_TEXT) |
21 .about(HELP_TEXT) |
20 } |
22 } |
21 |
23 |
22 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { |
24 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { |
23 let repo = invocation.repo?; |
25 let repo = invocation.repo?; |
24 |
26 |
25 let (matcher, _warnings) = hg::sparse::matcher(&repo).unwrap(); |
27 let (matcher, _warnings) = hg::sparse::matcher(&repo).unwrap(); |
26 let files = invocation.subcommand_args.values_of_os("files"); |
28 let files = invocation.subcommand_args.get_many::<OsString>("files"); |
27 if let Some(files) = files { |
29 if let Some(files) = files { |
|
30 let files: Vec<&OsStr> = files |
|
31 .filter(|s| !s.is_empty()) |
|
32 .map(|s| s.as_os_str()) |
|
33 .collect(); |
28 for file in files { |
34 for file in files { |
29 invocation.ui.write_stdout(b"matches: ")?; |
35 invocation.ui.write_stdout(b"matches: ")?; |
30 invocation.ui.write_stdout( |
36 invocation.ui.write_stdout( |
31 if matcher.matches(HgPath::new(file.as_bytes())) { |
37 if matcher.matches(HgPath::new(file.as_bytes())) { |
32 b"yes" |
38 b"yes" |