Cabal-3.12.1.0: A framework for packaging Haskell software

Copyright | Isaac Jones Simon Marlow 2003-2004
License | BSD3 portions Copyright (c) 2007, Galois Inc.
Maintainer | cabal-devel@haskell.org
Portability | portable
Safe Haskell | None
Language | Haskell2010

Distribution.Simple.Glob

Contents

- Globs
- Matching on globs
- Parsing globs
- Utility

Description

Simple file globbing.

Synopsis

- data Glob
- data GlobResult a
  - = GlobMatch a
  - | GlobWarnMultiDot a
  - | GlobMissingDirectory a
  - | GlobMatchesDirectory a
- globMatches :: [GlobResult a] -> [a]
- fileGlobMatches :: CabalSpecVersion -> Glob -> FilePath -> Maybe (GlobResult ())
- matchDirFileGlob :: Verbosity -> CabalSpecVersion -> FilePath -> FilePath -> IO [FilePath]
- matchDirFileGlobWithDie :: Verbosity -> (Verbosity -> CabalException -> IO [FilePath]) -> CabalSpecVersion -> FilePath -> FilePath -> IO [FilePath]
- runDirFileGlob :: Verbosity -> Maybe CabalSpecVersion -> FilePath -> Glob -> IO [GlobResult FilePath]
- parseFileGlob :: CabalSpecVersion -> FilePath -> Either GlobSyntaxError Glob
- data GlobSyntaxError
  - = StarInDirectory
  - | StarInFileName
  - | StarInExtension
  - | NoExtensionOnStar
  - | EmptyGlob
  - | LiteralFileNameGlobStar
  - | VersionDoesNotSupportGlobStar
  - | VersionDoesNotSupportGlob
- explainGlobSyntaxError :: FilePath -> GlobSyntaxError -> String
- isRecursiveInRoot :: Glob -> Bool

# Globs

data Glob Source #

A filepath specified by globbing.

#### Instances

Instances details

Parsec Glob Source # |
Instance details Defined in Distribution.Simple.Glob.Internal Methods parsec :: CabalParsing m => m Glob Source #
Pretty Glob Source # |
Instance details Defined in Distribution.Simple.Glob.Internal Methods pretty :: Glob -> Doc Source # prettyVersioned :: CabalSpecVersion -> Glob -> Doc Source #
Structured Glob Source # |
Instance details Defined in Distribution.Simple.Glob.Internal Methods structure :: Proxy Glob -> Structure Source # structureHash' :: Tagged Glob MD5
Binary Glob Source # |
Instance details Defined in Distribution.Simple.Glob.Internal Methods put :: Glob -> Put # get :: Get Glob # putList :: [Glob] -> Put #
Generic Glob Source # |

Instance details

Defined in Distribution.Simple.Glob.Internal

Associated Types

type Rep Glob |

Instance details

Defined in Distribution.Simple.Glob.Internal

type Rep Glob = D1 ('MetaData "Glob" "Distribution.Simple.Glob.Internal" "Cabal-3.12.1.0-cda0" 'False) ((C1 ('MetaCons "GlobDir" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 GlobPieces) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Glob)) :+: C1 ('MetaCons "GlobDirRecursive" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 GlobPieces))) :+: (C1 ('MetaCons "GlobFile" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 GlobPieces)) :+: C1 ('MetaCons "GlobDirTrailing" 'PrefixI 'False) (U1 :: Type -> Type)))

Methods

from :: Glob -> Rep Glob x #

to :: Rep Glob x -> Glob #

Show Glob Source # |
Instance details Defined in Distribution.Simple.Glob.Internal Methods showsPrec :: Int -> Glob -> ShowS # show :: Glob -> String # showList :: [Glob] -> ShowS #
Eq Glob Source # |
Instance details Defined in Distribution.Simple.Glob.Internal Methods (==) :: Glob -> Glob -> Bool # (/=) :: Glob -> Glob -> Bool #
type Rep Glob Source # |

Instance details

Defined in Distribution.Simple.Glob.Internal

type Rep Glob = D1 ('MetaData "Glob" "Distribution.Simple.Glob.Internal" "Cabal-3.12.1.0-cda0" 'False) ((C1 ('MetaCons "GlobDir" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 GlobPieces) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Glob)) :+: C1 ('MetaCons "GlobDirRecursive" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 GlobPieces))) :+: (C1 ('MetaCons "GlobFile" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 GlobPieces)) :+: C1 ('MetaCons "GlobDirTrailing" 'PrefixI 'False) (U1 :: Type -> Type)))

# Matching on globs

data GlobResult a Source #

Constructors

GlobMatch a | The glob matched the value supplied.
GlobWarnMultiDot a | The glob did not match the value supplied because the cabal-version is too low and the extensions on the file did not precisely match the glob's extensions, but rather the glob was a proper suffix of the file's extensions; i.e., if not for the low cabal-version, it would have matched.
GlobMissingDirectory a | The glob couldn't match because the directory named doesn't exist. The directory will be as it appears in the glob (i.e., relative to the directory passed to `matchDirFileGlob`, and, for 'data-files', relative to 'data-dir').
GlobMatchesDirectory a | The glob matched a directory when we were looking for files only. It didn't match a file! Since: Cabal-3.12.0.0

