summaryrefslogtreecommitdiffstats
path: root/lib/core/libimagrt/src/spec.rs
blob: 0293f249f406493c8d1dc2f942e368899cfafb1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use std::io::Write;

use clap::{App, ArgMatches, Shell};

/// An abstraction over `clap::App` functionality needed for initializing `Runtime`. Different
/// implementations can be used for testing `imag` binaries without running them as separate
/// processes.
pub trait CliSpec<'a> {
    fn name(&self) -> &str;
    fn matches(self) -> ArgMatches<'a>;
    fn completions<W: Write, S: Into<String>>(&mut self, _: S, _: Shell, _: &mut W) {}
}

impl<'a> CliSpec<'a> for App<'a, 'a> {
    fn name(&self) -> &str {
        self.get_name()
    }

    fn matches(self) -> ArgMatches<'a> {
        self.get_matches()
    }

    fn completions<W: Write, S: Into<String>>(&mut self,
                                              bin_name: S,
                                              for_shell: Shell,
                                              buf: &mut W) {

        self.gen_completions_to(bin_name, for_shell, buf);
    }
}