| 3991 | } |
| 3992 | |
| 3993 | pub fn parse_env_pairs(items: &[String]) -> Result<HashMap<String, String>> { |
| 3994 | let map = parse_key_value_pairs(items, "--env")?; |
| 3995 | for key in map.keys() { |
| 3996 | if !is_valid_env_name(key) { |
| 3997 | return Err(miette::miette!( |
| 3998 | "--env key must match [A-Za-z_][A-Za-z0-9_]*; got '{key}'" |
| 3999 | )); |
| 4000 | } |
| 4001 | if key.starts_with("OPENSHELL_") { |
| 4002 | return Err(miette::miette!( |
| 4003 | "--env keys starting with OPENSHELL_ are reserved; got '{key}'" |
| 4004 | )); |
| 4005 | } |
| 4006 | } |
| 4007 | Ok(map) |
| 4008 | } |
| 4009 | |
| 4010 | fn is_valid_env_name(key: &str) -> bool { |
| 4011 | let mut bytes = key.bytes(); |