woke
woke copied to clipboard
Add support to expand glob patterns
Please check if the PR fulfills these requirements
- [x] The commit message follows our guidelines
- [x] Tests for the changes have been added (for bug fixes / features)
- [x] Docs have been added / updated (for bug fixes / features) see docs/README.md
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
- Fix #210 (documentation).
- Add support to expand glob patterns within
woke. Support double star expansion.
What is the current behavior? (You can also link to an open issue here)
- If a directory is specified as input argument,
wokeparses all files recursively. - Glob patterns as input argument are not supported.
- It's not possible to pass a glob argument to specify that only a subset of files in a directory are parsed by woke.
- The
usage.mdfile indicates file globs can be used, but in reality glob patterns are not expanded by woke. Glob pattern expansion may be performed by a invoking shell, not by woke itself.
To change this, supply a space-separated list of globs as the first argument
If users want to perform glob expansion, they must perform glob expansion before before invoking woke, such as invoking wokefrom a shell.
What is the new behavior (if this is a feature change)?
When command-line arguments include a glob pattern, woke expands the glob pattern. The following special terms in the patterns are supported:
| Special Terms | Meaning |
|---|---|
* |
matches any sequence of non-path-separators |
/**/ |
matches zero or more directories |
? |
matches any single non-path-separator character |
[class] |
matches any single non-path-separator character against a class of characters ([see "character classes"]) |
{alt1,...} |
matches a sequence of characters if one of the comma-separated alternatives matches |
Does this PR introduce a breaking change? (What changes might users need to make due to this PR?)
A subtle problem could occur in the corner case when you want to match a file that includes the wildcard characters (e.g. * and ?).
Before this change, woke '*.go' would look for a file named *.go (without the wildcard expansion) because woke wasn't expanding glob patterns.
After this change, woke '*.go'would cause wildcard expansion. If you really want to match a file named *.go, either don't use wildcard or escape the wildcard, e.g. woke '\*.go'.
Other information:
To support double star expansion, there is a dependency on https://github.com/bmatcuk/doublestar.
What do you think about adding support for double star operator using one of the libraries listed here: https://www.client9.com/golang-globs-and-the-double-star-glob-operator/
Codecov Report
Merging #211 (92f7ec0) into main (b92e612) will increase coverage by
0.06%. The diff coverage is100.00%.
@@ Coverage Diff @@
## main #211 +/- ##
==========================================
+ Coverage 93.76% 93.82% +0.06%
==========================================
Files 23 23
Lines 818 826 +8
==========================================
+ Hits 767 775 +8
Misses 30 30
Partials 21 21
| Impacted Files | Coverage Δ | |
|---|---|---|
| pkg/parser/parser.go | 100.00% <ø> (ø) |
|
| cmd/root.go | 84.09% <100.00%> (+2.03%) |
:arrow_up: |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.