New printenv command #97

This commit is contained in:
sagie gur ari 2020-04-14 13:51:24 +00:00
parent 281beaa44a
commit f2b62e3b96
8 changed files with 119 additions and 0 deletions

View File

@ -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.

View File

@ -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
<a name="std__env__PrintEnv"></a>
## 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
<a name="std__env__SetCurrentDirectory"></a>
## std::env::SetCurrentDirectory
```sh

View File

@ -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)?)?;

View File

@ -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}
```

View File

@ -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<Box<dyn Command>, 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))
}

View File

@ -0,0 +1,7 @@
use super::*;
use crate::test;
#[test]
fn common_functions() {
test::test_common_command_functions(create("").unwrap());
}

View File

@ -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}

9
test/std/env/print_env_test.ds vendored Normal file
View File

@ -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