diff --git a/CHANGELOG.md b/CHANGELOG.md
index f6450b0..ee55be2 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
### v0.3.3
+* New env_to_map command #96
* New map_keys command.
* New temp_dir command.
* Runtime - Use default trait.
diff --git a/docs/sdk.md b/docs/sdk.md
index 491a98a..2227635 100644
--- a/docs/sdk.md
+++ b/docs/sdk.md
@@ -36,6 +36,7 @@
* [std::debug::DumpInstructions (dump_instructions)](#std__debug__DumpInstructions)
* [std::debug::DumpState (dump_state)](#std__debug__DumpState)
* [std::debug::DumpVariables (dump_variables)](#std__debug__DumpVariables)
+* [std::env::EnvToMap (env_to_map)](#std__env__EnvToMap)
* [std::env::GetHomeDirectory (get_home_dir)](#std__env__GetHomeDirectory)
* [std::env::GetOSFamily (os_family)](#std__env__GetOSFamily)
* [std::env::GetOSName (os_name)](#std__env__GetOSName)
@@ -1475,6 +1476,39 @@ assert found
#### Aliases:
dump_variables
+
+## std::env::EnvToMap
+```sh
+handle = env_to_map
+```
+
+Converts all environment variables to a map and returns the map handle.
+
+#### Parameters
+
+None
+
+#### Return Value
+
+The map handle.
+
+#### Examples
+
+```sh
+set_env env_to_map_test test_value
+
+handle = env_to_map
+
+value = map_get ${handle} env_to_map_test
+assert_eq ${value} test_value
+
+release ${handle}
+```
+
+
+#### Aliases:
+env_to_map
+
## std::env::GetHomeDirectory
```sh
diff --git a/duckscript_sdk/src/sdk/std/env/env_to_map/help.md b/duckscript_sdk/src/sdk/std/env/env_to_map/help.md
new file mode 100644
index 0000000..d4f7ec5
--- /dev/null
+++ b/duckscript_sdk/src/sdk/std/env/env_to_map/help.md
@@ -0,0 +1,26 @@
+```sh
+handle = env_to_map
+```
+
+Converts all environment variables to a map and returns the map handle.
+
+#### Parameters
+
+None
+
+#### Return Value
+
+The map handle.
+
+#### Examples
+
+```sh
+set_env env_to_map_test test_value
+
+handle = env_to_map
+
+value = map_get ${handle} env_to_map_test
+assert_eq ${value} test_value
+
+release ${handle}
+```
diff --git a/duckscript_sdk/src/sdk/std/env/env_to_map/mod.rs b/duckscript_sdk/src/sdk/std/env/env_to_map/mod.rs
new file mode 100755
index 0000000..73078eb
--- /dev/null
+++ b/duckscript_sdk/src/sdk/std/env/env_to_map/mod.rs
@@ -0,0 +1,66 @@
+use crate::utils::pckg;
+use crate::utils::state::put_handle;
+use duckscript::types::command::{Command, CommandResult, Commands};
+use duckscript::types::instruction::Instruction;
+use duckscript::types::runtime::StateValue;
+use std::collections::HashMap;
+use std::env;
+
+#[cfg(test)]
+#[path = "./mod_test.rs"]
+mod mod_test;
+
+#[derive(Clone)]
+pub(crate) struct CommandImpl {
+ package: String,
+}
+
+impl Command for CommandImpl {
+ fn name(&self) -> String {
+ pckg::concat(&self.package, "EnvToMap")
+ }
+
+ fn aliases(&self) -> Vec {
+ vec!["env_to_map".to_string()]
+ }
+
+ fn help(&self) -> String {
+ include_str!("help.md").to_string()
+ }
+
+ fn clone_and_box(&self) -> Box {
+ Box::new((*self).clone())
+ }
+
+ fn requires_context(&self) -> bool {
+ true
+ }
+
+ fn run_with_context(
+ &self,
+ _arguments: Vec,
+ state: &mut HashMap,
+ _variables: &mut HashMap,
+ _output_variable: Option,
+ _instructions: &Vec,
+ _commands: &mut Commands,
+ _line: usize,
+ ) -> CommandResult {
+ let all_vars = env::vars();
+ let mut map = HashMap::new();
+
+ for (var_key, var_value) in all_vars {
+ map.insert(var_key, StateValue::String(var_value.to_string()));
+ }
+
+ let key = put_handle(state, StateValue::SubState(map));
+
+ CommandResult::Continue(Some(key))
+ }
+}
+
+pub(crate) fn create(package: &str) -> Box {
+ Box::new(CommandImpl {
+ package: package.to_string(),
+ })
+}
diff --git a/duckscript_sdk/src/sdk/std/env/env_to_map/mod_test.rs b/duckscript_sdk/src/sdk/std/env/env_to_map/mod_test.rs
new file mode 100644
index 0000000..59d2dfb
--- /dev/null
+++ b/duckscript_sdk/src/sdk/std/env/env_to_map/mod_test.rs
@@ -0,0 +1,17 @@
+use super::*;
+use crate::test;
+use crate::test::CommandValidation;
+
+#[test]
+fn common_functions() {
+ test::test_common_command_functions(create(""));
+}
+
+#[test]
+fn run_valid() {
+ test::run_script_and_validate(
+ vec![create("")],
+ r#"out = env_to_map"#,
+ CommandValidation::Contains("out".to_string(), "handle:".to_string()),
+ );
+}
diff --git a/duckscript_sdk/src/sdk/std/env/get/help.md b/duckscript_sdk/src/sdk/std/env/get_env/help.md
similarity index 100%
rename from duckscript_sdk/src/sdk/std/env/get/help.md
rename to duckscript_sdk/src/sdk/std/env/get_env/help.md
diff --git a/duckscript_sdk/src/sdk/std/env/get/mod.rs b/duckscript_sdk/src/sdk/std/env/get_env/mod.rs
similarity index 100%
rename from duckscript_sdk/src/sdk/std/env/get/mod.rs
rename to duckscript_sdk/src/sdk/std/env/get_env/mod.rs
diff --git a/duckscript_sdk/src/sdk/std/env/get/mod_test.rs b/duckscript_sdk/src/sdk/std/env/get_env/mod_test.rs
similarity index 100%
rename from duckscript_sdk/src/sdk/std/env/get/mod_test.rs
rename to duckscript_sdk/src/sdk/std/env/get_env/mod_test.rs
diff --git a/duckscript_sdk/src/sdk/std/env/mod.rs b/duckscript_sdk/src/sdk/std/env/mod.rs
index db08056..9b362ed 100755
--- a/duckscript_sdk/src/sdk/std/env/mod.rs
+++ b/duckscript_sdk/src/sdk/std/env/mod.rs
@@ -1,4 +1,5 @@
-mod get;
+mod env_to_map;
+mod get_env;
mod get_home_dir;
mod get_user_name;
mod is_windows;
@@ -7,8 +8,8 @@ mod os_name;
mod os_release;
mod os_version;
mod print_current_directory;
-mod set;
mod set_current_directory;
+mod set_env;
mod uname;
mod unset;
@@ -21,7 +22,8 @@ static PACKAGE: &str = "env";
pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptError> {
let package = pckg::concat(parent, PACKAGE);
- commands.set(get::create(&package))?;
+ commands.set(env_to_map::create(&package))?;
+ commands.set(get_env::create(&package))?;
commands.set(get_home_dir::create(&package))?;
commands.set(get_user_name::create(&package))?;
commands.set(is_windows::create(&package)?)?;
@@ -30,8 +32,8 @@ pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptEr
commands.set(os_release::create(&package))?;
commands.set(os_version::create(&package))?;
commands.set(print_current_directory::create(&package))?;
- commands.set(set::create(&package))?;
commands.set(set_current_directory::create(&package))?;
+ commands.set(set_env::create(&package))?;
commands.set(uname::create(&package)?)?;
commands.set(unset::create(&package))?;
diff --git a/duckscript_sdk/src/sdk/std/env/set/help.md b/duckscript_sdk/src/sdk/std/env/set_env/help.md
similarity index 100%
rename from duckscript_sdk/src/sdk/std/env/set/help.md
rename to duckscript_sdk/src/sdk/std/env/set_env/help.md
diff --git a/duckscript_sdk/src/sdk/std/env/set/mod.rs b/duckscript_sdk/src/sdk/std/env/set_env/mod.rs
similarity index 100%
rename from duckscript_sdk/src/sdk/std/env/set/mod.rs
rename to duckscript_sdk/src/sdk/std/env/set_env/mod.rs
diff --git a/duckscript_sdk/src/sdk/std/env/set/mod_test.rs b/duckscript_sdk/src/sdk/std/env/set_env/mod_test.rs
similarity index 100%
rename from duckscript_sdk/src/sdk/std/env/set/mod_test.rs
rename to duckscript_sdk/src/sdk/std/env/set_env/mod_test.rs
diff --git a/test/std/env/env_to_map_test.ds b/test/std/env/env_to_map_test.ds
new file mode 100644
index 0000000..1aceb03
--- /dev/null
+++ b/test/std/env/env_to_map_test.ds
@@ -0,0 +1,15 @@
+
+fn test_env_to_map
+ set_env env_to_map_test1 test_value1
+
+ handle = env_to_map
+
+ set_env env_to_map_test2 test_value2
+
+ value = map_get ${handle} env_to_map_test1
+ assert_eq ${value} test_value1
+ value = map_get ${handle} env_to_map_test2
+ assert_false ${value}
+
+ release ${handle}
+end