New os_version, os_release, os_name and uname commands

This commit is contained in:
sagie gur ari 2020-03-07 21:06:32 +00:00
parent 39fd472bdf
commit 94eed136d5
20 changed files with 366 additions and 2 deletions

View file

@ -2,6 +2,10 @@
### v0.2.2
* \[Breaking Change\] uname is now a new command and does not alias os_family command.
* New os_version command.
* New os_release command.
* New os_name command.
* New is_windows command.
* New glob_chmod command.
* New glob_array command #90

View file

@ -40,6 +40,7 @@
* [std::env::PrintCurrentDirectory (pwd, print_current_directory)](#std__env__PrintCurrentDirectory)
* [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)
* [std::env::UnsetVar (unset_env)](#std__env__UnsetVar)
* [std::error::GetLastError (get_last_error)](#std__error__GetLastError)
* [std::error::GetLastErrorLine (get_last_error_line)](#std__error__GetLastErrorLine)
@ -1565,6 +1566,51 @@ set_env HOME /usr/me
#### Aliases:
set_env
<a name="std__env__UName"></a>
## std::env::UName
```sh
var = uname [-a]
```
Acts similar to uname on unix like systems.
#### Parameters
* Optional -a for extended information.
#### Return Value
The OS name and optionally extra information.
#### Examples
```sh
value = uname -a
```
#### Source:
```sh
scope::uname::extended_info = equals -a ${scope::uname::argument::1}
scope::uname::info = os_name
if ${scope::uname::extended_info}
scope::uname::release = os_release
scope::uname::version = os_version
scope::uname::info = set "${scope::uname::info} ${scope::uname::release} ${scope::uname::version}"
end
set ${scope::uname::info}
```
#### Aliases:
uname
<a name="std__env__UnsetVar"></a>
## std::env::UnsetVar
```sh

View file

@ -34,6 +34,7 @@ home = "^0.5"
java-properties = "^1"
meval = "^0.2"
rand = "^0.7"
uname = "^0.1"
walkdir = "^2"
whoami = "^0.7"

View file

@ -3,9 +3,13 @@ mod get_home_dir;
mod get_user_name;
mod is_windows;
mod os_family;
mod os_name;
mod os_release;
mod os_version;
mod print_current_directory;
mod set;
mod set_current_directory;
mod uname;
mod unset;
use crate::utils::pckg;
@ -22,9 +26,13 @@ pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptEr
commands.set(get_user_name::create(PACKAGE))?;
commands.set(is_windows::create(PACKAGE)?)?;
commands.set(os_family::create(PACKAGE))?;
commands.set(os_name::create(PACKAGE))?;
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(uname::create(&package)?)?;
commands.set(unset::create(&package))?;
Ok(())

View file

@ -16,7 +16,7 @@ impl Command for CommandImpl {
}
fn aliases(&self) -> Vec<String> {
vec!["os_family".to_string(), "uname".to_string()]
vec!["os_family".to_string()]
}
fn help(&self) -> String {

View file

@ -0,0 +1,19 @@
```sh
var = os_name
```
Returns the OS name.
#### Parameters
None
#### Return Value
The OS name.
#### Examples
```sh
name = os_name
```

43
duckscript_sdk/src/sdk/std/env/os_name/mod.rs vendored Executable file
View file

@ -0,0 +1,43 @@
use crate::utils::pckg;
use duckscript::types::command::{Command, CommandResult};
use uname::uname;
#[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, "GetOSName")
}
fn aliases(&self) -> Vec<String> {
vec!["os_name".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 {
match uname() {
Ok(info) => CommandResult::Continue(Some(info.sysname)),
Err(error) => CommandResult::Error(error.to_string()),
}
}
}
pub(crate) fn create(package: &str) -> Box<dyn Command> {
Box::new(CommandImpl {
package: package.to_string(),
})
}

View file

@ -0,0 +1,13 @@
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 = os_name", CommandValidation::Ignore);
}

View file

@ -0,0 +1,19 @@
```sh
var = os_release
```
Returns the OS release.
#### Parameters
None
#### Return Value
The OS release.
#### Examples
```sh
release = os_release
```

View file

@ -0,0 +1,43 @@
use crate::utils::pckg;
use duckscript::types::command::{Command, CommandResult};
use uname::uname;
#[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, "GetOSRelease")
}
fn aliases(&self) -> Vec<String> {
vec!["os_release".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 {
match uname() {
Ok(info) => CommandResult::Continue(Some(info.release)),
Err(error) => CommandResult::Error(error.to_string()),
}
}
}
pub(crate) fn create(package: &str) -> Box<dyn Command> {
Box::new(CommandImpl {
package: package.to_string(),
})
}

View 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 = os_release",
CommandValidation::Ignore,
);
}

View file

@ -0,0 +1,19 @@
```sh
var = os_version
```
Returns the OS version.
#### Parameters
None
#### Return Value
The OS version.
#### Examples
```sh
version = os_version
```

View file

@ -0,0 +1,43 @@
use crate::utils::pckg;
use duckscript::types::command::{Command, CommandResult};
use uname::uname;
#[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, "GetOSVersion")
}
fn aliases(&self) -> Vec<String> {
vec!["os_version".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 {
match uname() {
Ok(info) => CommandResult::Continue(Some(info.version)),
Err(error) => CommandResult::Error(error.to_string()),
}
}
}
pub(crate) fn create(package: &str) -> Box<dyn Command> {
Box::new(CommandImpl {
package: package.to_string(),
})
}

View 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 = os_version",
CommandValidation::Ignore,
);
}

View file

@ -0,0 +1,19 @@
```sh
var = uname [-a]
```
Acts similar to uname on unix like systems.
#### Parameters
* Optional -a for extended information.
#### Return Value
The OS name and optionally extra information.
#### Examples
```sh
value = uname -a
```

22
duckscript_sdk/src/sdk/std/env/uname/mod.rs vendored Executable file
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, "UName");
let command = create_alias_command(
name,
vec!["uname".to_string()],
include_str!("help.md").to_string(),
"uname".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,11 @@
scope::uname::extended_info = equals -a ${scope::uname::argument::1}
scope::uname::info = os_name
if ${scope::uname::extended_info}
scope::uname::release = os_release
scope::uname::version = os_version
scope::uname::info = set "${scope::uname::info} ${scope::uname::release} ${scope::uname::version}"
end
set ${scope::uname::info}

14
test/std/env/uname_test.ds vendored Normal file
View file

@ -0,0 +1,14 @@
fn test_uname
name = os_name
info = uname
assert_eq ${name} ${info}
end
fn test_uname_extended
name = os_name
release = os_release
version = os_version
info = uname -a
assert_eq "${name} ${release} ${version}" ${info}
end

View file

@ -20,7 +20,6 @@ fn test_found_all
for path in ${handle}
unix_path = replace ${path} \\ /
echo ${path} ${unix_path}
map_remove ${expected} ${unix_path}
end