use crate::poem::Verse; use std::collections::BTreeMap; use std::env; /// export /// /// The builtin `export` command. Used to set global environment variables for /// the current instance of the shell. /// /// # Aliases /// * export /// * set /// /// # Shell Examples /// ```sh /// export FOO=BAR /// ``` pub fn incant(verse: &Verse) -> i32 { match verse.clause() { Some(clause) => { for stanza in clause { let (key, val) = match stanza.split_once("=") { Some((key, val)) => (key, val), None => continue, }; env::set_var(key, val); } } None => { let sorted: BTreeMap<_, _> = env::vars().into_iter().collect(); for (key, val) in sorted { println!("{}={}", key, val); } } } 0 } /// unset /// /// The builtin `unset` command. Used to remove global environment variables /// from the current instance of the shell, since `export` may be called with /// an empty string as the value. /// /// # Shell Examples /// ```sh /// unset FOO /// ``` pub fn unincant(verse: &Verse) -> i32 { match verse.clause() { Some(clause) => { for stanza in clause { env::remove_var(stanza); } } None => { eprintln!("unset: not enough arguments"); return 1; } } 0 }