Skip to content

Commit 45ad3f3

Browse files
committed
Add new CLI command "tasklite json"
1 parent b17f480 commit 45ad3f3

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

tasklite-core/app/Main.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ data Command
108108
| ImportEml
109109
| IngestFile FilePath
110110
| Csv
111+
| Json
111112
| Ndjson
112113
| Sql
113114
| Backup
@@ -643,6 +644,9 @@ commandParser conf =
643644
(metavar "QUERY" <> help "The SQL query"))
644645
"Run any SQL query and show result as CSV")
645646

647+
<> command "json" (toParserInfo (pure Json)
648+
"Show tasks in JSON format")
649+
646650
<> command "ndjson" (toParserInfo (pure Ndjson)
647651
"Show tasks in NDJSON format")
648652

@@ -919,6 +923,7 @@ executeCLiCommand conf now connection = do
919923
ImportEml -> importEml conf connection
920924
IngestFile filePath -> ingestFile conf connection filePath
921925
Csv -> dumpCsv conf
926+
Json -> dumpJson conf
922927
Ndjson -> dumpNdjson conf
923928
Sql -> dumpSql conf
924929
Backup -> backupDatabase conf

tasklite-core/source/ImportExport.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,14 @@ dumpNdjson conf = do
481481
fmap (pretty . TL.decodeUtf8 . Aeson.encode) tasks
482482

483483

484+
dumpJson :: Config -> IO (Doc AnsiStyle)
485+
dumpJson conf = do
486+
-- TODO: Use Task instead of FullTask to fix broken notes export
487+
execWithConn conf $ \connection -> do
488+
tasks <- (query_ connection "select * from tasks_view") :: IO [FullTask]
489+
pure $ pretty $ fmap (TL.decodeUtf8 . Aeson.encode) tasks
490+
491+
484492
dumpSql :: Config -> IO (Doc AnsiStyle)
485493
dumpSql conf = do
486494
result <- readProcess "sqlite3"

0 commit comments

Comments
 (0)