diff --git a/CHANGELOG.md b/CHANGELOG.md index b722e0a..b6fd926 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## CHANGELOG +### v0.3.3 + +* New temp_dir command. +* Runtime - Use default trait. + ### v0.3.2 (2020-04-04) * New array_set command. diff --git a/docs/sdk.md b/docs/sdk.md index b9ade6b..2dc1658 100644 --- a/docs/sdk.md +++ b/docs/sdk.md @@ -79,6 +79,7 @@ * [std::fs::ReadText (readfile, read_text_file)](#std__fs__ReadText) * [std::fs::SetMode (chmod)](#std__fs__SetMode) * [std::fs::SetModeGlob (glob_chmod)](#std__fs__SetModeGlob) +* [std::fs::TempDirectory (temp_dir)](#std__fs__TempDirectory) * [std::fs::TempFile (temp_file)](#std__fs__TempFile) * [std::fs::WriteBytes (writebinfile, write_binary_file)](#std__fs__WriteBytes) * [std::fs::WriteText (writefile, write_text_file)](#std__fs__WriteText) @@ -2949,6 +2950,34 @@ set ${scope::glob_chmod::output} #### Aliases: glob_chmod + +## std::fs::TempDirectory +```sh +path = temp_dir +``` + +This command will return the system temporary directory path. + +#### Parameters + +None + +#### Return Value + +The directory path. + +#### Examples + +```sh +path = temp_dir + +echo ${path} +``` + + +#### Aliases: +temp_dir + ## std::fs::TempFile ```sh diff --git a/duckscript_sdk/src/sdk/std/fs/mod.rs b/duckscript_sdk/src/sdk/std/fs/mod.rs index 7e16f31..8bcad7e 100755 --- a/duckscript_sdk/src/sdk/std/fs/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/mod.rs @@ -18,6 +18,7 @@ mod rm; mod rmdir; mod set_mode; mod set_mode_glob; +mod temp_dir; mod temp_file; mod touch; mod write_bytes; @@ -52,6 +53,7 @@ pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptEr commands.set(rmdir::create(&package))?; commands.set(set_mode::create(&package))?; commands.set(set_mode_glob::create(&package)?)?; + commands.set(temp_dir::create(&package))?; commands.set(temp_file::create(&package))?; commands.set(touch::create(&package))?; commands.set(write_bytes::create(&package))?; diff --git a/duckscript_sdk/src/sdk/std/fs/temp_dir/help.md b/duckscript_sdk/src/sdk/std/fs/temp_dir/help.md new file mode 100644 index 0000000..3543597 --- /dev/null +++ b/duckscript_sdk/src/sdk/std/fs/temp_dir/help.md @@ -0,0 +1,21 @@ +```sh +path = temp_dir +``` + +This command will return the system temporary directory path. + +#### Parameters + +None + +#### Return Value + +The directory path. + +#### Examples + +```sh +path = temp_dir + +echo ${path} +``` diff --git a/duckscript_sdk/src/sdk/std/fs/temp_dir/mod.rs b/duckscript_sdk/src/sdk/std/fs/temp_dir/mod.rs new file mode 100755 index 0000000..fd957fd --- /dev/null +++ b/duckscript_sdk/src/sdk/std/fs/temp_dir/mod.rs @@ -0,0 +1,44 @@ +use crate::utils::pckg; +use duckscript::types::command::{Command, CommandResult}; +use fsio::path::from_path::FromPath; +use std::env; + +#[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, "TempDirectory") + } + + fn aliases(&self) -> Vec { + vec!["temp_dir".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 { + let directory_path = env::temp_dir(); + let directory = FromPath::from_path(&directory_path); + + CommandResult::Continue(Some(directory)) + } +} + +pub(crate) fn create(package: &str) -> Box { + Box::new(CommandImpl { + package: package.to_string(), + }) +} diff --git a/duckscript_sdk/src/sdk/std/fs/temp_dir/mod_test.rs b/duckscript_sdk/src/sdk/std/fs/temp_dir/mod_test.rs new file mode 100644 index 0000000..653808d --- /dev/null +++ b/duckscript_sdk/src/sdk/std/fs/temp_dir/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_simple() { + test::run_script_and_validate( + vec![create("")], + "out = temp_dir", + CommandValidation::Ignore, + ); +} diff --git a/test/std/fs/temp_dir_test.ds b/test/std/fs/temp_dir_test.ds new file mode 100644 index 0000000..dac6505 --- /dev/null +++ b/test/std/fs/temp_dir_test.ds @@ -0,0 +1,12 @@ + +fn test_simple + file = temp_file + directory = temp_dir + dir_exists = is_directory ${directory} + + valid = starts_with ${file} ${directory} + + assert ${valid} + assert ${dir_exists} +end +