hglib/commands/
cat.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 files: &'a [&'a str],
10    pub rev: &'a [&'a str],
11    pub decode: bool,
12    pub output: &'a str,
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            rev: &[],
22            decode: false,
23            output: "",
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        runcommand!(
33            client,
34            "cat",
35            self.files,
36            "-r",
37            self.rev,
38            "-o",
39            self.output,
40            "-I",
41            self.include,
42            "-X",
43            self.exclude
44        )
45    }
46}
47
48impl Client {
49    pub fn cat(&mut self, x: Arg) -> Result<Option<Vec<u8>>, HglibError> {
50        let (data, _) = x.run(self)?;
51        Ok(if x.output.is_empty() {
52            Some(data)
53        } else {
54            None
55        })
56    }
57}