module Command ( Command(..) , execCommand ) where import Options.Applicative ( Parser , argument , command , execParser , fullDesc , help , helper , info , metavar , progDesc , str , subparser , (<**>) ) import Data.Text (Text) data Command = Start FilePath Text | Stop FilePath deriving Show commandParser :: Parser Command commandParser = subparser (startCommand <> stopCommand) where stopCommand = command "stop" (info (Stop <$> pathParser <**> helper) (progDesc "Stop the current running task")) startCommand = command "start" (info (Start <$> pathParser <*> taskParser <**> helper) (progDesc "Start a new task or replace existing")) taskParser = argument str (metavar "TASK" <> help "Name of the task in 'foo.bar' format") pathParser = argument str (metavar "FILE" <> help "Filepath with the clocking information") execCommand :: IO Command execCommand = execParser opts where opts = info (commandParser <**> helper) fullDesc