foliage/app/Foliage/Options.hs

114 lines
3.0 KiB
Haskell
Raw Normal View History

2022-03-11 11:10:49 +03:00
module Foliage.Options
( parseCommand,
Command (..),
BuildOptions (..),
2022-05-19 10:01:57 +03:00
ImportIndexOptions (..),
ImportFilter (..),
2022-03-09 16:29:23 +03:00
)
where
import Foliage.Time
2022-03-09 16:29:23 +03:00
import Options.Applicative
data Command
= CreateKeys FilePath
| Build BuildOptions
2022-05-19 10:01:57 +03:00
| ImportIndex ImportIndexOptions
parseCommand :: IO Command
parseCommand =
customExecParser
(prefs showHelpOnEmpty)
$ info
2022-03-09 16:29:23 +03:00
(optionsParser <**> helper)
( fullDesc
<> progDesc "foliage"
<> header "foliage - a builder for static Hackage repositories"
)
optionsParser :: Parser Command
2022-03-09 16:29:23 +03:00
optionsParser =
hsubparser $
command "create-keys" (info createKeysCommand (progDesc "Create TUF keys"))
<> command "build" (info buildCommand (progDesc "Build repository"))
2022-05-19 10:01:57 +03:00
<> command "import-index" (info importIndexCommand (progDesc "Import from Hackage index"))
2022-03-29 12:10:19 +03:00
data BuildOptions = BuildOptions
{ buildOptsKeysPath :: FilePath,
buildOptsCurrentTime :: Maybe UTCTime,
buildOptsInputDir :: FilePath,
buildOptsOutputDir :: FilePath
}
buildCommand :: Parser Command
buildCommand =
Build
<$> ( BuildOptions
<$> strOption
( long "keys"
<> metavar "KEYS"
<> help "TUF keys location"
<> showDefault
<> value "_keys"
)
<*> optional
( option
(maybeReader iso8601ParseM)
( long "current-time"
<> metavar "TIME"
<> help "Set current time"
<> showDefault
)
)
2022-03-29 12:10:19 +03:00
<*> strOption
( long "input-directory"
<> metavar "INPUT"
<> help "Repository input directory"
<> showDefault
<> value "_sources"
)
<*> strOption
( long "output-directory"
2022-03-29 12:10:19 +03:00
<> metavar "OUTPUT"
<> help "Repository output directory"
<> showDefault
<> value "_repo"
)
)
createKeysCommand :: Parser Command
createKeysCommand =
CreateKeys
2022-03-09 16:29:23 +03:00
<$> strOption
( long "keys"
<> metavar "KEYS"
<> help "TUF keys location"
<> showDefault
<> value "_keys"
)
data ImportFilter = ImportFilter String (Maybe String)
2022-05-19 10:01:57 +03:00
newtype ImportIndexOptions = ImportIndexOptions
{ importOptsFilter :: Maybe ImportFilter
}
2022-05-19 10:01:57 +03:00
importIndexCommand :: Parser Command
importIndexCommand =
ImportIndex . ImportIndexOptions
<$> optional
( ImportFilter
<$> strOption
( long "package-name"
<> metavar "NAME"
<> help "package name"
)
<*> optional
( strOption
( long "package-version"
<> metavar "VERSION"
<> help "package version"
)
)
)