zoi_cli/cmd/env.rs
1//! Command for managing environment variables and shell integration.
2
3use anyhow::Result;
4use clap_complete::Shell;
5use colored::Colorize;
6use zoi_project::{config, environment};
7
8/// Runs the 'env' command.
9///
10/// Sets up the environment for a project or exports shell configuration
11/// for environment variables.
12///
13/// # Errors
14///
15/// Returns an error if the project configuration cannot be loaded or if
16/// environment setup/export fails.
17pub fn run(env_alias: Option<&str>, export_shell: Option<Shell>) -> Result<()> {
18 let config = config::load()?;
19 if let Some(shell) = export_shell {
20 environment::export_shell(env_alias, &config, shell)?;
21 } else {
22 environment::setup(env_alias, &config)?;
23 println!("\n{}", "Environment setup complete.".green());
24 }
25 Ok(())
26}