2024-04-25 22:21:55 +02:00
|
|
|
module Main where
|
|
|
|
|
|
|
|
import Data.Text as T
|
|
|
|
import Data.Text.IO as T
|
2024-05-28 23:46:09 +02:00
|
|
|
|
2024-04-25 22:21:55 +02:00
|
|
|
-- import Data.Time.Clock
|
|
|
|
import Data.Time.LocalTime
|
2024-05-28 23:46:09 +02:00
|
|
|
import NCDeck
|
2024-04-25 22:21:55 +02:00
|
|
|
import Options.Applicative
|
|
|
|
import System.IO
|
|
|
|
|
|
|
|
data Options = Options
|
|
|
|
{ hostname :: Text
|
|
|
|
, username :: Text
|
|
|
|
, cmd :: Command
|
|
|
|
}
|
|
|
|
|
|
|
|
data Command
|
|
|
|
= ListBoards
|
|
|
|
| ListStacks
|
2024-05-28 23:46:09 +02:00
|
|
|
{ boardId :: Word
|
|
|
|
}
|
2024-04-25 22:21:55 +02:00
|
|
|
| ListCards
|
2024-05-28 23:46:09 +02:00
|
|
|
{ boardId :: Word
|
|
|
|
, stackId :: Word
|
|
|
|
}
|
2024-04-25 22:21:55 +02:00
|
|
|
| CreateCard
|
2024-05-28 23:46:09 +02:00
|
|
|
{ boardId :: Word
|
|
|
|
, stackId :: Word
|
|
|
|
, title :: Text
|
|
|
|
, description :: Text
|
|
|
|
, date :: LocalTime
|
|
|
|
, weeklyRepeats :: Word
|
|
|
|
}
|
2024-04-25 22:21:55 +02:00
|
|
|
|
|
|
|
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
|
2024-05-28 23:46:09 +02:00
|
|
|
|
2024-04-25 22:21:55 +02:00
|
|
|
parseListStacks :: Parser Command
|
|
|
|
parseListStacks =
|
|
|
|
ListStacks
|
2024-05-28 23:46:09 +02:00
|
|
|
<$> option
|
|
|
|
auto
|
|
|
|
( long "board-id"
|
|
|
|
<> short 'b'
|
|
|
|
<> metavar "BOARD_ID"
|
|
|
|
<> help "the id of the kanban board"
|
|
|
|
)
|
2024-04-25 22:21:55 +02:00
|
|
|
|
|
|
|
parseListCards :: Parser Command
|
|
|
|
parseListCards =
|
|
|
|
ListCards
|
2024-05-28 23:46:09 +02:00
|
|
|
<$> 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"
|
|
|
|
)
|
2024-04-25 22:21:55 +02:00
|
|
|
|
|
|
|
parseCreateCard :: Parser Command
|
|
|
|
parseCreateCard =
|
|
|
|
CreateCard
|
2024-05-28 23:46:09 +02:00
|
|
|
<$> 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"
|
|
|
|
)
|
2024-04-25 22:21:55 +02:00
|
|
|
<*> strOption
|
2024-05-28 23:46:09 +02:00
|
|
|
( 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"
|
|
|
|
)
|
2024-04-25 22:21:55 +02:00
|
|
|
<*> strOption
|
2024-05-28 23:46:09 +02:00
|
|
|
( 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"
|
|
|
|
)
|
2024-04-25 22:21:55 +02:00
|
|
|
|
|
|
|
parseOptions :: Parser Options
|
|
|
|
parseOptions =
|
|
|
|
Options
|
|
|
|
<$> strOption
|
2024-05-28 23:46:09 +02:00
|
|
|
( long "hostname"
|
|
|
|
<> short 'o'
|
|
|
|
<> metavar "HOSTNAME"
|
|
|
|
<> help "the hostname of the Nextcloud instance"
|
|
|
|
)
|
2024-04-25 22:21:55 +02:00
|
|
|
<*> strOption
|
2024-05-28 23:46:09 +02:00
|
|
|
( long "username"
|
|
|
|
<> short 'u'
|
|
|
|
<> metavar "USERNAME"
|
|
|
|
<> help "the Nextcloud username"
|
|
|
|
)
|
2024-04-25 22:21:55 +02:00
|
|
|
<*> hsubparser
|
2024-05-28 23:47:23 +02:00
|
|
|
( command "list-boards" (info (pure ListBoards) (progDesc "list all boards"))
|
2024-05-28 23:46:09 +02:00
|
|
|
<> 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"))
|
|
|
|
)
|
|
|
|
|
2024-04-25 22:21:55 +02:00
|
|
|
main :: IO ()
|
|
|
|
main = run =<< execParser opts
|
|
|
|
where
|
2024-05-28 23:46:09 +02:00
|
|
|
opts =
|
|
|
|
info
|
|
|
|
(parseOptions <**> helper)
|
|
|
|
( fullDesc
|
|
|
|
<> progDesc "Manage a Nextcloud Deck"
|
|
|
|
<> header "ncdeck - Manage a Nextcloud Deck"
|
|
|
|
)
|