hglib/commands/
addremove.rs1use crate::client::{Client, HglibError, Runner};
6use crate::{runcommand, MkArg};
7
8pub struct Arg<'a> {
9 pub files: &'a [&'a str],
10 pub similarity: Option<u32>,
11 pub subrepos: bool,
12 pub dryrun: bool,
13 pub include: &'a [&'a str],
14 pub exclude: &'a [&'a str],
15}
16
17impl<'a> Default for Arg<'a> {
18 fn default() -> Self {
19 Self {
20 files: &[],
21 similarity: None,
22 subrepos: false,
23 dryrun: false,
24 include: &[],
25 exclude: &[],
26 }
27 }
28}
29
30impl<'a> Arg<'a> {
31 fn run(&self, client: &mut Client) -> Result<(Vec<u8>, i32), HglibError> {
32 if let Some(x) = self.similarity {
33 if x > 100 {
34 return Err(HglibError::from(format!("Invalid similarity: {}", x)));
35 }
36 }
37 runcommand!(
38 client,
39 "addremove",
40 self.files,
41 "-s",
42 self.similarity,
43 "-n",
44 self.dryrun,
45 "-S",
46 self.subrepos,
47 "-I",
48 self.include,
49 "-X",
50 self.exclude
51 )
52 }
53}
54
55impl Client {
56 pub fn addremove(&mut self, x: Arg) -> Result<bool, HglibError> {
57 HglibError::handle_err(x.run(self))
58 }
59}