hglib/commands/
copy.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this file,
3// You can obtain one at http://mozilla.org/MPL/2.0/.
4
5use crate::client::{Client, HglibError, Runner};
6use crate::{runcommand, MkArg};
7
8pub struct Arg<'a> {
9    pub source: &'a [&'a str],
10    pub dest: &'a str,
11    pub after: bool,
12    pub force: bool,
13    pub dryrun: bool,
14    pub include: &'a [&'a str],
15    pub exclude: &'a [&'a str],
16}
17
18impl<'a> Default for Arg<'a> {
19    fn default() -> Self {
20        Self {
21            source: &[],
22            dest: "",
23            after: false,
24            force: false,
25            dryrun: false,
26            include: &[],
27            exclude: &[],
28        }
29    }
30}
31
32impl<'a> Arg<'a> {
33    fn run(&self, client: &mut Client) -> Result<(Vec<u8>, i32), HglibError> {
34        let mut args = self.source.to_vec();
35        args.push(self.dest);
36        runcommand!(
37            client,
38            "copy",
39            args,
40            "-A",
41            self.after,
42            "-f",
43            self.force,
44            "-n",
45            self.dryrun,
46            "-I",
47            self.include,
48            "-X",
49            self.exclude
50        )
51    }
52}
53
54impl Client {
55    pub fn copy(&mut self, x: Arg) -> Result<bool, HglibError> {
56        HglibError::handle_err(x.run(self))
57    }
58}