summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Omni/Task.hs26
1 files changed, 26 insertions, 0 deletions
diff --git a/Omni/Task.hs b/Omni/Task.hs
index 13fc63c..a724e82 100644
--- a/Omni/Task.hs
+++ b/Omni/Task.hs
@@ -20,6 +20,7 @@ import qualified Omni.Test as Test
import qualified System.Console.Docopt as Docopt
import System.Directory (doesFileExist, removeFile)
import System.Environment (setEnv)
+import System.Process (readProcess)
import qualified Test.Tasty as Tasty
import Prelude (read)
@@ -54,6 +55,7 @@ Usage:
task stats [--epic=<id>] [--json]
task export [-o <file>]
task import -i <file>
+ task sync
task test
task (-h | --help)
@@ -71,6 +73,7 @@ Commands:
stats Show task statistics
export Export tasks to JSONL
import Import tasks from JSONL file
+ sync Export and commit task changes locally
test Run tests
Options:
@@ -373,6 +376,7 @@ move' args
Just f -> pure (T.pack f)
importTasks (T.unpack file)
putText <| "Imported tasks from " <> file
+ | args `Cli.has` Cli.command "sync" = syncTasks
| otherwise = putText (T.pack <| Cli.usage help)
where
getArgText :: Cli.Arguments -> String -> IO Text
@@ -382,6 +386,23 @@ move' args
Nothing -> panic (T.pack name <> " required")
Just val -> pure (T.pack val)
+syncTasks :: IO ()
+syncTasks = do
+ let jsonlPath = ".tasks/tasks.jsonl"
+ exportTasks (Just jsonlPath)
+ hasChanges <- checkGitChanges jsonlPath
+ if hasChanges
+ then do
+ _ <- readProcess "git" ["add", jsonlPath] ""
+ _ <- readProcess "git" ["commit", "-m", "task: sync task database"] ""
+ putText "Task changes committed locally."
+ else putText "No task changes to sync."
+ where
+ checkGitChanges :: FilePath -> IO Bool
+ checkGitChanges path = do
+ status <- readProcess "git" ["status", "--porcelain", path] ""
+ pure (not (null status))
+
test :: Test.Tree
test =
Test.group
@@ -793,6 +814,11 @@ cliTests =
Right args -> do
args `Cli.has` Cli.command "stats" Test.@?= True
Cli.getArg args (Cli.longOption "epic") Test.@?= Just "t-abc123",
+ Test.unit "sync command" <| do
+ let result = Docopt.parseArgs help ["sync"]
+ case result of
+ Left err -> Test.assertFailure <| "Failed to parse 'sync': " <> show err
+ Right args -> args `Cli.has` Cli.command "sync" Test.@?= True,
Test.unit "create with flags in different order" <| do
let result = Docopt.parseArgs help ["create", "Test", "--json", "--priority=1", "--namespace=Omni/Task"]
case result of