#### Instances

Instances details

Functor GlobResult Source # |
Instance details Defined in Distribution.Simple.Glob.Internal Methods fmap :: (a -> b) -> GlobResult a -> GlobResult b # (<$) :: a -> GlobResult b -> GlobResult a #
Show a => Show (GlobResult a) Source # |
Instance details Defined in Distribution.Simple.Glob.Internal Methods showsPrec :: Int -> GlobResult a -> ShowS # show :: GlobResult a -> String # showList :: [GlobResult a] -> ShowS #
Eq a => Eq (GlobResult a) Source # |
Instance details Defined in Distribution.Simple.Glob.Internal Methods (==) :: GlobResult a -> GlobResult a -> Bool # (/=) :: GlobResult a -> GlobResult a -> Bool #
Ord a => Ord (GlobResult a) Source # |

Instance details

Defined in Distribution.Simple.Glob.Internal

Methods

compare :: GlobResult a -> GlobResult a -> Ordering #

(<) :: GlobResult a -> GlobResult a -> Bool #

(<=) :: GlobResult a -> GlobResult a -> Bool #

(>) :: GlobResult a -> GlobResult a -> Bool #

(>=) :: GlobResult a -> GlobResult a -> Bool #

max :: GlobResult a -> GlobResult a -> GlobResult a #

min :: GlobResult a -> GlobResult a -> GlobResult a #

globMatches :: [GlobResult a] -> [a] Source #

Extract the matches from a list of `GlobResult`s.

Note: throws away the `GlobMissingDirectory` results; chances are that you want to check for these and error out if any are present.

Since: Cabal-3.12.0.0

fileGlobMatches :: CabalSpecVersion -> Glob -> FilePath -> Maybe (GlobResult ()) Source #

How/does the glob match the given filepath, according to the cabal version? Since this is pure, we don't make a distinction between matching on directories or files (i.e. this function won't return `GlobMatchesDirectory`)

matchDirFileGlob :: Verbosity -> CabalSpecVersion -> FilePath -> FilePath -> IO [FilePath] Source #

This will `die'` when the glob matches no files, or if the glob refers to a missing directory, or if the glob fails to parse.

The `Version` argument must be the spec version of the package description being processed, as globs behave slightly differently in different spec versions.

The first `FilePath` argument is the directory that the glob is relative to. It must be a valid directory (and hence it can't be the empty string). The returned values will not include this prefix.

The second `FilePath` is the glob itself.

matchDirFileGlobWithDie :: Verbosity -> (Verbosity -> CabalException -> IO [FilePath]) -> CabalSpecVersion -> FilePath -> FilePath -> IO [FilePath] Source #

Like `matchDirFileGlob` but with customizable `die`

Since: Cabal-3.6.0.0

runDirFileGlob Source #

Arguments

:: Verbosity |
-> Maybe CabalSpecVersion | If the glob we are running should care about the cabal spec, and warnings such as `GlobWarnMultiDot`, then this should be the version. If you want to run a glob but don't care about any of the cabal-spec restrictions on globs, use `Nothing`!
-> FilePath |
-> Glob |
-> IO [GlobResult FilePath] |

Match files against a pre-parsed glob, starting in a directory.

The `Version` argument must be the spec version of the package description being processed, as globs behave slightly differently in different spec versions.

The `FilePath` argument is the directory that the glob is relative to. It must be a valid directory (and hence it can't be the empty string). The returned values will not include this prefix.

# Parsing globs

parseFileGlob :: CabalSpecVersion -> FilePath -> Either GlobSyntaxError Glob Source #

data GlobSyntaxError Source #

Constructors

StarInDirectory |
StarInFileName |
StarInExtension |
NoExtensionOnStar |
EmptyGlob |
LiteralFileNameGlobStar |
VersionDoesNotSupportGlobStar |
VersionDoesNotSupportGlob |

#### Instances

Instances details

Show GlobSyntaxError Source # |
Instance details Defined in Distribution.Simple.Glob.Internal Methods showsPrec :: Int -> GlobSyntaxError -> ShowS # show :: GlobSyntaxError -> String # showList :: [GlobSyntaxError] -> ShowS #
Eq GlobSyntaxError Source # |
Instance details Defined in Distribution.Simple.Glob.Internal Methods (==) :: GlobSyntaxError -> GlobSyntaxError -> Bool # (/=) :: GlobSyntaxError -> GlobSyntaxError -> Bool #

explainGlobSyntaxError :: FilePath -> GlobSyntaxError -> String Source #

# Utility

isRecursiveInRoot :: Glob -> Bool Source #

Is the root of this relative glob path a directory-recursive wildcard, e.g. `**/*.txt` ?