1use crate::client::{Client, HglibError, Runner};
6use crate::{runcommand, MkArg};
7
8pub struct Arg<'a> {
9 pub source: &'a str,
10 pub noupdate: bool,
11 pub dest: &'a str,
12 pub branch: &'a str,
13 pub updaterev: &'a str,
14 pub revrange: &'a str,
15 pub pull: bool,
16 pub stream: bool,
17 pub ssh: &'a str,
18 pub remotecmd: &'a str,
19 pub insecure: bool,
20}
21
22impl<'a> Default for Arg<'a> {
23 fn default() -> Self {
24 Self {
25 source: ".",
26 noupdate: false,
27 dest: "",
28 branch: "",
29 updaterev: "",
30 revrange: "",
31 pull: false,
32 stream: false,
33 ssh: "",
34 remotecmd: "",
35 insecure: false,
36 }
37 }
38}
39
40impl<'a> Arg<'a> {
41 pub fn run<T: Runner>(&self, client: &mut T) -> Result<(Vec<u8>, i32), HglibError> {
42 runcommand!(
43 client,
44 "clone",
45 &[self.source, self.dest],
46 "-U",
47 self.noupdate,
48 "-b",
49 self.branch,
50 "-u",
51 self.updaterev,
52 "-r",
53 self.revrange,
54 "--pull",
55 self.pull,
56 "--stream",
57 self.stream,
58 "-e",
59 self.ssh,
60 "--remotecmd",
61 self.remotecmd,
62 "--insecure",
63 self.insecure
64 )
65 }
66}
67
68impl Client {
69 pub fn clone(&mut self, x: Arg) -> Result<(), HglibError> {
70 x.run(self)?;
71 Ok(())
72 }
73}