builtins : ajout export

This commit is contained in:
Ahurac 2024-04-19 11:32:47 +02:00
parent c7e9b19ac1
commit 1e72ff63f8
3 changed files with 16 additions and 1 deletions

View file

@ -65,3 +65,17 @@ pub(super) fn unset(args: &Vec<String>, variables: &mut Variables, exit_code: &m
exit_code.set_success();
}
pub(super) fn export(args: &Vec<String>, variables: &mut Variables, exit_code: &mut ExitCode) {
for variable in args.iter() {
let assignation: Vec<&str> = variable.split('=').collect();
if assignation.len() == 2 {
variables.set(&assignation[0], &assignation[1]);
}
variables.export(&assignation[0]);
}
exit_code.set_success();
}

View file

@ -30,6 +30,7 @@ impl Builtin {
"cd" => Some(builtins::cd),
"exit" => Some(builtins::exit),
"unset" => Some(builtins::unset),
"export" => Some(builtins::export),
":" => Some(builtins::colon),
_ => None,
};

View file

@ -1,5 +1,5 @@
use std::collections::HashMap;
use std::env::{self, args};
use std::env;
pub struct Variables {
variables: HashMap<String, String>,