mirror of
https://github.com/sagiegurari/duckscript
synced 2024-10-14 03:42:32 +00:00
New printenv command #97
This commit is contained in:
parent
281beaa44a
commit
f2b62e3b96
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
### v0.3.3
|
### v0.3.3
|
||||||
|
|
||||||
|
* New printenv command #97
|
||||||
* New env_to_map command #96
|
* New env_to_map command #96
|
||||||
* New map_keys command.
|
* New map_keys command.
|
||||||
* New temp_dir command.
|
* New temp_dir command.
|
||||||
|
|
47
docs/sdk.md
47
docs/sdk.md
|
@ -46,6 +46,7 @@
|
||||||
* [std::env::GetVar (get_env)](#std__env__GetVar)
|
* [std::env::GetVar (get_env)](#std__env__GetVar)
|
||||||
* [std::env::IsWindows (is_windows)](#std__env__IsWindows)
|
* [std::env::IsWindows (is_windows)](#std__env__IsWindows)
|
||||||
* [std::env::PrintCurrentDirectory (pwd, print_current_directory)](#std__env__PrintCurrentDirectory)
|
* [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::SetCurrentDirectory (cd, set_current_dir, set_current_directory)](#std__env__SetCurrentDirectory)
|
||||||
* [std::env::SetVar (set_env)](#std__env__SetVar)
|
* [std::env::SetVar (set_env)](#std__env__SetVar)
|
||||||
* [std::env::UName (uname)](#std__env__UName)
|
* [std::env::UName (uname)](#std__env__UName)
|
||||||
|
@ -1761,6 +1762,52 @@ directory = pwd
|
||||||
#### Aliases:
|
#### Aliases:
|
||||||
pwd, print_current_directory
|
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>
|
<a name="std__env__SetCurrentDirectory"></a>
|
||||||
## std::env::SetCurrentDirectory
|
## std::env::SetCurrentDirectory
|
||||||
```sh
|
```sh
|
||||||
|
|
2
duckscript_sdk/src/sdk/std/env/mod.rs
vendored
2
duckscript_sdk/src/sdk/std/env/mod.rs
vendored
|
@ -8,6 +8,7 @@ mod os_name;
|
||||||
mod os_release;
|
mod os_release;
|
||||||
mod os_version;
|
mod os_version;
|
||||||
mod print_current_directory;
|
mod print_current_directory;
|
||||||
|
mod print_env;
|
||||||
mod set_current_directory;
|
mod set_current_directory;
|
||||||
mod set_env;
|
mod set_env;
|
||||||
mod uname;
|
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_release::create(&package))?;
|
||||||
commands.set(os_version::create(&package))?;
|
commands.set(os_version::create(&package))?;
|
||||||
commands.set(print_current_directory::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_current_directory::create(&package))?;
|
||||||
commands.set(set_env::create(&package))?;
|
commands.set(set_env::create(&package))?;
|
||||||
commands.set(uname::create(&package)?)?;
|
commands.set(uname::create(&package)?)?;
|
||||||
|
|
24
duckscript_sdk/src/sdk/std/env/print_env/help.md
vendored
Normal file
24
duckscript_sdk/src/sdk/std/env/print_env/help.md
vendored
Normal 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}
|
||||||
|
```
|
22
duckscript_sdk/src/sdk/std/env/print_env/mod.rs
vendored
Executable file
22
duckscript_sdk/src/sdk/std/env/print_env/mod.rs
vendored
Executable 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))
|
||||||
|
}
|
7
duckscript_sdk/src/sdk/std/env/print_env/mod_test.rs
vendored
Normal file
7
duckscript_sdk/src/sdk/std/env/print_env/mod_test.rs
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
use super::*;
|
||||||
|
use crate::test;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn common_functions() {
|
||||||
|
test::test_common_command_functions(create("").unwrap());
|
||||||
|
}
|
7
duckscript_sdk/src/sdk/std/env/print_env/script.ds
vendored
Normal file
7
duckscript_sdk/src/sdk/std/env/print_env/script.ds
vendored
Normal 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
9
test/std/env/print_env_test.ds
vendored
Normal 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
|
Loading…
Reference in a new issue