builtins : ajout export
This commit is contained in:
parent
c7e9b19ac1
commit
1e72ff63f8
3 changed files with 16 additions and 1 deletions
|
@ -65,3 +65,17 @@ pub(super) fn unset(args: &Vec<String>, variables: &mut Variables, exit_code: &m
|
||||||
|
|
||||||
exit_code.set_success();
|
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();
|
||||||
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ impl Builtin {
|
||||||
"cd" => Some(builtins::cd),
|
"cd" => Some(builtins::cd),
|
||||||
"exit" => Some(builtins::exit),
|
"exit" => Some(builtins::exit),
|
||||||
"unset" => Some(builtins::unset),
|
"unset" => Some(builtins::unset),
|
||||||
|
"export" => Some(builtins::export),
|
||||||
":" => Some(builtins::colon),
|
":" => Some(builtins::colon),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::env::{self, args};
|
use std::env;
|
||||||
|
|
||||||
pub struct Variables {
|
pub struct Variables {
|
||||||
variables: HashMap<String, String>,
|
variables: HashMap<String, String>,
|
||||||
|
|
Loading…
Reference in a new issue