mirror of
https://github.com/sagiegurari/duckscript
synced 2024-10-14 11:53:05 +00:00
New cpu_count command
This commit is contained in:
parent
f2b62e3b96
commit
a32c4428b2
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
### v0.3.3
|
### v0.3.3
|
||||||
|
|
||||||
|
* New cpu_count command.
|
||||||
* New printenv command #97
|
* New printenv command #97
|
||||||
* New env_to_map command #96
|
* New env_to_map command #96
|
||||||
* New map_keys command.
|
* New map_keys command.
|
||||||
|
|
27
docs/sdk.md
27
docs/sdk.md
|
@ -37,6 +37,7 @@
|
||||||
* [std::debug::DumpState (dump_state)](#std__debug__DumpState)
|
* [std::debug::DumpState (dump_state)](#std__debug__DumpState)
|
||||||
* [std::debug::DumpVariables (dump_variables)](#std__debug__DumpVariables)
|
* [std::debug::DumpVariables (dump_variables)](#std__debug__DumpVariables)
|
||||||
* [std::env::EnvToMap (env_to_map)](#std__env__EnvToMap)
|
* [std::env::EnvToMap (env_to_map)](#std__env__EnvToMap)
|
||||||
|
* [std::env::GetCpuCount (cpu_count, get_cpu_count)](#std__env__GetCpuCount)
|
||||||
* [std::env::GetHomeDirectory (get_home_dir)](#std__env__GetHomeDirectory)
|
* [std::env::GetHomeDirectory (get_home_dir)](#std__env__GetHomeDirectory)
|
||||||
* [std::env::GetOSFamily (os_family)](#std__env__GetOSFamily)
|
* [std::env::GetOSFamily (os_family)](#std__env__GetOSFamily)
|
||||||
* [std::env::GetOSName (os_name)](#std__env__GetOSName)
|
* [std::env::GetOSName (os_name)](#std__env__GetOSName)
|
||||||
|
@ -1510,6 +1511,32 @@ release ${handle}
|
||||||
#### Aliases:
|
#### Aliases:
|
||||||
env_to_map
|
env_to_map
|
||||||
|
|
||||||
|
<a name="std__env__GetCpuCount"></a>
|
||||||
|
## std::env::GetCpuCount
|
||||||
|
```sh
|
||||||
|
var = cpu_count
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns the number of CPUs.
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
#### Return Value
|
||||||
|
|
||||||
|
The CPU count.
|
||||||
|
|
||||||
|
#### Examples
|
||||||
|
|
||||||
|
```sh
|
||||||
|
count = cpu_count
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### Aliases:
|
||||||
|
cpu_count, get_cpu_count
|
||||||
|
|
||||||
<a name="std__env__GetHomeDirectory"></a>
|
<a name="std__env__GetHomeDirectory"></a>
|
||||||
## std::env::GetHomeDirectory
|
## std::env::GetHomeDirectory
|
||||||
```sh
|
```sh
|
||||||
|
|
|
@ -33,6 +33,7 @@ glob = "^0.3"
|
||||||
home = "^0.5"
|
home = "^0.5"
|
||||||
java-properties = "^1"
|
java-properties = "^1"
|
||||||
meval = "^0.2"
|
meval = "^0.2"
|
||||||
|
num_cpus = "^1"
|
||||||
rand = "^0.7"
|
rand = "^0.7"
|
||||||
walkdir = "^2"
|
walkdir = "^2"
|
||||||
whoami = "^0.8"
|
whoami = "^0.8"
|
||||||
|
|
19
duckscript_sdk/src/sdk/std/env/cpu_count/help.md
vendored
Normal file
19
duckscript_sdk/src/sdk/std/env/cpu_count/help.md
vendored
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
```sh
|
||||||
|
var = cpu_count
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns the number of CPUs.
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
#### Return Value
|
||||||
|
|
||||||
|
The CPU count.
|
||||||
|
|
||||||
|
#### Examples
|
||||||
|
|
||||||
|
```sh
|
||||||
|
count = cpu_count
|
||||||
|
```
|
42
duckscript_sdk/src/sdk/std/env/cpu_count/mod.rs
vendored
Executable file
42
duckscript_sdk/src/sdk/std/env/cpu_count/mod.rs
vendored
Executable file
|
@ -0,0 +1,42 @@
|
||||||
|
use crate::utils::pckg;
|
||||||
|
use duckscript::types::command::{Command, CommandResult};
|
||||||
|
use num_cpus;
|
||||||
|
|
||||||
|
#[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, "GetCpuCount")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn aliases(&self) -> Vec<String> {
|
||||||
|
vec!["cpu_count".to_string(), "get_cpu_count".to_string()]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn help(&self) -> String {
|
||||||
|
include_str!("help.md").to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clone_and_box(&self) -> Box<dyn Command> {
|
||||||
|
Box::new((*self).clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(&self, _arguments: Vec<String>) -> CommandResult {
|
||||||
|
let num = num_cpus::get();
|
||||||
|
|
||||||
|
CommandResult::Continue(Some(num.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn create(package: &str) -> Box<dyn Command> {
|
||||||
|
Box::new(CommandImpl {
|
||||||
|
package: package.to_string(),
|
||||||
|
})
|
||||||
|
}
|
17
duckscript_sdk/src/sdk/std/env/cpu_count/mod_test.rs
vendored
Normal file
17
duckscript_sdk/src/sdk/std/env/cpu_count/mod_test.rs
vendored
Normal file
|
@ -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("")],
|
||||||
|
"out = cpu_count",
|
||||||
|
CommandValidation::Ignore,
|
||||||
|
);
|
||||||
|
}
|
2
duckscript_sdk/src/sdk/std/env/mod.rs
vendored
2
duckscript_sdk/src/sdk/std/env/mod.rs
vendored
|
@ -1,3 +1,4 @@
|
||||||
|
mod cpu_count;
|
||||||
mod env_to_map;
|
mod env_to_map;
|
||||||
mod get_env;
|
mod get_env;
|
||||||
mod get_home_dir;
|
mod get_home_dir;
|
||||||
|
@ -23,6 +24,7 @@ static PACKAGE: &str = "env";
|
||||||
pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptError> {
|
pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptError> {
|
||||||
let package = pckg::concat(parent, PACKAGE);
|
let package = pckg::concat(parent, PACKAGE);
|
||||||
|
|
||||||
|
commands.set(cpu_count::create(&package))?;
|
||||||
commands.set(env_to_map::create(&package))?;
|
commands.set(env_to_map::create(&package))?;
|
||||||
commands.set(get_env::create(&package))?;
|
commands.set(get_env::create(&package))?;
|
||||||
commands.set(get_home_dir::create(&package))?;
|
commands.set(get_home_dir::create(&package))?;
|
||||||
|
|
7
test/std/env/cpu_count_test.ds
vendored
Normal file
7
test/std/env/cpu_count_test.ds
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
|
||||||
|
fn test_cpu_count
|
||||||
|
value = cpu_count
|
||||||
|
valid = greater_than ${value} 0
|
||||||
|
|
||||||
|
assert ${valid}
|
||||||
|
end
|
Loading…
Reference in a new issue