From 1e72ff63f845041971fc015a3dee1f7f92434fa4 Mon Sep 17 00:00:00 2001 From: Ahurac Date: Fri, 19 Apr 2024 11:32:47 +0200 Subject: [PATCH] builtins : ajout export --- src/command/builtins.rs | 14 ++++++++++++++ src/command/mod.rs | 1 + src/variables.rs | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/command/builtins.rs b/src/command/builtins.rs index 522e63a..c90687d 100644 --- a/src/command/builtins.rs +++ b/src/command/builtins.rs @@ -65,3 +65,17 @@ pub(super) fn unset(args: &Vec, variables: &mut Variables, exit_code: &m exit_code.set_success(); } + +pub(super) fn export(args: &Vec, 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(); +} diff --git a/src/command/mod.rs b/src/command/mod.rs index 59b60d0..1f28de0 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -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, }; diff --git a/src/variables.rs b/src/variables.rs index 17dced7..716e994 100644 --- a/src/variables.rs +++ b/src/variables.rs @@ -1,5 +1,5 @@ use std::collections::HashMap; -use std::env::{self, args}; +use std::env; pub struct Variables { variables: HashMap,