mirror of
https://github.com/sagiegurari/duckscript
synced 2024-10-06 16:09:39 +00:00
New glob_chmod command
This commit is contained in:
parent
f9f53421fe
commit
01f004b721
|
@ -2,12 +2,14 @@
|
|||
|
||||
### v0.2.2
|
||||
|
||||
* New glob_chmod command.
|
||||
* New glob_array command #90
|
||||
* New chmod command #19
|
||||
* New is_readonly command.
|
||||
* New is_path_exists command.
|
||||
* New is_directory command.
|
||||
* New is_file command.
|
||||
* Runtime - Fix value expansion for control characters
|
||||
|
||||
### v0.2.1 (2020-02-21)
|
||||
|
||||
|
|
67
docs/sdk.md
67
docs/sdk.md
|
@ -71,6 +71,7 @@
|
|||
* [std::fs::ReadBytes (readbinfile, read_binary_file)](#std__fs__ReadBytes)
|
||||
* [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::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)
|
||||
|
@ -2649,6 +2650,72 @@ chmod 777 ./myfile.txt
|
|||
#### Aliases:
|
||||
chmod
|
||||
|
||||
<a name="std__fs__SetModeGlob"></a>
|
||||
## std::fs::SetModeGlob
|
||||
|
||||
```sh
|
||||
result = glob_chmod mode glob
|
||||
```
|
||||
|
||||
This command will update the mode for the given glob pattern.<br>
|
||||
**This command is currently only available for unix like systems and will return false for all others such as windows.**
|
||||
|
||||
#### Parameters
|
||||
|
||||
* The new mode, for example 755
|
||||
* The path glob
|
||||
|
||||
#### Return Value
|
||||
|
||||
The amount of path entries affected by the operation or false in case of any error.
|
||||
|
||||
#### Examples
|
||||
|
||||
```sh
|
||||
file1 = set ./target/_duskscript_test/glob_chmod/modify1.txt
|
||||
touch ${file1}
|
||||
file2 = set ./target/_duskscript_test/glob_chmod/modify2.txt
|
||||
touch ${file2}
|
||||
|
||||
count = glob_chmod 777 ./target/_duskscript_test/glob_chmod/**/*.txt
|
||||
assert_eq ${count} 2
|
||||
|
||||
readonly = is_readonly ${file1}
|
||||
assert_false ${readonly}
|
||||
readonly = is_readonly ${file2}
|
||||
assert_false ${readonly}
|
||||
|
||||
count = glob_chmod 444 ./target/_duskscript_test/glob_chmod/**/*.txt
|
||||
assert_eq ${count} 2
|
||||
|
||||
readonly = is_readonly ${file1}
|
||||
assert ${readonly}
|
||||
readonly = is_readonly ${file2}
|
||||
assert ${readonly}
|
||||
```
|
||||
|
||||
|
||||
#### Source:
|
||||
|
||||
```sh
|
||||
|
||||
scope::glob_chmod::handle = glob_array ${scope::glob_chmod::argument::2}
|
||||
scope::glob_chmod::count = array_length ${scope::glob_chmod::handle}
|
||||
|
||||
for scope::glob_chmod::entry in ${scope::glob_chmod::handle}
|
||||
chmod ${scope::glob_chmod::argument::1} ${scope::glob_chmod::entry}
|
||||
end
|
||||
|
||||
release ${scope::glob_chmod::handle}
|
||||
|
||||
set ${scope::glob_chmod::count}
|
||||
|
||||
```
|
||||
|
||||
|
||||
#### Aliases:
|
||||
glob_chmod
|
||||
|
||||
<a name="std__fs__TempFile"></a>
|
||||
## std::fs::TempFile
|
||||
```sh
|
||||
|
|
|
@ -17,6 +17,7 @@ mod read_text;
|
|||
mod rm;
|
||||
mod rmdir;
|
||||
mod set_mode;
|
||||
mod set_mode_glob;
|
||||
mod temp_file;
|
||||
mod touch;
|
||||
mod write_bytes;
|
||||
|
@ -50,6 +51,7 @@ pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptEr
|
|||
commands.set(rm::create(&package))?;
|
||||
commands.set(rmdir::create(&package))?;
|
||||
commands.set(set_mode::create(&package))?;
|
||||
commands.set(set_mode_glob::create(&package)?)?;
|
||||
commands.set(temp_file::create(&package))?;
|
||||
commands.set(touch::create(&package))?;
|
||||
commands.set(write_bytes::create(&package))?;
|
||||
|
|
40
duckscript_sdk/src/sdk/std/fs/set_mode_glob/help.md
Normal file
40
duckscript_sdk/src/sdk/std/fs/set_mode_glob/help.md
Normal file
|
@ -0,0 +1,40 @@
|
|||
```sh
|
||||
result = glob_chmod mode glob
|
||||
```
|
||||
|
||||
This command will update the mode for the given glob pattern.<br>
|
||||
**This command is currently only available for unix like systems and will return false for all others such as windows.**
|
||||
|
||||
#### Parameters
|
||||
|
||||
* The new mode, for example 755
|
||||
* The path glob
|
||||
|
||||
#### Return Value
|
||||
|
||||
The amount of path entries affected by the operation or false in case of any error.
|
||||
|
||||
#### Examples
|
||||
|
||||
```sh
|
||||
file1 = set ./target/_duskscript_test/glob_chmod/modify1.txt
|
||||
touch ${file1}
|
||||
file2 = set ./target/_duskscript_test/glob_chmod/modify2.txt
|
||||
touch ${file2}
|
||||
|
||||
count = glob_chmod 777 ./target/_duskscript_test/glob_chmod/**/*.txt
|
||||
assert_eq ${count} 2
|
||||
|
||||
readonly = is_readonly ${file1}
|
||||
assert_false ${readonly}
|
||||
readonly = is_readonly ${file2}
|
||||
assert_false ${readonly}
|
||||
|
||||
count = glob_chmod 444 ./target/_duskscript_test/glob_chmod/**/*.txt
|
||||
assert_eq ${count} 2
|
||||
|
||||
readonly = is_readonly ${file1}
|
||||
assert ${readonly}
|
||||
readonly = is_readonly ${file2}
|
||||
assert ${readonly}
|
||||
```
|
22
duckscript_sdk/src/sdk/std/fs/set_mode_glob/mod.rs
Executable file
22
duckscript_sdk/src/sdk/std/fs/set_mode_glob/mod.rs
Executable 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, "SetModeGlob");
|
||||
let command = create_alias_command(
|
||||
name,
|
||||
vec!["glob_chmod".to_string()],
|
||||
include_str!("help.md").to_string(),
|
||||
"glob_chmod".to_string(),
|
||||
include_str!("script.ds").to_string(),
|
||||
2,
|
||||
)?;
|
||||
|
||||
Ok(Box::new(command))
|
||||
}
|
7
duckscript_sdk/src/sdk/std/fs/set_mode_glob/mod_test.rs
Normal file
7
duckscript_sdk/src/sdk/std/fs/set_mode_glob/mod_test.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
use super::*;
|
||||
use crate::test;
|
||||
|
||||
#[test]
|
||||
fn common_functions() {
|
||||
test::test_common_command_functions(create("").unwrap());
|
||||
}
|
11
duckscript_sdk/src/sdk/std/fs/set_mode_glob/script.ds
Normal file
11
duckscript_sdk/src/sdk/std/fs/set_mode_glob/script.ds
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
scope::glob_chmod::handle = glob_array ${scope::glob_chmod::argument::2}
|
||||
scope::glob_chmod::count = array_length ${scope::glob_chmod::handle}
|
||||
|
||||
for scope::glob_chmod::entry in ${scope::glob_chmod::handle}
|
||||
chmod ${scope::glob_chmod::argument::1} ${scope::glob_chmod::entry}
|
||||
end
|
||||
|
||||
release ${scope::glob_chmod::handle}
|
||||
|
||||
set ${scope::glob_chmod::count}
|
34
test/std/fs/chmod_glob_test.ds
Normal file
34
test/std/fs/chmod_glob_test.ds
Normal file
|
@ -0,0 +1,34 @@
|
|||
|
||||
os = os_family
|
||||
windows = equals ${os} "windows"
|
||||
|
||||
fn test_modify
|
||||
if not ${windows}
|
||||
file1 = set ./target/_duskscript_test/glob_chmod/modify1.txt
|
||||
touch ${file1}
|
||||
file2 = set ./target/_duskscript_test/glob_chmod/modify2.txt
|
||||
touch ${file2}
|
||||
|
||||
count = glob_chmod 777 ./target/_duskscript_test/glob_chmod/**/*.txt
|
||||
assert_eq ${count} 2
|
||||
|
||||
readonly = is_readonly ${file1}
|
||||
assert_false ${readonly}
|
||||
readonly = is_readonly ${file2}
|
||||
assert_false ${readonly}
|
||||
|
||||
count = glob_chmod 444 ./target/_duskscript_test/glob_chmod/**/*.txt
|
||||
assert_eq ${count} 2
|
||||
|
||||
readonly = is_readonly ${file1}
|
||||
assert ${readonly}
|
||||
readonly = is_readonly ${file2}
|
||||
assert ${readonly}
|
||||
end
|
||||
end
|
||||
|
||||
fn test_not_exists
|
||||
count = glob_chmod 777 ./target/*.nofile
|
||||
|
||||
assert_eq ${count} 0
|
||||
end
|
Loading…
Reference in a new issue