Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to expand glob patterns #211

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

sebastien-rosset
Copy link
Contributor

@sebastien-rosset sebastien-rosset commented Jun 28, 2022

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • 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, ...)

  1. Fix Suggestion to improve "glob" expansion in documentation #210 (documentation).
  2. 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)

  1. If a directory is specified as input argument, woke parses all files recursively.
  2. Glob patterns as input argument are not supported.
  3. It's not possible to pass a glob argument to specify that only a subset of files in a directory are parsed by woke.
  4. The usage.md file 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.

@sebastien-rosset
Copy link
Contributor Author

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/

@sebastien-rosset sebastien-rosset force-pushed the glob-expansion branch 6 times, most recently from 55f50f4 to 80f9b24 Compare June 30, 2022 23:19
cmd/root.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Jul 19, 2022

Codecov Report

Merging #211 (92f7ec0) into main (b92e612) will increase coverage by 0.06%.
The diff coverage is 100.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%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@sebastien-rosset sebastien-rosset marked this pull request as draft July 27, 2022 23:24
@sebastien-rosset sebastien-rosset marked this pull request as ready for review November 7, 2022 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suggestion to improve "glob" expansion in documentation
2 participants