add fourmolu config; reformat using fourmolu
This commit is contained in:
parent
dfe275eedf
commit
74f96dc563
31
app/Main.hs
31
app/Main.hs
|
@ -2,11 +2,12 @@ module Main where
|
||||||
|
|
||||||
import Data.Text as T
|
import Data.Text as T
|
||||||
import Data.Text.IO as T
|
import Data.Text.IO as T
|
||||||
|
|
||||||
-- import Data.Time.Clock
|
-- import Data.Time.Clock
|
||||||
import Data.Time.LocalTime
|
import Data.Time.LocalTime
|
||||||
|
import NCDeck
|
||||||
import Options.Applicative
|
import Options.Applicative
|
||||||
import System.IO
|
import System.IO
|
||||||
import NCDeck
|
|
||||||
|
|
||||||
data Options = Options
|
data Options = Options
|
||||||
{ hostname :: Text
|
{ hostname :: Text
|
||||||
|
@ -55,7 +56,8 @@ run (Options {..}) = do
|
||||||
parseListStacks :: Parser Command
|
parseListStacks :: Parser Command
|
||||||
parseListStacks =
|
parseListStacks =
|
||||||
ListStacks
|
ListStacks
|
||||||
<$> option auto
|
<$> option
|
||||||
|
auto
|
||||||
( long "board-id"
|
( long "board-id"
|
||||||
<> short 'b'
|
<> short 'b'
|
||||||
<> metavar "BOARD_ID"
|
<> metavar "BOARD_ID"
|
||||||
|
@ -65,13 +67,15 @@ parseListStacks =
|
||||||
parseListCards :: Parser Command
|
parseListCards :: Parser Command
|
||||||
parseListCards =
|
parseListCards =
|
||||||
ListCards
|
ListCards
|
||||||
<$> option auto
|
<$> option
|
||||||
|
auto
|
||||||
( long "board-id"
|
( long "board-id"
|
||||||
<> short 'b'
|
<> short 'b'
|
||||||
<> metavar "BOARD_ID"
|
<> metavar "BOARD_ID"
|
||||||
<> help "the id of the kanban board"
|
<> help "the id of the kanban board"
|
||||||
)
|
)
|
||||||
<*> option auto
|
<*> option
|
||||||
|
auto
|
||||||
( long "stack-id"
|
( long "stack-id"
|
||||||
<> short 's'
|
<> short 's'
|
||||||
<> metavar "STACK_ID"
|
<> metavar "STACK_ID"
|
||||||
|
@ -81,13 +85,15 @@ parseListCards =
|
||||||
parseCreateCard :: Parser Command
|
parseCreateCard :: Parser Command
|
||||||
parseCreateCard =
|
parseCreateCard =
|
||||||
CreateCard
|
CreateCard
|
||||||
<$> option auto
|
<$> option
|
||||||
|
auto
|
||||||
( long "board-id"
|
( long "board-id"
|
||||||
<> short 'b'
|
<> short 'b'
|
||||||
<> metavar "BOARD_ID"
|
<> metavar "BOARD_ID"
|
||||||
<> help "the id of the kanban board"
|
<> help "the id of the kanban board"
|
||||||
)
|
)
|
||||||
<*> option auto
|
<*> option
|
||||||
|
auto
|
||||||
( long "stack-id"
|
( long "stack-id"
|
||||||
<> short 's'
|
<> short 's'
|
||||||
<> metavar "STACK_ID"
|
<> metavar "STACK_ID"
|
||||||
|
@ -107,19 +113,22 @@ parseCreateCard =
|
||||||
<> showDefault
|
<> showDefault
|
||||||
<> help "the card's description"
|
<> help "the card's description"
|
||||||
)
|
)
|
||||||
<*> option auto
|
<*> option
|
||||||
|
auto
|
||||||
( long "date" -- FIXME: make this optional?
|
( long "date" -- FIXME: make this optional?
|
||||||
<> short 'e'
|
<> short 'e'
|
||||||
<> metavar "DATE"
|
<> metavar "DATE"
|
||||||
<> help "the card's date, format: YYYY-MM-DD hh:mm:ss"
|
<> help "the card's date, format: YYYY-MM-DD hh:mm:ss"
|
||||||
)
|
)
|
||||||
<*> option auto
|
<*> option
|
||||||
|
auto
|
||||||
( long "weekly-repeats"
|
( long "weekly-repeats"
|
||||||
<> short 'w'
|
<> short 'w'
|
||||||
<> metavar "COUNT"
|
<> metavar "COUNT"
|
||||||
<> value 0
|
<> value 0
|
||||||
<> showDefault
|
<> showDefault
|
||||||
<> help "repeat the card weekly COUNT times")
|
<> help "repeat the card weekly COUNT times"
|
||||||
|
)
|
||||||
|
|
||||||
parseOptions :: Parser Options
|
parseOptions :: Parser Options
|
||||||
parseOptions =
|
parseOptions =
|
||||||
|
@ -146,7 +155,9 @@ parseOptions =
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = run =<< execParser opts
|
main = run =<< execParser opts
|
||||||
where
|
where
|
||||||
opts = info (parseOptions <**> helper)
|
opts =
|
||||||
|
info
|
||||||
|
(parseOptions <**> helper)
|
||||||
( fullDesc
|
( fullDesc
|
||||||
<> progDesc "Manage a Nextcloud Deck"
|
<> progDesc "Manage a Nextcloud Deck"
|
||||||
<> header "ncdeck - Manage a Nextcloud Deck"
|
<> header "ncdeck - Manage a Nextcloud Deck"
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
indentation: 2
|
||||||
|
column-limit: none
|
||||||
|
function-arrows: leading
|
||||||
|
comma-style: leading
|
||||||
|
import-export-style: leading
|
||||||
|
indent-wheres: true
|
||||||
|
record-brace-space: true
|
||||||
|
newline-between-decls: true
|
||||||
|
haddock-style: multi-line
|
||||||
|
haddock-style-module: null
|
||||||
|
let-style: newline
|
||||||
|
in-style: left-align
|
||||||
|
single-constraint-parens: always
|
||||||
|
single-deriving-parens: always
|
||||||
|
unicode: never
|
||||||
|
respectful: true
|
109
src/NCDeck.hs
109
src/NCDeck.hs
|
@ -8,21 +8,23 @@ module NCDeck
|
||||||
, createCard
|
, createCard
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Prelude hiding (id)
|
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Text as T
|
import Data.Text qualified as T
|
||||||
import qualified Data.Text.Encoding as T
|
import Data.Text.Encoding qualified as T
|
||||||
|
import Prelude hiding (id)
|
||||||
|
|
||||||
-- import Data.Time.Clock
|
-- import Data.Time.Clock
|
||||||
import Data.Time.LocalTime
|
|
||||||
|
import Control.Monad
|
||||||
|
import Control.Monad.IO.Class
|
||||||
import Data.Time.Calendar
|
import Data.Time.Calendar
|
||||||
import Data.Time.Calendar.OrdinalDate
|
import Data.Time.Calendar.OrdinalDate
|
||||||
import Data.Time.Clock.POSIX (POSIXTime)
|
import Data.Time.Clock.POSIX (POSIXTime)
|
||||||
|
import Data.Time.LocalTime
|
||||||
import GHC.Generics
|
import GHC.Generics
|
||||||
import Network.HTTP.Req
|
import Network.HTTP.Req
|
||||||
import Control.Monad
|
|
||||||
import Control.Monad.IO.Class
|
|
||||||
|
|
||||||
data Board = Board
|
data Board = Board
|
||||||
{ id :: Int
|
{ id :: Int
|
||||||
|
@ -30,7 +32,8 @@ data Board = Board
|
||||||
, deletedAt :: POSIXTime
|
, deletedAt :: POSIXTime
|
||||||
, lastModified :: POSIXTime
|
, lastModified :: POSIXTime
|
||||||
, archived :: Bool
|
, archived :: Bool
|
||||||
} deriving Generic
|
}
|
||||||
|
deriving (Generic)
|
||||||
|
|
||||||
data Stack = Stack
|
data Stack = Stack
|
||||||
{ id :: Int
|
{ id :: Int
|
||||||
|
@ -39,38 +42,58 @@ data Stack = Stack
|
||||||
, deletedAt :: POSIXTime
|
, deletedAt :: POSIXTime
|
||||||
, lastModified :: POSIXTime
|
, lastModified :: POSIXTime
|
||||||
, cards :: Maybe [Card]
|
, cards :: Maybe [Card]
|
||||||
} deriving Generic
|
}
|
||||||
|
deriving (Generic)
|
||||||
|
|
||||||
data Card = Card
|
data Card = Card
|
||||||
{ id :: Int
|
{ id :: Int
|
||||||
, title :: Text
|
, title :: Text
|
||||||
, description :: Text
|
, description :: Text
|
||||||
, duedate :: Maybe LocalTime
|
, duedate :: Maybe LocalTime
|
||||||
} deriving Generic
|
}
|
||||||
|
deriving (Generic)
|
||||||
|
|
||||||
instance FromJSON Board
|
instance FromJSON Board
|
||||||
|
|
||||||
instance Show Board where
|
instance Show Board where
|
||||||
show :: Board -> String
|
show :: Board -> String
|
||||||
show (Board {..}) =
|
show (Board {..}) =
|
||||||
T.unpack title <> "\n" <>
|
T.unpack title
|
||||||
"------------------------------------------------------\n" <>
|
<> "\n"
|
||||||
"id:\t\t" <> show id <> "\n" <>
|
<> "------------------------------------------------------\n"
|
||||||
"last modified:\t" <> show lastModified <> "\n" <>
|
<> "id:\t\t"
|
||||||
"deleted at:\t" <> show deletedAt <> "\n" <>
|
<> show id
|
||||||
"archived: \t" <> show archived <> "\n"
|
<> "\n"
|
||||||
|
<> "last modified:\t"
|
||||||
|
<> show lastModified
|
||||||
|
<> "\n"
|
||||||
|
<> "deleted at:\t"
|
||||||
|
<> show deletedAt
|
||||||
|
<> "\n"
|
||||||
|
<> "archived: \t"
|
||||||
|
<> show archived
|
||||||
|
<> "\n"
|
||||||
|
|
||||||
instance FromJSON Stack
|
instance FromJSON Stack
|
||||||
|
|
||||||
instance Show Stack where
|
instance Show Stack where
|
||||||
show :: Stack -> String
|
show :: Stack -> String
|
||||||
show (Stack {..}) =
|
show (Stack {..}) =
|
||||||
T.unpack title <> "\n" <>
|
T.unpack title
|
||||||
"------------------------------------------------------\n" <>
|
<> "\n"
|
||||||
"id:\t\t" <> show id <> "\n" <>
|
<> "------------------------------------------------------\n"
|
||||||
"last modified:\t" <> show lastModified <> "\n" <>
|
<> "id:\t\t"
|
||||||
"deleted at:\t" <> show deletedAt <> "\n" <>
|
<> show id
|
||||||
"#cards: \t" <> show (length cards) <> "\n"
|
<> "\n"
|
||||||
|
<> "last modified:\t"
|
||||||
|
<> show lastModified
|
||||||
|
<> "\n"
|
||||||
|
<> "deleted at:\t"
|
||||||
|
<> show deletedAt
|
||||||
|
<> "\n"
|
||||||
|
<> "#cards: \t"
|
||||||
|
<> show (length cards)
|
||||||
|
<> "\n"
|
||||||
|
|
||||||
instance FromJSON Card
|
instance FromJSON Card
|
||||||
|
|
||||||
|
@ -81,15 +104,23 @@ instance Show Card where
|
||||||
desc = T.unpack $ truncateDesc description
|
desc = T.unpack $ truncateDesc description
|
||||||
dd = maybe "None" show duedate
|
dd = maybe "None" show duedate
|
||||||
in
|
in
|
||||||
T.unpack title <> "\n" <>
|
T.unpack title
|
||||||
"----------------------------------------------------\n" <>
|
<> "\n"
|
||||||
"id:\t\t" <> show id <> "\n" <>
|
<> "----------------------------------------------------\n"
|
||||||
"description: \t" <> desc <> "\n" <>
|
<> "id:\t\t"
|
||||||
"due date: \t" <> dd <> "\n"
|
<> show id
|
||||||
|
<> "\n"
|
||||||
|
<> "description: \t"
|
||||||
|
<> desc
|
||||||
|
<> "\n"
|
||||||
|
<> "due date: \t"
|
||||||
|
<> dd
|
||||||
|
<> "\n"
|
||||||
where
|
where
|
||||||
truncateDesc :: Text -> Text
|
truncateDesc :: Text -> Text
|
||||||
truncateDesc input =
|
truncateDesc input =
|
||||||
let (fstLine, _) = T.break (== '\n') input
|
let
|
||||||
|
(fstLine, _) = T.break (== '\n') input
|
||||||
in
|
in
|
||||||
if T.length fstLine > 30
|
if T.length fstLine > 30
|
||||||
then T.take 30 fstLine <> "..."
|
then T.take 30 fstLine <> "..."
|
||||||
|
@ -100,7 +131,8 @@ authHeaders username password =
|
||||||
let
|
let
|
||||||
usernameBS = T.encodeUtf8 username
|
usernameBS = T.encodeUtf8 username
|
||||||
passwordBS = T.encodeUtf8 password
|
passwordBS = T.encodeUtf8 password
|
||||||
in header "OCS-APIRequest" "true" <> basicAuth usernameBS passwordBS
|
in
|
||||||
|
header "OCS-APIRequest" "true" <> basicAuth usernameBS passwordBS
|
||||||
|
|
||||||
baseUrl :: Text -> Url Https
|
baseUrl :: Text -> Url Https
|
||||||
baseUrl hostname =
|
baseUrl hostname =
|
||||||
|
@ -111,7 +143,8 @@ listBoards hostname username password =
|
||||||
let
|
let
|
||||||
headers = authHeaders username password
|
headers = authHeaders username password
|
||||||
url = baseUrl hostname /: "boards"
|
url = baseUrl hostname /: "boards"
|
||||||
in runReq defaultHttpConfig $ do
|
in
|
||||||
|
runReq defaultHttpConfig $ do
|
||||||
response <- req GET url NoReqBody jsonResponse headers
|
response <- req GET url NoReqBody jsonResponse headers
|
||||||
return $ responseBody response
|
return $ responseBody response
|
||||||
|
|
||||||
|
@ -120,7 +153,8 @@ listStacks hostname username password boardId =
|
||||||
let
|
let
|
||||||
headers = authHeaders username password
|
headers = authHeaders username password
|
||||||
url = baseUrl hostname /: "boards" /: T.pack (show boardId) /: "stacks"
|
url = baseUrl hostname /: "boards" /: T.pack (show boardId) /: "stacks"
|
||||||
in runReq defaultHttpConfig $ do
|
in
|
||||||
|
runReq defaultHttpConfig $ do
|
||||||
response <- req GET url NoReqBody jsonResponse headers
|
response <- req GET url NoReqBody jsonResponse headers
|
||||||
return $ responseBody response
|
return $ responseBody response
|
||||||
|
|
||||||
|
@ -129,9 +163,11 @@ listCards hostname username password boardId stackId =
|
||||||
let
|
let
|
||||||
headers = authHeaders username password
|
headers = authHeaders username password
|
||||||
url = baseUrl hostname /: "boards" /: T.pack (show boardId) /: "stacks" /: T.pack (show stackId)
|
url = baseUrl hostname /: "boards" /: T.pack (show boardId) /: "stacks" /: T.pack (show stackId)
|
||||||
in runReq defaultHttpConfig $ do
|
in
|
||||||
|
runReq defaultHttpConfig $ do
|
||||||
response <- req GET url NoReqBody jsonResponse headers
|
response <- req GET url NoReqBody jsonResponse headers
|
||||||
let stack :: Stack = responseBody response
|
let
|
||||||
|
stack :: Stack = responseBody response
|
||||||
return $ fromMaybe [] stack.cards
|
return $ fromMaybe [] stack.cards
|
||||||
|
|
||||||
createCard :: Text -> Text -> Text -> Word -> Word -> Text -> Text -> LocalTime -> Word -> IO ()
|
createCard :: Text -> Text -> Text -> Word -> Word -> Text -> Text -> LocalTime -> Word -> IO ()
|
||||||
|
@ -143,10 +179,11 @@ createCard hostname username password boardId stackId title description date wee
|
||||||
(_, dayOfYear) = toOrdinalDate date.localDay
|
(_, dayOfYear) = toOrdinalDate date.localDay
|
||||||
(year, month, day) = toGregorian date.localDay
|
(year, month, day) = toGregorian date.localDay
|
||||||
expandedTitle =
|
expandedTitle =
|
||||||
T.replace "%YY" (T.pack $ show year) $
|
T.replace "%YY" (T.pack $ show year)
|
||||||
T.replace "%MM" (T.pack $ show month) $
|
$ T.replace "%MM" (T.pack $ show month)
|
||||||
T.replace "%DD" (T.pack $ show day) title
|
$ T.replace "%DD" (T.pack $ show day) title
|
||||||
body = object
|
body =
|
||||||
|
object
|
||||||
[ "title" .= expandedTitle
|
[ "title" .= expandedTitle
|
||||||
, "type" .= ("plain" :: Text)
|
, "type" .= ("plain" :: Text)
|
||||||
, "order" .= dayOfYear
|
, "order" .= dayOfYear
|
||||||
|
|
Loading…
Reference in New Issue