Skip to content

Commit

Permalink
feat (IO.Taskell/Data.Taskell.Lists): added -i option to analyse a ta…
Browse files Browse the repository at this point in the history
…skell file
  • Loading branch information
smallhadroncollider committed May 25, 2018
1 parent 15fb8f0 commit 5a0144e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/Data/Taskell/Lists.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ClassyPrelude hiding (empty)

import Data.Sequence as S ((!?), (|>), update, deleteAt)

import Data.Taskell.List (List(..), empty, extract, append, searchFor)
import Data.Taskell.List as L (List(..), empty, extract, append, searchFor, count)
import Data.Taskell.Task (Task)
import qualified Data.Taskell.Seq as S

Expand Down Expand Up @@ -57,3 +57,10 @@ appendToLast t ls = fromMaybe ls $ do
l <- ls !? i
let l' = append l t
return $ updateLists i ls l'

analyse :: Text -> Lists -> Text
analyse filepath ls = concat [
filepath , "\n"
, "Lists: ", tshow $ length ls, "\n"
, "Tasks: ", tshow $ foldl' (+) 0 (L.count <$> ls)
]
15 changes: 14 additions & 1 deletion src/IO/Taskell.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import System.Directory (getCurrentDirectory, doesFileExist)
import Data.FileEmbed (embedFile)

import Config (version, usage)
import Data.Taskell.Lists (Lists, initial)
import Data.Taskell.Lists (Lists, initial, analyse)
import IO.Config (Config, general, filename, token, trello)
import IO.Markdown (stringify, parse)
import IO.Trello (TrelloBoardID, getCards)
Expand All @@ -23,6 +23,7 @@ parseArgs :: [Text] -> ReaderConfig Next
parseArgs ["-v"] = return $ Output version
parseArgs ["-h"] = return $ Output usage
parseArgs ["-t", boardID, file] = loadTrello boardID file
parseArgs ["-i", file] = fileInfo file
parseArgs [file] = loadFile file
parseArgs [] = (pack . filename . general <$> ask) >>= loadFile
parseArgs _ = return $ Output (unlines ["Invalid options", "", usage])
Expand Down Expand Up @@ -50,6 +51,18 @@ loadTrello boardID filepath = do
then return $ Output (filepath ++ " already exists")
else createTrello boardID path

fileInfo :: Text -> ReaderConfig Next
fileInfo filepath = do
let path = unpack filepath
exists' <- fileExists path
if exists'
then do
content <- readData path
return $ case content of
Right lists -> Output $ analyse filepath lists
Left err -> Output $ pack path ++ ": " ++ err
else return Exit

createTrello :: TrelloBoardID -> FilePath -> ReaderConfig Next
createTrello boardID path = do
config <- ask
Expand Down
9 changes: 5 additions & 4 deletions templates/usage.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Usage: taskell ([options] | [-t <trello-board-id>] file)
Usage: taskell ([options] | [-i | -t <trello-board-id>] file)

Options:

-h Help
-v Version number
-t <trello-board-id> Create a new taskell file from the given Trello board ID
-h Help
-v Version number
-i file Display information about a file
-t <trello-board-id> file Create a new taskell file from the given Trello board ID
7 changes: 7 additions & 0 deletions test/Data/Taskell/ListsTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,11 @@ test_lists =
(appendToLast (T.new "Blah") empty)
)
]

, testCase "analyse" (
assertEqual
"Returns an analysis"
"test.md\nLists: 3\nTasks: 9"
(analyse "test.md" testLists)
)
]

0 comments on commit 5a0144e

Please sign in to comment.