From 62509c100c876b6d427673709a530c481ec7e4c0 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Tue, 25 Aug 2020 19:04:50 -0700 Subject: 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 search the directories listed in the PATH environment variable for a file that starts with "nitrocli-", followed by the extension name. This file is then executed. It is assumed that the extension recognizes (or at least not prohibits) the following arguments: --nitrocli (providing the path to the nitrocli binary), --model (with the model passed to the main program), and --verbosity (the verbosity level). --- src/tests/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/tests/mod.rs') diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 65983bb..5e47520 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -9,6 +9,7 @@ use nitrokey_test::test as test_device; mod config; mod encrypted; +mod extensions; mod fill; mod hidden; mod list; @@ -23,6 +24,7 @@ mod unencrypted; struct Nitrocli { model: Option, + path: Option, admin_pin: Option, user_pin: Option, new_admin_pin: Option, @@ -34,6 +36,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, @@ -54,6 +57,12 @@ impl Nitrocli { self } + /// Set the `PATH` used for looking up extensions. + fn path(mut self, path: impl Into) -> Self { + self.path = Some(path.into()); + self + } + pub fn admin_pin(mut self, pin: impl Into) -> Self { self.admin_pin = Some(pin.into()); self @@ -102,6 +111,7 @@ impl Nitrocli { stdout: &mut stdout, stderr: &mut stderr, is_tty: false, + path: self.path.clone(), admin_pin: self.admin_pin.clone(), user_pin: self.user_pin.clone(), new_admin_pin: self.new_admin_pin.clone(), -- cgit v1.2.1