hglib/commands/
archive.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 dest: &'a str,
10    pub rev: &'a str,
11    pub nodecode: bool,
12    pub prefix: &'a str,
13    pub typ: &'a str,
14    pub subrepos: bool,
15    pub include: &'a [&'a str],
16    pub exclude: &'a [&'a str],
17}
18
19impl<'a> Default for Arg<'a> {
20    fn default() -> Self {
21        Self {
22            dest: "",
23            rev: "",
24            nodecode: false,
25            prefix: "",
26            typ: "",
27            subrepos: false,
28            include: &[],
29            exclude: &[],
30        }
31    }
32}
33
34impl<'a> Arg<'a> {
35    fn run(&self, client: &mut Client) -> Result<(Vec<u8>, i32), HglibError> {
36        runcommand!(
37            client,
38            "archive",
39            &[self.dest],
40            "-r",
41            self.rev,
42            "--no-decode",
43            self.nodecode,
44            "-p",
45            self.prefix,
46            "-t",
47            self.typ,
48            "-S",
49            self.subrepos,
50            "-I",
51            self.include,
52            "-X",
53            self.exclude
54        )
55    }
56}
57
58impl Client {
59    pub fn archive(&mut self, x: Arg) -> Result<(), HglibError> {
60        x.run(self)?;
61        Ok(())
62    }
63}