pilu/src/CLI.hs

48 lines
1.2 KiB
Haskell
Raw Normal View History

2019-04-07 18:08:22 +02:00
module CLI (
Invocation(..)
, Mode(..)
2019-04-07 18:08:22 +02:00
, invoked
) where
import Options.Applicative (
Parser, auto, execParser, flag, fullDesc, header, help, helper, info
, infoOption, long, option, short, value
2019-04-07 18:08:22 +02:00
)
import Control.Applicative ((<**>), optional)
import Data.Monoid ((<>))
import Data.Time (Day)
2019-04-07 18:08:22 +02:00
import Data.Version (showVersion)
import qualified Paths_pilu as Pilu (version)
data Mode = Inventory | Schedule
data Invocation = Invocation {
mode :: Mode
, date :: Maybe Day
}
2019-04-07 18:08:22 +02:00
versionStr :: String
versionStr = showVersion Pilu.version
version :: Parser (Invocation -> Invocation)
version =
infoOption versionStr
(short 'v' <> long "version" <> help "Show the version number")
2019-04-07 18:08:22 +02:00
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"
)
2019-04-07 18:08:22 +02:00
invoked :: IO Invocation
invoked = execParser $
info
(invocation <**> version <**> helper)
2019-04-07 18:08:22 +02:00
(fullDesc <> header ("Pilu v" ++ versionStr))