31 lines
657 B
Rust
31 lines
657 B
Rust
use std::{
|
|
env,
|
|
fs::write
|
|
};
|
|
|
|
mod error;
|
|
|
|
fn main() {
|
|
// try to get share file variable
|
|
if let Ok(file) = env::var("ENV_SHARE_FILE") {
|
|
if let Ok(var_string) = env::var("ENV_SHARE_VARS") {
|
|
// build output
|
|
let mut output = String::new();
|
|
let vars = var_string.split(':');
|
|
for var in vars {
|
|
let value = env::var(var).unwrap_or(String::new());
|
|
if value.is_empty() { continue; }
|
|
|
|
output += &format!("{var} = {value}\n");
|
|
}
|
|
|
|
// write to file
|
|
let result = write(&file, output);
|
|
match result {
|
|
Err(_) => error::write_fail(&file),
|
|
_ => { }
|
|
}
|
|
} else { error::vars_unset(); }
|
|
} else { error::file_unset(); }
|
|
}
|
|
|