diff --git a/duckscript_sdk/src/sdk/std/env/os_name/mod.rs b/duckscript_sdk/src/sdk/std/env/os_name/mod.rs index 9b81de9..c383cf9 100755 --- a/duckscript_sdk/src/sdk/std/env/os_name/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/os_name/mod.rs @@ -5,6 +5,23 @@ use duckscript::types::command::{Command, CommandResult}; #[path = "./mod_test.rs"] mod mod_test; +cfg_if::cfg_if! { + if #[cfg(windows)] { + fn get_os_value() -> Result { + Ok("Windows".to_string()) + } + } else { + use uname::uname; + + fn get_os_value() -> Result { + match uname() { + Ok(info) => Ok(info.sysname), + Err(error) => Err(error.to_string()), + } + } + } +} + #[derive(Clone)] pub(crate) struct CommandImpl { package: String, @@ -28,15 +45,9 @@ impl Command for CommandImpl { } fn run(&self, _arguments: Vec) -> CommandResult { - if cfg!(windows) { - CommandResult::Continue(Some("Windows".to_string())) - } else { - use uname::uname; - - match uname() { - Ok(info) => CommandResult::Continue(Some(info.sysname)), - Err(error) => CommandResult::Error(error.to_string()), - } + match get_os_value() { + Ok(value) => CommandResult::Continue(Some(value)), + Err(error) => CommandResult::Error(error), } } } diff --git a/duckscript_sdk/src/sdk/std/env/os_release/mod.rs b/duckscript_sdk/src/sdk/std/env/os_release/mod.rs index 53b83e9..d593701 100755 --- a/duckscript_sdk/src/sdk/std/env/os_release/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/os_release/mod.rs @@ -5,6 +5,23 @@ use duckscript::types::command::{Command, CommandResult}; #[path = "./mod_test.rs"] mod mod_test; +cfg_if::cfg_if! { + if #[cfg(windows)] { + fn get_os_value() -> Result { + Err("Not Supported.".to_string()) + } + } else { + use uname::uname; + + fn get_os_value() -> Result { + match uname() { + Ok(info) => Ok(info.release), + Err(error) => Err(error.to_string()), + } + } + } +} + #[derive(Clone)] pub(crate) struct CommandImpl { package: String, @@ -28,15 +45,9 @@ impl Command for CommandImpl { } fn run(&self, _arguments: Vec) -> CommandResult { - if cfg!(windows) { - CommandResult::Error("Not Supported.".to_string()) - } else { - use uname::uname; - - match uname() { - Ok(info) => CommandResult::Continue(Some(info.release)), - Err(error) => CommandResult::Error(error.to_string()), - } + match get_os_value() { + Ok(value) => CommandResult::Continue(Some(value)), + Err(error) => CommandResult::Error(error), } } } diff --git a/duckscript_sdk/src/sdk/std/env/os_version/mod.rs b/duckscript_sdk/src/sdk/std/env/os_version/mod.rs index e160e0c..f1a52f1 100755 --- a/duckscript_sdk/src/sdk/std/env/os_version/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/os_version/mod.rs @@ -5,6 +5,23 @@ use duckscript::types::command::{Command, CommandResult}; #[path = "./mod_test.rs"] mod mod_test; +cfg_if::cfg_if! { + if #[cfg(windows)] { + fn get_os_value() -> Result { + Err("Not Supported.".to_string()) + } + } else { + use uname::uname; + + fn get_os_value() -> Result { + match uname() { + Ok(info) => Ok(info.version), + Err(error) => Err(error.to_string()), + } + } + } +} + #[derive(Clone)] pub(crate) struct CommandImpl { package: String, @@ -28,15 +45,9 @@ impl Command for CommandImpl { } fn run(&self, _arguments: Vec) -> CommandResult { - if cfg!(windows) { - CommandResult::Error("Not Supported.".to_string()) - } else { - use uname::uname; - - match uname() { - Ok(info) => CommandResult::Continue(Some(info.version)), - Err(error) => CommandResult::Error(error.to_string()), - } + match get_os_value() { + Ok(value) => CommandResult::Continue(Some(value)), + Err(error) => CommandResult::Error(error), } } }