hglib/commands/
init.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 ssh: &'a str,
11    pub remotecmd: &'a str,
12    pub insecure: bool,
13}
14
15impl<'a> Default for Arg<'a> {
16    fn default() -> Self {
17        Self {
18            dest: "",
19            ssh: "",
20            remotecmd: "",
21            insecure: false,
22        }
23    }
24}
25
26impl<'a> Arg<'a> {
27    pub fn run<T: Runner>(&self, client: &mut T) -> Result<(Vec<u8>, i32), HglibError> {
28        runcommand!(
29            client,
30            "init",
31            &[self.dest],
32            "-e",
33            self.ssh,
34            "--remotecmd",
35            self.remotecmd,
36            "--insecure",
37            self.insecure
38        )
39    }
40}
41
42impl Client {
43    pub fn init(&mut self, x: Arg) -> Result<(), HglibError> {
44        x.run(self)?;
45        Ok(())
46    }
47}