pilu/src/CLI.hs

48 lines
1.2 KiB
Haskell

module CLI (
Invocation(..)
, Mode(..)
, invoked
) where
import Options.Applicative (
Parser, auto, execParser, flag, fullDesc, header, help, helper, info
, infoOption, long, option, short, value
)
import Control.Applicative ((<**>), optional)
import Data.Monoid ((<>))
import Data.Time (Day)
import Data.Version (showVersion)
import qualified Paths_pilu as Pilu (version)
data Mode = Inventory | Schedule
data Invocation = Invocation {
mode :: Mode
, date :: Maybe Day
}
versionStr :: String
versionStr = showVersion Pilu.version
version :: Parser (Invocation -> Invocation)
version =
infoOption versionStr
(short 'v' <> long "version" <> help "Show the version number")
invocation :: Parser Invocation
invocation = Invocation
<$> flag Schedule Inventory
(short 'i' <> long "inventory" <> help "Show a full inventory")
<*> option (optional auto) (
value Nothing
<> short 'd'
<> long "date"
<> help "Evaluate the situation at that date"
)
invoked :: IO Invocation
invoked = execParser $
info
(invocation <**> version <**> helper)
(fullDesc <> header ("Pilu v" ++ versionStr))