Skip to content

Commit

Permalink
update docs: add glob
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirMarkelov committed Mar 20, 2020
1 parent ff95f50 commit a792d15
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "haku"
version = "0.3.1"
version = "0.3.2"
authors = ["Vladimir Markelov <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
Expand Down
6 changes: 6 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
haku (0.3.2) unstable; urgency=medium

* New function `glog` to get list of files that match a pattern

-- Vladimir Markelov <[email protected]> Thu, 19 Mar 2020 23:54:58 -0700

haku (0.3.1) unstable; urgency=medium

* First public version
Expand Down
1 change: 1 addition & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,7 @@ is executed. If you want to "delete" such variable, use workaround with empty va
- `with-stem` - replaces file or directory stem and keep existing extension: `with-stem("/opt/doc/today.log", "yesterday")` => `"/opt/doc/yesterday.log"`
- `join` - joins any number of path elements into one path using OS file path separator: `"join("/opt", "doc", "today.log")` => `"/opt/doc/today.log"`
- `invoke-dir`, `invokedir` - `invoke-dir()` returns the directory from which the script was executed. It maybe useful if you call `cd` a few time and want to return to the original directory or to build absolute path related to the current working directory.
- `glob` - `glob(pattern[,what])` returns a list of files and/or directories that match `pattern`in Linux shell style. `what` default value is `0`. When `what=1`, glob retuns only files; when `what=2`, glob returns only directories; otherwise glob returns both

#### String manipulation

Expand Down
6 changes: 6 additions & 0 deletions src/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,12 @@ fn decrement(args: &[VarValue]) -> FuncResult {
Ok(VarValue::Int(val))
}

/// Returns a list of files and/or directories that match a pattern.
/// First argument is a glob pattern.
/// Second argument is optional:
/// 0 (default) - return both files and directories
/// 1 - return only files
/// 2 - return only directories
fn globfiles(args: &[VarValue]) -> FuncResult {
let patt = if args.is_empty() { "*".to_owned() } else { args[0].to_string() };
let globtype = if args.len() > 1 { args[1].to_int() } else { 0 };
Expand Down

0 comments on commit a792d15

Please sign in to comment.