2022-09-19 16:33:50 +03:00
|
|
|
{-# LANGUAGE DeriveAnyClass #-}
|
|
|
|
{-# LANGUAGE DeriveGeneric #-}
|
|
|
|
{-# LANGUAGE DerivingStrategies #-}
|
|
|
|
|
2022-03-11 11:10:49 +03:00
|
|
|
module Foliage.Options
|
2022-03-28 07:53:39 +03:00
|
|
|
( parseCommand,
|
|
|
|
Command (..),
|
|
|
|
BuildOptions (..),
|
2022-09-19 16:33:50 +03:00
|
|
|
SignOptions (..),
|
2022-05-19 10:01:57 +03:00
|
|
|
ImportIndexOptions (..),
|
|
|
|
ImportFilter (..),
|
2022-03-09 16:29:23 +03:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
2022-09-19 16:33:50 +03:00
|
|
|
import Development.Shake.Classes (Binary, Hashable, NFData)
|
2022-03-28 07:53:39 +03:00
|
|
|
import Foliage.Time
|
2022-09-19 16:33:50 +03:00
|
|
|
import GHC.Generics
|
2022-03-09 16:29:23 +03:00
|
|
|
import Options.Applicative
|
|
|
|
|
2022-03-28 07:53:39 +03:00
|
|
|
data Command
|
|
|
|
= CreateKeys FilePath
|
|
|
|
| Build BuildOptions
|
2022-05-19 10:01:57 +03:00
|
|
|
| ImportIndex ImportIndexOptions
|
2022-03-28 07:53:39 +03:00
|
|
|
|
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2022-03-28 07:53:39 +03:00
|
|
|
optionsParser :: Parser Command
|
2022-03-09 16:29:23 +03:00
|
|
|
optionsParser =
|
2022-03-28 07:53:39 +03:00
|
|
|
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-28 07:53:39 +03:00
|
|
|
|
2022-09-19 16:33:50 +03:00
|
|
|
data SignOptions
|
|
|
|
= SignOptsSignWithKeys FilePath
|
|
|
|
| SignOptsDon'tSign
|
|
|
|
deriving (Show, Eq, Generic)
|
|
|
|
deriving anyclass (Binary, Hashable, NFData)
|
|
|
|
|
2022-03-29 12:10:19 +03:00
|
|
|
data BuildOptions = BuildOptions
|
2022-09-19 16:33:50 +03:00
|
|
|
{ buildOptsSignOpts :: SignOptions,
|
2022-03-29 12:10:19 +03:00
|
|
|
buildOptsCurrentTime :: Maybe UTCTime,
|
2022-06-08 05:39:46 +03:00
|
|
|
buildOptsExpireSignaturesOn :: Maybe UTCTime,
|
2022-03-29 12:10:19 +03:00
|
|
|
buildOptsInputDir :: FilePath,
|
2022-12-16 18:15:40 +03:00
|
|
|
buildOptsOutputDir :: FilePath,
|
2023-02-14 05:29:16 +03:00
|
|
|
buildOptsNumThreads :: Int,
|
|
|
|
buildOptsWriteMetadata :: Bool
|
2022-03-29 12:10:19 +03:00
|
|
|
}
|
2022-03-28 07:53:39 +03:00
|
|
|
|
|
|
|
buildCommand :: Parser Command
|
|
|
|
buildCommand =
|
|
|
|
Build
|
|
|
|
<$> ( BuildOptions
|
2022-09-19 16:33:50 +03:00
|
|
|
<$> signOpts
|
2022-03-28 07:53:39 +03:00
|
|
|
<*> optional
|
|
|
|
( option
|
|
|
|
(maybeReader iso8601ParseM)
|
|
|
|
( long "current-time"
|
|
|
|
<> metavar "TIME"
|
|
|
|
<> help "Set current time"
|
|
|
|
<> showDefault
|
|
|
|
)
|
|
|
|
)
|
2022-06-08 05:39:46 +03:00
|
|
|
<*> optional
|
|
|
|
( option
|
|
|
|
(maybeReader iso8601ParseM)
|
|
|
|
( long "expire-signatures-on"
|
|
|
|
<> metavar "TIME"
|
|
|
|
<> help "Set an expiry date on TUF signatures"
|
|
|
|
)
|
|
|
|
)
|
2022-03-29 12:10:19 +03:00
|
|
|
<*> strOption
|
|
|
|
( long "input-directory"
|
|
|
|
<> metavar "INPUT"
|
|
|
|
<> help "Repository input directory"
|
|
|
|
<> showDefault
|
|
|
|
<> value "_sources"
|
|
|
|
)
|
2022-03-28 07:53:39 +03:00
|
|
|
<*> strOption
|
|
|
|
( long "output-directory"
|
2022-03-29 12:10:19 +03:00
|
|
|
<> metavar "OUTPUT"
|
2022-03-28 07:53:39 +03:00
|
|
|
<> help "Repository output directory"
|
|
|
|
<> showDefault
|
|
|
|
<> value "_repo"
|
|
|
|
)
|
2022-12-16 18:15:40 +03:00
|
|
|
<*> option
|
|
|
|
auto
|
|
|
|
( long "num-jobs"
|
|
|
|
<> short 'j'
|
|
|
|
<> metavar "JOBS"
|
|
|
|
<> help "Number of jobs to run in parallel, 0 is 'all available cores'"
|
|
|
|
<> showDefault
|
|
|
|
<> value 1
|
|
|
|
)
|
2023-02-14 05:29:16 +03:00
|
|
|
<*> switch
|
|
|
|
( long "write-metadata"
|
|
|
|
<> help "Write metadata in the output-directory"
|
|
|
|
<> showDefault
|
|
|
|
)
|
2022-03-28 07:53:39 +03:00
|
|
|
)
|
2022-09-19 16:33:50 +03:00
|
|
|
where
|
|
|
|
signOpts =
|
|
|
|
( SignOptsSignWithKeys
|
|
|
|
<$> strOption
|
|
|
|
( long "keys"
|
|
|
|
<> metavar "KEYS"
|
|
|
|
<> help "TUF keys location"
|
|
|
|
<> showDefault
|
|
|
|
<> value "_keys"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
<|> ( SignOptsDon'tSign
|
|
|
|
<$ switch (long "no-signatures" <> help "Don't sign the repository")
|
|
|
|
)
|
2022-03-28 07:53:39 +03:00
|
|
|
|
|
|
|
createKeysCommand :: Parser Command
|
|
|
|
createKeysCommand =
|
|
|
|
CreateKeys
|
2022-03-09 16:29:23 +03:00
|
|
|
<$> strOption
|
2022-03-16 11:49:26 +03:00
|
|
|
( long "keys"
|
|
|
|
<> metavar "KEYS"
|
2022-03-28 07:53:39 +03:00
|
|
|
<> help "TUF keys location"
|
2022-03-16 11:49:26 +03:00
|
|
|
<> showDefault
|
|
|
|
<> value "_keys"
|
|
|
|
)
|
|
|
|
|
2022-03-30 06:17:22 +03:00
|
|
|
data ImportFilter = ImportFilter String (Maybe String)
|
|
|
|
|
2022-05-19 10:01:57 +03:00
|
|
|
newtype ImportIndexOptions = ImportIndexOptions
|
2022-03-30 06:17:22 +03:00
|
|
|
{ importOptsFilter :: Maybe ImportFilter
|
|
|
|
}
|
2022-03-28 07:53:39 +03:00
|
|
|
|
2022-05-19 10:01:57 +03:00
|
|
|
importIndexCommand :: Parser Command
|
|
|
|
importIndexCommand =
|
|
|
|
ImportIndex . ImportIndexOptions
|
2022-03-28 07:53:39 +03:00
|
|
|
<$> optional
|
2022-03-30 06:17:22 +03:00
|
|
|
( ImportFilter
|
|
|
|
<$> strOption
|
|
|
|
( long "package-name"
|
|
|
|
<> metavar "NAME"
|
|
|
|
<> help "package name"
|
|
|
|
)
|
|
|
|
<*> optional
|
|
|
|
( strOption
|
|
|
|
( long "package-version"
|
|
|
|
<> metavar "VERSION"
|
|
|
|
<> help "package version"
|
|
|
|
)
|
|
|
|
)
|
2022-03-28 07:53:39 +03:00
|
|
|
)
|