pub struct Env { /* private fields */ }Expand description
Environment variables and runtime dependencies used by Cursus.
Populated from the process environment at the binary boundary and threaded
into the library so that internal functions never read std::env directly.
Carries the CommandRunner, Filesystem, Git, and optional
CodeForgeClient so that all I/O can be intercepted or replaced.
Implementations§
Source§impl Env
impl Env
Sourcepub fn new(
runner: Arc<dyn CommandRunner>,
filesystem: Arc<dyn Filesystem>,
git: Arc<dyn Git>,
) -> Self
pub fn new( runner: Arc<dyn CommandRunner>, filesystem: Arc<dyn Filesystem>, git: Arc<dyn Git>, ) -> Self
Creates an Env with the given command runner, filesystem, and git implementation.
Use the builder methods (with_editor,
with_code_forge_client) to add optional configuration.
Sourcepub fn with_oidc_environment(self, oidc_environment: bool) -> Self
pub fn with_oidc_environment(self, oidc_environment: bool) -> Self
Sets whether an OIDC-capable CI environment is detected.
Sourcepub fn with_node_auth_token_present(self, present: bool) -> Self
pub fn with_node_auth_token_present(self, present: bool) -> Self
Sets whether NODE_AUTH_TOKEN is present in the environment.
Sourcepub fn with_cargo_registry_token_present(self, present: bool) -> Self
pub fn with_cargo_registry_token_present(self, present: bool) -> Self
Sets whether CARGO_REGISTRY_TOKEN is present in the environment.
Sourcepub fn with_editor(self, editor: String) -> Self
pub fn with_editor(self, editor: String) -> Self
Sets the editor to open changeset files with.
Sourcepub fn with_code_forge_client(self, client: Arc<dyn CodeForgeClient>) -> Self
pub fn with_code_forge_client(self, client: Arc<dyn CodeForgeClient>) -> Self
Sets the code forge client for API operations.
Sourcepub fn with_editor_opt(self, editor: Option<String>) -> Self
pub fn with_editor_opt(self, editor: Option<String>) -> Self
Sets the editor from an Option, overwriting any previously set value.
Passing None clears a previously set editor.
Sourcepub fn with_code_forge_client_result(
self,
client: Result<Arc<dyn CodeForgeClient>, String>,
) -> Self
pub fn with_code_forge_client_result( self, client: Result<Arc<dyn CodeForgeClient>, String>, ) -> Self
Sets the code forge client from a Result, overwriting any previously set value.
Passing Err(reason) records why the client is unavailable.
Sourcepub fn with_locale(self, locale: String) -> Self
pub fn with_locale(self, locale: String) -> Self
Sets the locale for all user-visible messages.
The locale string should be a BCP 47 tag (e.g. "en", "en-US",
"pt-BR"). Defaults to "en".
Sourcepub fn with_dry_run_runner(self) -> Self
pub fn with_dry_run_runner(self) -> Self
Wraps the current command runner in a DryRunCommandRunner that suppresses
all mutating operations.
This is called automatically by [crate::run_with] when --dry-run is set,
so all code paths (both the binary and integration tests) benefit from the
dry-run protection without any manual composition.
Sourcepub fn apply_global(self, global: &GlobalArgs) -> Self
pub fn apply_global(self, global: &GlobalArgs) -> Self
Applies global CLI flags to this environment.
Currently handles --dry-run by wrapping the command runner in a
DryRunCommandRunner.
Sourcepub fn fs(&self) -> &dyn Filesystem
pub fn fs(&self) -> &dyn Filesystem
Returns the filesystem implementation.
Sourcepub fn runner(&self) -> Arc<dyn CommandRunner> ⓘ
pub fn runner(&self) -> Arc<dyn CommandRunner> ⓘ
Returns the command runner.
Sourcepub async fn run_editor_on(&self, path: &Path, cwd: &Path) -> Result<()>
pub async fn run_editor_on(&self, path: &Path, cwd: &Path) -> Result<()>
Opens the user’s editor on the specified file.
Resolves the editor from self.editor(), falling back to the first
available platform-appropriate editor: notepad on Windows, or the first
of nano, vim, vi, emacs found on Unix. The working directory for
the editor process is cwd.
The editor string is passed to run_shell_interactive
so that multi-word values such as code --wait are interpreted correctly by the
shell. The file path is quoted via [crate::shell::shell_quote] to prevent word
splitting on filenames that contain spaces or other special characters.
§Errors
Returns an error if no editor is found or the editor process fails.
Sourcepub async fn run(
&self,
program: &str,
args: &[&str],
cwd: &Path,
) -> Result<Output>
pub async fn run( &self, program: &str, args: &[&str], cwd: &Path, ) -> Result<Output>
Runs a program with the given arguments in the specified directory.
Delegates to the underlying CommandRunner. Read-only.
Sourcepub async fn run_mut(
&self,
program: &str,
args: &[&str],
cwd: &Path,
) -> Result<Output>
pub async fn run_mut( &self, program: &str, args: &[&str], cwd: &Path, ) -> Result<Output>
Runs a mutating program with the given arguments in the specified directory.
Delegates to the underlying CommandRunner. Skipped by DryRunCommandRunner.
Sourcepub async fn run_interactive(
&self,
program: &str,
args: &[&str],
cwd: &Path,
) -> Result<ExitStatus>
pub async fn run_interactive( &self, program: &str, args: &[&str], cwd: &Path, ) -> Result<ExitStatus>
Runs a program with inherited stdin/stdout/stderr for interactive use.
Delegates to the underlying CommandRunner. Skipped by DryRunCommandRunner.
Sourcepub async fn run_shell_interactive(
&self,
command: &str,
cwd: &Path,
) -> Result<ExitStatus>
pub async fn run_shell_interactive( &self, command: &str, cwd: &Path, ) -> Result<ExitStatus>
Runs a shell command via the platform shell with inherited stdin/stdout/stderr.
Delegates to the underlying CommandRunner. Skipped by DryRunCommandRunner.
Sourcepub async fn run_streaming(
&self,
command: &str,
cwd: &Path,
) -> Result<ExitStatus>
pub async fn run_streaming( &self, command: &str, cwd: &Path, ) -> Result<ExitStatus>
Runs a shell command via the platform shell, streaming output live to the terminal.
Delegates to the underlying CommandRunner. Skipped by DryRunCommandRunner.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Env
impl !RefUnwindSafe for Env
impl Send for Env
impl Sync for Env
impl Unpin for Env
impl UnsafeUnpin for Env
impl !UnwindSafe for Env
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more