module Main where import Data.Text as T import Data.Text.IO as T -- import Data.Time.Clock import Data.Time.LocalTime import NCDeck import Options.Applicative import System.IO data Options = Options { hostname :: Text , username :: Text , cmd :: Command } data Command = ListBoards | ListStacks { boardId :: Word } | ListCards { boardId :: Word , stackId :: Word } | CreateCard { boardId :: Word , stackId :: Word , title :: Text , description :: Text , date :: LocalTime , weeklyRepeats :: Word } run :: Options -> IO () run (Options {..}) = do hSetBuffering stdout NoBuffering hSetEcho stdin False T.putStr "Please enter the password: " password <- T.getLine T.putStrLn $ T.replicate (T.length password) "*" case cmd of ListBoards -> do boards <- listBoards hostname username password mapM_ print boards ListStacks {..} -> do stacks <- listStacks hostname username password boardId mapM_ print stacks ListCards {..} -> do cards <- listCards hostname username password boardId stackId mapM_ print cards CreateCard {..} -> do createCard hostname username password boardId stackId title description date weeklyRepeats parseListStacks :: Parser Command parseListStacks = ListStacks <$> option auto ( long "board-id" <> short 'b' <> metavar "BOARD_ID" <> help "the id of the kanban board" ) parseListCards :: Parser Command parseListCards = ListCards <$> option auto ( long "board-id" <> short 'b' <> metavar "BOARD_ID" <> help "the id of the kanban board" ) <*> option auto ( long "stack-id" <> short 's' <> metavar "STACK_ID" <> help "the id of the kanban stack" ) parseCreateCard :: Parser Command parseCreateCard = CreateCard <$> option auto ( long "board-id" <> short 'b' <> metavar "BOARD_ID" <> help "the id of the kanban board" ) <*> option auto ( long "stack-id" <> short 's' <> metavar "STACK_ID" <> help "the id of the kanban stack" ) <*> strOption ( long "title" <> short 't' <> metavar "TITLE" <> help "the card's title; the card's date can be included using the placeholders %YY, %MM and %DD" ) <*> strOption ( long "description" <> short 'd' <> metavar "DESC" <> value "" <> showDefault <> help "the card's description" ) <*> option auto ( long "date" -- FIXME: make this optional? <> short 'e' <> metavar "DATE" <> help "the card's date, format: YYYY-MM-DD hh:mm:ss" ) <*> option auto ( long "weekly-repeats" <> short 'w' <> metavar "COUNT" <> value 0 <> showDefault <> help "repeat the card weekly COUNT times" ) parseOptions :: Parser Options parseOptions = Options <$> strOption ( long "hostname" <> short 'o' <> metavar "HOSTNAME" <> help "the hostname of the Nextcloud instance" ) <*> strOption ( long "username" <> short 'u' <> metavar "USERNAME" <> help "the Nextcloud username" ) <*> hsubparser ( command "list-boards" (info (pure ListBoards) (progDesc "list all boards")) <> command "list-stacks" (info parseListStacks (progDesc "list all stacks")) <> command "list-cards" (info parseListCards (progDesc "list all cards")) <> command "create-card" (info parseCreateCard (progDesc "create a new card")) ) main :: IO () main = run =<< execParser opts where opts = info (parseOptions <**> helper) ( fullDesc <> progDesc "Manage a Nextcloud Deck" <> header "ncdeck - Manage a Nextcloud Deck" )