From 477a86c18a2ef7fdff3d770578cff96b2fceb06b Mon Sep 17 00:00:00 2001 From: James Brechtel Date: Thu, 14 May 2026 10:34:36 -0400 Subject: [PATCH] Add --sync flag for one-shot sync-and-exit mode Useful for wake-from-sleep hooks: run 'converge --sync' to commit any pending changes, pull from remotes, and push, then exit. Shows 'Syncing N repo(s)' instead of 'Watching N repo(s)'. --- SPEC.md | 2 ++ app/Main.hs | 36 +++++++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/SPEC.md b/SPEC.md index 3a0f4fc..d8058e2 100644 --- a/SPEC.md +++ b/SPEC.md @@ -16,3 +16,5 @@ ## Supports configurable log levels (debug, info, warn, error) ## Supports logging to a file instead of stderr via --log-file or log_file config ## Can notify on pull: per-repo notify_on_pull setting sends a desktop notification when new commits are pulled from the remote + +## --sync / -s flag runs a single sync cycle (commit + pull + push) and exits, useful for wake-from-sleep hooks diff --git a/app/Main.hs b/app/Main.hs index 5bb1721..500050a 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -22,6 +22,8 @@ data CliArgs = CliArgs -- ^ Log level override. , cliLogFile :: !(Maybe FilePath) -- ^ Log file path. + , cliSync :: !Bool + -- ^ Run a single sync cycle and exit (useful for wake-from-sleep hooks). } cliParser :: Parser CliArgs @@ -87,6 +89,11 @@ cliParser = <> help "Write logs to a file instead of stderr" ) ) + <*> switch + ( long "sync" + <> short 's' + <> help "Run a single sync cycle (commit + pull + push) and exit" + ) parserInfo :: ParserInfo CliArgs parserInfo = @@ -134,15 +141,26 @@ main = do hPutStrLn stderr ("Using config: " <> path) Nothing -> hPutStrLn stderr "No config file found, using single-repo mode" - hPutStrLn stderr $ - "Watching " - <> show (length (optRepos options)) - <> " repo(s)" - <> " (debounce: " - <> show (optDebounceMs options) - <> "ms)" - mapM_ (\r -> hPutStrLn stderr (" - " <> rcPath r)) (optRepos options) - runConverge options + let repos = optRepos options + if cliSync cli + then do + hPutStrLn stderr $ + "Syncing " + <> show (length repos) + <> " repo(s)" + mapM_ (\r -> hPutStrLn stderr (" - " <> rcPath r)) repos + logger <- newLogger (optLogLevel options) (optLogFile options) + mapM_ (syncRepo options logger) repos + else do + hPutStrLn stderr $ + "Watching " + <> show (length repos) + <> " repo(s)" + <> " (debounce: " + <> show (optDebounceMs options) + <> "ms)" + mapM_ (\r -> hPutStrLn stderr (" - " <> rcPath r)) repos + runConverge options -- | Apply CLI overrides (debounce, log level, log file) to Options.