aboutsummaryrefslogtreecommitdiff
path: root/nitrocli/src/main.rs
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2019-01-06 16:59:11 -0800
committerDaniel Mueller <deso@posteo.net>2019-01-06 16:59:11 -0800
commite78d0432b8db215cf76cb410de354287fc2da8ba (patch)
tree1c8e160868d7749b44f66e317848170947b28249 /nitrocli/src/main.rs
parent6bb629b4d1035c3fd851244060f99da78a7bd929 (diff)
downloadnitrocli-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/main.rs')
-rw-r--r--nitrocli/src/main.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/nitrocli/src/main.rs b/nitrocli/src/main.rs
index bb4b007..92ecfe6 100644
--- a/nitrocli/src/main.rs
+++ b/nitrocli/src/main.rs
@@ -101,6 +101,8 @@ pub(crate) struct RunCtx<'io> {
pub stdout: &'io mut dyn io::Write,
/// The `Write` object used as standard error throughout the program.
pub stderr: &'io mut dyn io::Write,
+ /// The content of the `PATH` environment variable.
+ pub path: Option<ffi::OsString>,
/// The admin PIN, if provided through an environment variable.
pub admin_pin: Option<ffi::OsString>,
/// The user PIN, if provided through an environment variable.
@@ -129,6 +131,11 @@ fn run<'ctx, 'io: 'ctx>(ctx: &'ctx mut RunCtx<'io>, args: Vec<String>) -> i32 {
// argparse printed an error message
_ => 1,
},
+ Error::ExtensionFailed(_, rc) => {
+ // We let the extension itself deal with error reporting, we
+ // just mirror its exit code (if any).
+ rc.unwrap_or(1)
+ }
_ => {
let _ = eprintln!(ctx, "{}", err);
1
@@ -146,6 +153,7 @@ fn main() {
let ctx = &mut RunCtx {
stdout: &mut stdout,
stderr: &mut stderr,
+ path: env::var_os("PATH"),
admin_pin: env::var_os(NITROCLI_ADMIN_PIN),
user_pin: env::var_os(NITROCLI_USER_PIN),
new_admin_pin: env::var_os(NITROCLI_NEW_ADMIN_PIN),