convex-pbt-cli
Safe HaskellSafe-Inferred
LanguageHaskell2010

PbtCli.Glob

Description

Minimal shell-style globbing, enough for the packages: field of a cabal.project file.

The reference implementation (scriptslist-test-suiteslist-test-suites.sh) resolves package entries by letting bash expand them, so tokens such as */*.cabal or pkgs/* work. This module reproduces that behaviour without a shell and without pulling in a dependency: patterns are matched segment by segment against the real filesystem, * and ? never cross a directory separator, and — as in bash — a wildcard does not match a leading dot.

Synopsis

Documentation

isGlob :: String -> Bool Source #

Does this token contain any wildcard metacharacter?

matchSegment :: String -> String -> Bool Source #

Match a single path segment against a single pattern segment.

* matches any run of characters, ? exactly one, and everything else is literal. A pattern that does not itself start with . never matches a name that does, which is how shell globs hide dotfiles.

expandGlob :: FilePath -> String -> IO [FilePath] Source #

Expand pattern, interpreted relative to base, into the paths that actually exist. The returned paths keep the base </> … prefix and are sorted, so callers get a deterministic order.

A pattern with no wildcard is simply checked for existence, which makes this function usable for every packages: token, glob or not.