From 94eed136d5d08357b6c59c9a8e22a083c4941075 Mon Sep 17 00:00:00 2001 From: sagie gur ari Date: Sat, 7 Mar 2020 21:06:32 +0000 Subject: [PATCH] New os_version, os_release, os_name and uname commands --- CHANGELOG.md | 4 ++ docs/sdk.md | 46 +++++++++++++++++++ duckscript_sdk/Cargo.toml | 1 + duckscript_sdk/src/sdk/std/env/mod.rs | 8 ++++ .../src/sdk/std/env/os_family/mod.rs | 2 +- .../src/sdk/std/env/os_name/help.md | 19 ++++++++ duckscript_sdk/src/sdk/std/env/os_name/mod.rs | 43 +++++++++++++++++ .../src/sdk/std/env/os_name/mod_test.rs | 13 ++++++ .../src/sdk/std/env/os_release/help.md | 19 ++++++++ .../src/sdk/std/env/os_release/mod.rs | 43 +++++++++++++++++ .../src/sdk/std/env/os_release/mod_test.rs | 17 +++++++ .../src/sdk/std/env/os_version/help.md | 19 ++++++++ .../src/sdk/std/env/os_version/mod.rs | 43 +++++++++++++++++ .../src/sdk/std/env/os_version/mod_test.rs | 17 +++++++ duckscript_sdk/src/sdk/std/env/uname/help.md | 19 ++++++++ duckscript_sdk/src/sdk/std/env/uname/mod.rs | 22 +++++++++ .../src/sdk/std/env/uname/mod_test.rs | 7 +++ .../src/sdk/std/env/uname/script.ds | 11 +++++ test/std/env/uname_test.ds | 14 ++++++ test/std/fs/glob_array_test.ds | 1 - 20 files changed, 366 insertions(+), 2 deletions(-) create mode 100644 duckscript_sdk/src/sdk/std/env/os_name/help.md create mode 100755 duckscript_sdk/src/sdk/std/env/os_name/mod.rs create mode 100644 duckscript_sdk/src/sdk/std/env/os_name/mod_test.rs create mode 100644 duckscript_sdk/src/sdk/std/env/os_release/help.md create mode 100755 duckscript_sdk/src/sdk/std/env/os_release/mod.rs create mode 100644 duckscript_sdk/src/sdk/std/env/os_release/mod_test.rs create mode 100644 duckscript_sdk/src/sdk/std/env/os_version/help.md create mode 100755 duckscript_sdk/src/sdk/std/env/os_version/mod.rs create mode 100644 duckscript_sdk/src/sdk/std/env/os_version/mod_test.rs create mode 100644 duckscript_sdk/src/sdk/std/env/uname/help.md create mode 100755 duckscript_sdk/src/sdk/std/env/uname/mod.rs create mode 100644 duckscript_sdk/src/sdk/std/env/uname/mod_test.rs create mode 100644 duckscript_sdk/src/sdk/std/env/uname/script.ds create mode 100644 test/std/env/uname_test.ds diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f098be..81e7821 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/sdk.md b/docs/sdk.md index 0e43670..fcdb382 100644 --- a/docs/sdk.md +++ b/docs/sdk.md @@ -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 + +## 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 + ## std::env::UnsetVar ```sh diff --git a/duckscript_sdk/Cargo.toml b/duckscript_sdk/Cargo.toml index 4c266f3..1203794 100644 --- a/duckscript_sdk/Cargo.toml +++ b/duckscript_sdk/Cargo.toml @@ -34,6 +34,7 @@ home = "^0.5" java-properties = "^1" meval = "^0.2" rand = "^0.7" +uname = "^0.1" walkdir = "^2" whoami = "^0.7" diff --git a/duckscript_sdk/src/sdk/std/env/mod.rs b/duckscript_sdk/src/sdk/std/env/mod.rs index 943f5bb..e2dfe06 100755 --- a/duckscript_sdk/src/sdk/std/env/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/mod.rs @@ -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(()) diff --git a/duckscript_sdk/src/sdk/std/env/os_family/mod.rs b/duckscript_sdk/src/sdk/std/env/os_family/mod.rs index 8f52ba7..f2a971a 100755 --- a/duckscript_sdk/src/sdk/std/env/os_family/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/os_family/mod.rs @@ -16,7 +16,7 @@ impl Command for CommandImpl { } fn aliases(&self) -> Vec { - vec!["os_family".to_string(), "uname".to_string()] + vec!["os_family".to_string()] } fn help(&self) -> String { diff --git a/duckscript_sdk/src/sdk/std/env/os_name/help.md b/duckscript_sdk/src/sdk/std/env/os_name/help.md new file mode 100644 index 0000000..e481fd3 --- /dev/null +++ b/duckscript_sdk/src/sdk/std/env/os_name/help.md @@ -0,0 +1,19 @@ +```sh +var = os_name +``` + +Returns the OS name. + +#### Parameters + +None + +#### Return Value + +The OS name. + +#### Examples + +```sh +name = os_name +``` diff --git a/duckscript_sdk/src/sdk/std/env/os_name/mod.rs b/duckscript_sdk/src/sdk/std/env/os_name/mod.rs new file mode 100755 index 0000000..dc07777 --- /dev/null +++ b/duckscript_sdk/src/sdk/std/env/os_name/mod.rs @@ -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 { + vec!["os_name".to_string()] + } + + fn help(&self) -> String { + include_str!("help.md").to_string() + } + + fn clone_and_box(&self) -> Box { + Box::new((*self).clone()) + } + + fn run(&self, _arguments: Vec) -> CommandResult { + match uname() { + Ok(info) => CommandResult::Continue(Some(info.sysname)), + Err(error) => CommandResult::Error(error.to_string()), + } + } +} + +pub(crate) fn create(package: &str) -> Box { + Box::new(CommandImpl { + package: package.to_string(), + }) +} diff --git a/duckscript_sdk/src/sdk/std/env/os_name/mod_test.rs b/duckscript_sdk/src/sdk/std/env/os_name/mod_test.rs new file mode 100644 index 0000000..eddb740 --- /dev/null +++ b/duckscript_sdk/src/sdk/std/env/os_name/mod_test.rs @@ -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); +} diff --git a/duckscript_sdk/src/sdk/std/env/os_release/help.md b/duckscript_sdk/src/sdk/std/env/os_release/help.md new file mode 100644 index 0000000..9d3063c --- /dev/null +++ b/duckscript_sdk/src/sdk/std/env/os_release/help.md @@ -0,0 +1,19 @@ +```sh +var = os_release +``` + +Returns the OS release. + +#### Parameters + +None + +#### Return Value + +The OS release. + +#### Examples + +```sh +release = os_release +``` diff --git a/duckscript_sdk/src/sdk/std/env/os_release/mod.rs b/duckscript_sdk/src/sdk/std/env/os_release/mod.rs new file mode 100755 index 0000000..6da6c3d --- /dev/null +++ b/duckscript_sdk/src/sdk/std/env/os_release/mod.rs @@ -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 { + vec!["os_release".to_string()] + } + + fn help(&self) -> String { + include_str!("help.md").to_string() + } + + fn clone_and_box(&self) -> Box { + Box::new((*self).clone()) + } + + fn run(&self, _arguments: Vec) -> CommandResult { + match uname() { + Ok(info) => CommandResult::Continue(Some(info.release)), + Err(error) => CommandResult::Error(error.to_string()), + } + } +} + +pub(crate) fn create(package: &str) -> Box { + Box::new(CommandImpl { + package: package.to_string(), + }) +} diff --git a/duckscript_sdk/src/sdk/std/env/os_release/mod_test.rs b/duckscript_sdk/src/sdk/std/env/os_release/mod_test.rs new file mode 100644 index 0000000..5f11457 --- /dev/null +++ b/duckscript_sdk/src/sdk/std/env/os_release/mod_test.rs @@ -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, + ); +} diff --git a/duckscript_sdk/src/sdk/std/env/os_version/help.md b/duckscript_sdk/src/sdk/std/env/os_version/help.md new file mode 100644 index 0000000..a0389ed --- /dev/null +++ b/duckscript_sdk/src/sdk/std/env/os_version/help.md @@ -0,0 +1,19 @@ +```sh +var = os_version +``` + +Returns the OS version. + +#### Parameters + +None + +#### Return Value + +The OS version. + +#### Examples + +```sh +version = os_version +``` diff --git a/duckscript_sdk/src/sdk/std/env/os_version/mod.rs b/duckscript_sdk/src/sdk/std/env/os_version/mod.rs new file mode 100755 index 0000000..e02703b --- /dev/null +++ b/duckscript_sdk/src/sdk/std/env/os_version/mod.rs @@ -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 { + vec!["os_version".to_string()] + } + + fn help(&self) -> String { + include_str!("help.md").to_string() + } + + fn clone_and_box(&self) -> Box { + Box::new((*self).clone()) + } + + fn run(&self, _arguments: Vec) -> CommandResult { + match uname() { + Ok(info) => CommandResult::Continue(Some(info.version)), + Err(error) => CommandResult::Error(error.to_string()), + } + } +} + +pub(crate) fn create(package: &str) -> Box { + Box::new(CommandImpl { + package: package.to_string(), + }) +} diff --git a/duckscript_sdk/src/sdk/std/env/os_version/mod_test.rs b/duckscript_sdk/src/sdk/std/env/os_version/mod_test.rs new file mode 100644 index 0000000..f80dac6 --- /dev/null +++ b/duckscript_sdk/src/sdk/std/env/os_version/mod_test.rs @@ -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, + ); +} diff --git a/duckscript_sdk/src/sdk/std/env/uname/help.md b/duckscript_sdk/src/sdk/std/env/uname/help.md new file mode 100644 index 0000000..755e166 --- /dev/null +++ b/duckscript_sdk/src/sdk/std/env/uname/help.md @@ -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 +``` diff --git a/duckscript_sdk/src/sdk/std/env/uname/mod.rs b/duckscript_sdk/src/sdk/std/env/uname/mod.rs new file mode 100755 index 0000000..d27b000 --- /dev/null +++ b/duckscript_sdk/src/sdk/std/env/uname/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, "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)) +} diff --git a/duckscript_sdk/src/sdk/std/env/uname/mod_test.rs b/duckscript_sdk/src/sdk/std/env/uname/mod_test.rs new file mode 100644 index 0000000..cbc4367 --- /dev/null +++ b/duckscript_sdk/src/sdk/std/env/uname/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/uname/script.ds b/duckscript_sdk/src/sdk/std/env/uname/script.ds new file mode 100644 index 0000000..5654049 --- /dev/null +++ b/duckscript_sdk/src/sdk/std/env/uname/script.ds @@ -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} diff --git a/test/std/env/uname_test.ds b/test/std/env/uname_test.ds new file mode 100644 index 0000000..2c09104 --- /dev/null +++ b/test/std/env/uname_test.ds @@ -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 diff --git a/test/std/fs/glob_array_test.ds b/test/std/fs/glob_array_test.ds index 2fbe445..962fa0b 100644 --- a/test/std/fs/glob_array_test.ds +++ b/test/std/fs/glob_array_test.ds @@ -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