packages feed

fluent-lint-1.0.0: app/Config.hs

module Config where

import Data.List.NonEmpty (NonEmpty, some1)
import Data.Version (showVersion)
import Options.Applicative
import Paths_fluent_lint qualified
import Prelude

-- | What the command line asks for.
data Config = Config
    { lenient :: Bool
    , reference :: Maybe FilePath
    , files :: NonEmpty FilePath
    }

-- | The options and arguments of the command line.
parser :: Parser Config
parser = do
    lenient <-
        switch $
            long "lenient"
                <> help "Warn about syntax errors instead of failing"
    reference <-
        optional . strOption $
            long "reference"
                <> metavar "FILE"
                <> help "The file whose messages every file must match"
    files <- some1 . strArgument $ metavar "FILE" <> help "The files to check"
    pure Config{..}

parserInfo :: ParserInfo Config
parserInfo =
    info (helper <*> versioner <*> parser) . header $
        "Read Fluent files and validate their contents for errors or missing keys."
  where
    versioner = simpleVersioner $ "fluent-lint " <> showVersion Paths_fluent_lint.version

-- | Reads the command line.
get :: IO Config
get = execParser parserInfo