diff --git a/CHANGELOG.md b/CHANGELOG.md index ee55be2..e99f63d 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### v0.3.3 +* New printenv command #97 * New env_to_map command #96 * New map_keys command. * New temp_dir command. diff --git a/docs/sdk.md b/docs/sdk.md index 2227635..7363ebc 100644 --- a/docs/sdk.md +++ b/docs/sdk.md @@ -46,6 +46,7 @@ * [std::env::GetVar (get_env)](#std__env__GetVar) * [std::env::IsWindows (is_windows)](#std__env__IsWindows) * [std::env::PrintCurrentDirectory (pwd, print_current_directory)](#std__env__PrintCurrentDirectory) +* [std::env::PrintEnv (print_env, printenv)](#std__env__PrintEnv) * [std::env::SetCurrentDirectory (cd, set_current_dir, set_current_directory)](#std__env__SetCurrentDirectory) * [std::env::SetVar (set_env)](#std__env__SetVar) * [std::env::UName (uname)](#std__env__UName) @@ -1761,6 +1762,52 @@ directory = pwd #### Aliases: pwd, print_current_directory + +## std::env::PrintEnv + +```sh +var = printenv +``` + +Prints and returns all environment variables. + +#### Parameters + +None + +#### Return Value + +All environment variables printout text. + +#### Examples + +```sh +set_env TEST_PRINT_ENV TRUE + +text = printenv + +valid = contains ${text} TEST_PRINT_ENV=TRUE +assert ${valid} +``` + + +#### Source: + +```sh + +scope::print_env::map = env_to_map +scope::print_env::text = map_to_properties ${scope::print_env::map} +release ${scope::print_env::map} + +echo ${scope::print_env::text} +set ${scope::print_env::text} + +``` + + +#### Aliases: +print_env, printenv + ## std::env::SetCurrentDirectory ```sh diff --git a/duckscript_sdk/src/sdk/std/env/mod.rs b/duckscript_sdk/src/sdk/std/env/mod.rs index 9b362ed..cf94434 100755 --- a/duckscript_sdk/src/sdk/std/env/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/mod.rs @@ -8,6 +8,7 @@ mod os_name; mod os_release; mod os_version; mod print_current_directory; +mod print_env; mod set_current_directory; mod set_env; mod uname; @@ -32,6 +33,7 @@ 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(print_env::create(&package)?)?; commands.set(set_current_directory::create(&package))?; commands.set(set_env::create(&package))?; commands.set(uname::create(&package)?)?; diff --git a/duckscript_sdk/src/sdk/std/env/print_env/help.md b/duckscript_sdk/src/sdk/std/env/print_env/help.md new file mode 100644 index 0000000..ab34050 --- /dev/null +++ b/duckscript_sdk/src/sdk/std/env/print_env/help.md @@ -0,0 +1,24 @@ +```sh +var = printenv +``` + +Prints and returns all environment variables. + +#### Parameters + +None + +#### Return Value + +All environment variables printout text. + +#### Examples + +```sh +set_env TEST_PRINT_ENV TRUE + +text = printenv + +valid = contains ${text} TEST_PRINT_ENV=TRUE +assert ${valid} +``` diff --git a/duckscript_sdk/src/sdk/std/env/print_env/mod.rs b/duckscript_sdk/src/sdk/std/env/print_env/mod.rs new file mode 100755 index 0000000..58b45f5 --- /dev/null +++ b/duckscript_sdk/src/sdk/std/env/print_env/mod.rs @@ -0,0 +1,22 @@ +use crate::types::command::create_alias_command; +use crate::utils::pckg; +use duckscript::types::command::Command; +use duckscript::types::error::ScriptError; + +#[cfg(test)] +#[path = "./mod_test.rs"] +mod mod_test; + +pub(crate) fn create(package: &str) -> Result, ScriptError> { + let name = pckg::concat(package, "PrintEnv"); + let command = create_alias_command( + name, + vec!["print_env".to_string(), "printenv".to_string()], + include_str!("help.md").to_string(), + "print_env".to_string(), + include_str!("script.ds").to_string(), + 0, + )?; + + Ok(Box::new(command)) +} diff --git a/duckscript_sdk/src/sdk/std/env/print_env/mod_test.rs b/duckscript_sdk/src/sdk/std/env/print_env/mod_test.rs new file mode 100644 index 0000000..cbc4367 --- /dev/null +++ b/duckscript_sdk/src/sdk/std/env/print_env/mod_test.rs @@ -0,0 +1,7 @@ +use super::*; +use crate::test; + +#[test] +fn common_functions() { + test::test_common_command_functions(create("").unwrap()); +} diff --git a/duckscript_sdk/src/sdk/std/env/print_env/script.ds b/duckscript_sdk/src/sdk/std/env/print_env/script.ds new file mode 100644 index 0000000..54d2855 --- /dev/null +++ b/duckscript_sdk/src/sdk/std/env/print_env/script.ds @@ -0,0 +1,7 @@ + +scope::print_env::map = env_to_map +scope::print_env::text = map_to_properties ${scope::print_env::map} +release ${scope::print_env::map} + +echo ${scope::print_env::text} +set ${scope::print_env::text} diff --git a/test/std/env/print_env_test.ds b/test/std/env/print_env_test.ds new file mode 100644 index 0000000..21f099b --- /dev/null +++ b/test/std/env/print_env_test.ds @@ -0,0 +1,9 @@ + +fn test_print_env + set_env TEST_PRINT_ENV TRUE + + text = printenv + + valid = contains ${text} TEST_PRINT_ENV=TRUE + assert ${valid} +end