Git Product home page Git Product logo

Comments (1)

daveaglick avatar daveaglick commented on August 30, 2024

These are all great questions and should be clarified in the docs.

I would expect that the pattern /{a,}/**/x.txt would require matched files to be at least two directories deep since / is the root, {a,}/ is one deep and then **/ is another one or more.

So you're thinking that /a/x.txt and /d/x.txt should not be matches for /{a,}/**/x.txt? I actually wrote a new test to confirm the docs:

[Test]
public void WildcardShouldMatchEmptyPath()
{
    // Given
    TestFileProvider fileProvider = new TestFileProvider();
    fileProvider.AddDirectory("/");
    fileProvider.AddDirectory("/root");
    fileProvider.AddDirectory("/root/a");
    fileProvider.AddDirectory("/root/a/b");
    fileProvider.AddDirectory("/root/d");
    fileProvider.AddFile("/root/a/x.txt");
    fileProvider.AddFile("/root/a/b/x.txt");
    fileProvider.AddFile("/root/d/x.txt");
    IDirectory directory = fileProvider.GetDirectory("/");

    // When
    IEnumerable<IFile> matches = Globber.GetFiles(directory, "root/{a,}/**/x.txt");

    // Then
    matches.Select(x => x.Path.FullPath).ShouldBe(
        new[] { "/root/a/x.txt", "/root/a/b/x.txt", "/root/d/x.txt" }, true);
}

Sure enough, the **/ pattern matches zero or more path segments. I'll try to clarify this in the docs.

There is one thing wrong with the example though: rooted globbing patterns aren't allowed. So the pattern /{a,}/**/x.txt from the docs would actually throw an exception - I'll need to get that corrected.

It says that * and ** match any number of characters, does that mean 0 or more such that /*.txt would match "/.txt"?

That's correct, *.txt would match a file named .txt

Is {n,x} an or statement that will match either "n" or "x" or is this a range that will match anything from "n" to "x", such as "t"?

The former - it specifies a set, not a range.

If {n,x} is an or statement then can it be even longer, such as {n,x,y} to match three characters?

Correct.

When you leave one side null, for example {c,}, does it match everything that is "c" or greater meaning that it would match "c" and "t", but not "a" or "b"

No, there's no range calculus going on. It's most useful when dealing with "not" logic like {!a,} which means "any match except a".

It says that ! is useful when used with multiple expansion such as {*,!x}. Is it usable in any other way and what would it mean in that context?

The best way to get an idea how ! works is to probably look at the test cases here: https://github.com/Wyamio/Wyam/blob/15c34df68f3908019b4ff289e82ffdc346b15ca9/tests/core/Wyam.Core.Tests/IO/Globbing/GlobberFixture.cs#L126-L162 One interesting use is to exclude specific extensions: {!.txt,}

Thanks a lot for these great questions - it challenged some of my own recollection of how the globbing works and made me write a few new unit tests just to be sure I understood it correctly. I'll revisit the docs around this area soon (and will keep this issue open as a reminder until I do).

from wyam.web.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.