diff options
author | Daniel Mueller <deso@posteo.net> | 2020-08-25 19:04:50 -0700 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2020-08-25 19:04:50 -0700 |
commit | 223c8484f727451d15ad23ffb0133a1858b56b5c (patch) | |
tree | 383713050d9da0fa3f6b7ef9802bfbfd836ebb74 /src/main.rs | |
parent | c2a9d31ee70ddae22ea410a383a094b7842e50fd (diff) | |
download | nitrocli-223c8484f727451d15ad23ffb0133a1858b56b5c.tar.gz nitrocli-223c8484f727451d15ad23ffb0133a1858b56b5c.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 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).
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index 27097c9..5d4ea1d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -80,6 +80,7 @@ use std::ffi; use std::io; use std::process; use std::result; +use std::str; use crate::error::Error; @@ -121,6 +122,8 @@ pub struct ExecCtx<'io> { pub stdout: &'io mut dyn io::Write, /// See `RunCtx::stderr`. pub stderr: &'io mut dyn io::Write, + /// See `RunCtx::path`. + pub path: Option<ffi::OsString>, /// See `RunCtx::admin_pin`. pub admin_pin: Option<ffi::OsString>, /// See `RunCtx::user_pin`. @@ -153,6 +156,7 @@ fn handle_arguments(ctx: &mut RunCtx<'_>, args: Vec<String>) -> Result<()> { model: args.model, stdout: ctx.stdout, stderr: ctx.stderr, + path: ctx.path.take(), admin_pin: ctx.admin_pin.take(), user_pin: ctx.user_pin.take(), new_admin_pin: ctx.new_admin_pin.take(), @@ -180,6 +184,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. @@ -217,6 +223,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), |