From 141e8ab4efeea055b89ef71cfbf5cbded1c38177 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 18 Mar 2026 20:12:02 -0700 Subject: [PATCH] Allow passing arguments to `run()` --- src/env.rs | 4 ++-- src/main.rs | 2 +- src/run.rs | 10 ++++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/env.rs b/src/env.rs index 98117023..d10c9c7c 100644 --- a/src/env.rs +++ b/src/env.rs @@ -9,7 +9,7 @@ pub(crate) struct Env { } impl Env { - pub(crate) fn main() -> Result { + pub(crate) fn main(args: impl Iterator>) -> Result { let dir = env::current_dir().context(error::CurrentDirectoryGet)?; let style = env::var_os("NO_COLOR").is_none() @@ -20,7 +20,7 @@ impl Env { Ok(Self::new( dir, - env::args(), + args, Box::new(io::stdin()), out_stream, err_stream, diff --git a/src/main.rs b/src/main.rs index 9ce15bdd..3b116a71 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ fn main() { - if let Err(code) = imdl::run() { + if let Err(code) = imdl::run(std::env::args()) { std::process::exit(code); } } diff --git a/src/run.rs b/src/run.rs index 1325352d..da0cb09f 100644 --- a/src/run.rs +++ b/src/run.rs @@ -1,3 +1,9 @@ +//! `intermodal` is primarily used as a command-line binary, but does provide a +//! limited public library interface. +//! +//! Please keep in mind that there are no semantic version guarantees for the +//! library interface. It may break or change at any time. + use crate::common::*; /// Entry point into the IMDL binary. @@ -17,8 +23,8 @@ use crate::common::*; /// In case of an error, a nonzero status code is returned. This status code can /// be passed to `std::process::exit`, to exit the process and report its /// failure to the system. -pub fn run() -> Result<(), i32> { - let mut env = match Env::main() { +pub fn run(args: impl Iterator>) -> Result<(), i32> { + let mut env = match Env::main(args) { Ok(env) => env, Err(err) => { eprintln!("{err}");