diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2017-08-13 21:48:17 +0000 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2017-08-27 15:12:09 +0200 |
commit | 59a3662ac47b0c657781bd1db34bbf9a5a692326 (patch) | |
tree | 709f72c44c8d978a5a76abb9036c6f08744a4aa2 /lib/core/libimagrt/src/spec.rs | |
parent | 31254071e5a4bf2f5db9067c5cdb22c25579ac67 (diff) |
Reorganize code in subdirs
Diffstat (limited to 'lib/core/libimagrt/src/spec.rs')
-rw-r--r-- | lib/core/libimagrt/src/spec.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/core/libimagrt/src/spec.rs b/lib/core/libimagrt/src/spec.rs new file mode 100644 index 00000000..0293f249 --- /dev/null +++ b/lib/core/libimagrt/src/spec.rs @@ -0,0 +1,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); + } +} |