mirror of
https://github.com/sagiegurari/duckscript
synced 2024-10-14 11:53:05 +00:00
New temp_dir command
This commit is contained in:
parent
4251109c4e
commit
2ca953b171
|
@ -1,5 +1,10 @@
|
||||||
## CHANGELOG
|
## CHANGELOG
|
||||||
|
|
||||||
|
### v0.3.3
|
||||||
|
|
||||||
|
* New temp_dir command.
|
||||||
|
* Runtime - Use default trait.
|
||||||
|
|
||||||
### v0.3.2 (2020-04-04)
|
### v0.3.2 (2020-04-04)
|
||||||
|
|
||||||
* New array_set command.
|
* New array_set command.
|
||||||
|
|
29
docs/sdk.md
29
docs/sdk.md
|
@ -79,6 +79,7 @@
|
||||||
* [std::fs::ReadText (readfile, read_text_file)](#std__fs__ReadText)
|
* [std::fs::ReadText (readfile, read_text_file)](#std__fs__ReadText)
|
||||||
* [std::fs::SetMode (chmod)](#std__fs__SetMode)
|
* [std::fs::SetMode (chmod)](#std__fs__SetMode)
|
||||||
* [std::fs::SetModeGlob (glob_chmod)](#std__fs__SetModeGlob)
|
* [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::TempFile (temp_file)](#std__fs__TempFile)
|
||||||
* [std::fs::WriteBytes (writebinfile, write_binary_file)](#std__fs__WriteBytes)
|
* [std::fs::WriteBytes (writebinfile, write_binary_file)](#std__fs__WriteBytes)
|
||||||
* [std::fs::WriteText (writefile, write_text_file)](#std__fs__WriteText)
|
* [std::fs::WriteText (writefile, write_text_file)](#std__fs__WriteText)
|
||||||
|
@ -2949,6 +2950,34 @@ set ${scope::glob_chmod::output}
|
||||||
#### Aliases:
|
#### Aliases:
|
||||||
glob_chmod
|
glob_chmod
|
||||||
|
|
||||||
|
<a name="std__fs__TempDirectory"></a>
|
||||||
|
## 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
|
||||||
|
|
||||||
<a name="std__fs__TempFile"></a>
|
<a name="std__fs__TempFile"></a>
|
||||||
## std::fs::TempFile
|
## std::fs::TempFile
|
||||||
```sh
|
```sh
|
||||||
|
|
|
@ -18,6 +18,7 @@ mod rm;
|
||||||
mod rmdir;
|
mod rmdir;
|
||||||
mod set_mode;
|
mod set_mode;
|
||||||
mod set_mode_glob;
|
mod set_mode_glob;
|
||||||
|
mod temp_dir;
|
||||||
mod temp_file;
|
mod temp_file;
|
||||||
mod touch;
|
mod touch;
|
||||||
mod write_bytes;
|
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(rmdir::create(&package))?;
|
||||||
commands.set(set_mode::create(&package))?;
|
commands.set(set_mode::create(&package))?;
|
||||||
commands.set(set_mode_glob::create(&package)?)?;
|
commands.set(set_mode_glob::create(&package)?)?;
|
||||||
|
commands.set(temp_dir::create(&package))?;
|
||||||
commands.set(temp_file::create(&package))?;
|
commands.set(temp_file::create(&package))?;
|
||||||
commands.set(touch::create(&package))?;
|
commands.set(touch::create(&package))?;
|
||||||
commands.set(write_bytes::create(&package))?;
|
commands.set(write_bytes::create(&package))?;
|
||||||
|
|
21
duckscript_sdk/src/sdk/std/fs/temp_dir/help.md
Normal file
21
duckscript_sdk/src/sdk/std/fs/temp_dir/help.md
Normal file
|
@ -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}
|
||||||
|
```
|
44
duckscript_sdk/src/sdk/std/fs/temp_dir/mod.rs
Executable file
44
duckscript_sdk/src/sdk/std/fs/temp_dir/mod.rs
Executable file
|
@ -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<String> {
|
||||||
|
vec!["temp_dir".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 directory_path = env::temp_dir();
|
||||||
|
let directory = FromPath::from_path(&directory_path);
|
||||||
|
|
||||||
|
CommandResult::Continue(Some(directory))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn create(package: &str) -> Box<dyn Command> {
|
||||||
|
Box::new(CommandImpl {
|
||||||
|
package: package.to_string(),
|
||||||
|
})
|
||||||
|
}
|
17
duckscript_sdk/src/sdk/std/fs/temp_dir/mod_test.rs
Normal file
17
duckscript_sdk/src/sdk/std/fs/temp_dir/mod_test.rs
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_simple() {
|
||||||
|
test::run_script_and_validate(
|
||||||
|
vec![create("")],
|
||||||
|
"out = temp_dir",
|
||||||
|
CommandValidation::Ignore,
|
||||||
|
);
|
||||||
|
}
|
12
test/std/fs/temp_dir_test.ds
Normal file
12
test/std/fs/temp_dir_test.ds
Normal file
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue