dennisdoomen / dennisdoomen/pathy

[API Proposal]: GlobDirectories, Glob and exclude patterns

Open
#141 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C#
Stars
27
Forks
5
Avg merge
21h 29m
Merged PRs (30d)
10

Description

### Background and motivation

`Pathy.Globbing` only exposes `GlobFiles`. Two capabilities that `Microsoft.Extensions.FileSystemGlobbing` already provides are not reachable: matching directories, and excluding patterns. Exclusions in particular are close to essential in real projects, because almost every glob over a source tree needs to skip `bin`, `obj`, `node_modules` or `.git`. Today callers have to post-filter the results, which is both slower and more verbose than letting the matcher do it.

### API Proposal

```C#
namespace Pathy
{
public static class ChainablePathGlobbingExtensions
{
public static ChainablePath[] GlobDirectories(this ChainablePath path, params string[] globPatterns);
public static ChainablePath[] Glob(this ChainablePath path, params string[] globPatterns);

public static ChainablePath[] GlobFiles(this ChainablePath path, string[] include, string[] exclude);
}
}
```

`Glob` matches both files and directories. The `include`/`exclude` overload maps directly onto the matcher's `AddInclude` and `AddExclude`.

### API Usage

```C#
var sourceFiles = ChainablePath.Current.GlobFiles(
include: new[] { "**/*.cs" },
exclude: new[] { "**/bin/**", "**/obj/**" });

var testProjects = ChainablePath.Current.GlobDirectories("**/*.Specs");

var everything = (ChainablePath.Current / "artifacts").Glob("**/*");
```

### Alternative Designs

* A small options object or builder instead of an `include`/`exclude` pair. More extensible, but heavier for the common case.
* Leave exclusion to LINQ after the fact. That is what people do today, and it means walking directories that are then thrown away.

### Risks

Two positional string array parameters are easy to transpose, so named arguments should be encouraged in the documentation, or the shape reconsidered. Adding an overload next to the existing `params string[]` version may create ambiguity at the call site and needs checking.

Contributor guide

Open the contributing guide

Research direction

Locate the existing ChainablePathGlobbingExtensions.GlobFiles implementation and its use of Microsoft.Extensions.FileSystemGlobbing. Compare the proposed GlobDirectories, Glob, and include/exclude overload against the current API; done means the requested APIs match the examples, directory and exclusion matching works, and documentation covers named arguments.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.