diff options
author | Daniel Mueller <deso@posteo.net> | 2019-01-06 16:59:11 -0800 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2019-01-06 16:59:11 -0800 |
commit | e78d0432b8db215cf76cb410de354287fc2da8ba (patch) | |
tree | 1c8e160868d7749b44f66e317848170947b28249 /nitrocli/src/tests/mod.rs | |
parent | 6bb629b4d1035c3fd851244060f99da78a7bd929 (diff) | |
download | nitrocli-e78d0432b8db215cf76cb410de354287fc2da8ba.tar.gz nitrocli-e78d0432b8db215cf76cb410de354287fc2da8ba.tar.bz2 |
Introduce support for user-provided extensions
This change introduces support for discovering and executing
user-provided extensions to the program. Extensions are useful for
allowing users to provide additional functionality on top of the
nitrocli proper. Implementation wise we stick to an approach similar to
git or cargo subcommands in nature: we find executables in the PATH
environment variable whose file name starts with "nitrocli-" and allow
for them to be invoked as a nitrocli command.
Diffstat (limited to 'nitrocli/src/tests/mod.rs')
-rw-r--r-- | nitrocli/src/tests/mod.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/nitrocli/src/tests/mod.rs b/nitrocli/src/tests/mod.rs index dc15117..ce3f861 100644 --- a/nitrocli/src/tests/mod.rs +++ b/nitrocli/src/tests/mod.rs @@ -85,6 +85,15 @@ impl Builder { self } + /// Set the `PATH` used for looking up extensions. + fn path<P>(mut self, path: P) -> Self + where + P: Into<ffi::OsString>, + { + self.0.path = Some(path.into()); + self + } + /// Set the password to use for certain operations. fn password<P>(mut self, password: P) -> Self where @@ -102,6 +111,7 @@ impl Builder { struct Nitrocli { model: Option<nitrokey::Model>, + path: Option<ffi::OsString>, admin_pin: Option<ffi::OsString>, user_pin: Option<ffi::OsString>, new_admin_pin: Option<ffi::OsString>, @@ -113,6 +123,7 @@ impl Nitrocli { pub fn new() -> Self { Self { model: None, + path: None, admin_pin: Some(nitrokey::DEFAULT_ADMIN_PIN.into()), user_pin: Some(nitrokey::DEFAULT_USER_PIN.into()), new_admin_pin: None, @@ -166,6 +177,7 @@ impl Nitrocli { let ctx = &mut crate::RunCtx { stdout: &mut stdout, stderr: &mut stderr, + path: self.path.clone(), admin_pin: self.admin_pin.clone(), user_pin: self.user_pin.clone(), new_admin_pin: self.new_admin_pin.clone(), |