logicaffeine_system/env.rs
1//! Environment Variable and Argument Access
2//!
3//! Provides access to environment variables and command-line arguments.
4//!
5//! # Platform Support
6//!
7//! - **Native**: Full access to system environment
8//! - **WASM**: Not available (module not compiled for wasm32)
9//!
10//! # Example
11//!
12//! ```
13//! use logicaffeine_system::env;
14//!
15//! // Read environment variable
16//! if let Some(home) = env::get("HOME".to_string()) {
17//! assert!(!home.is_empty());
18//! }
19//!
20//! // Command-line arguments are always available
21//! let args = env::args();
22//! assert!(!args.is_empty());
23//! ```
24
25use std::env as std_env;
26use logicaffeine_data::LogosSeq;
27
28/// Returns the value of an environment variable.
29///
30/// # Arguments
31///
32/// * `key` - The environment variable name
33///
34/// # Returns
35///
36/// `Some(value)` if the variable exists and is valid UTF-8, `None` otherwise.
37///
38/// # Example
39///
40/// ```
41/// use logicaffeine_system::env;
42///
43/// let path = env::get("PATH".to_string());
44/// ```
45pub fn get(key: String) -> Option<String> {
46 std_env::var(&key).ok()
47}
48
49/// Returns command-line arguments as a vector.
50///
51/// The first element is the program name (or path), followed by any
52/// arguments passed to the program.
53///
54/// # Returns
55///
56/// A vector of all command-line arguments.
57///
58/// # Example
59///
60/// ```
61/// use logicaffeine_system::env;
62///
63/// let args = env::args();
64/// assert!(!args.is_empty());
65/// ```
66pub fn args() -> LogosSeq<String> {
67 LogosSeq::from_vec(std_env::args().collect())
68}