Use XDG config directory as default config path
- Look for config at $XDG_CONFIG_HOME/converge/config.yaml by default - --config still overrides to an explicit path - Falls back to single-repo --repo mode if no config file found - New defaultConfigPath and configFileExists helpers in Converge module
This commit is contained in:
+34
-17
@@ -76,27 +76,40 @@ main :: IO ()
|
||||
main = do
|
||||
cli <- execParser parserInfo
|
||||
let mDebounceOverride = cliDebounce cli
|
||||
options <- case cliConfig cli of
|
||||
(options, configSource) <- case cliConfig cli of
|
||||
Just cfgPath -> do
|
||||
cfg <- loadConfig cfgPath
|
||||
let opts = configToOptions cfg
|
||||
pure $ case mDebounceOverride of
|
||||
Just ms -> opts{optDebounceMs = ms}
|
||||
Nothing -> opts
|
||||
Nothing ->
|
||||
pure $
|
||||
defaultOptions
|
||||
{ optRepos =
|
||||
[ defaultRepoConfig
|
||||
{ rcPath = fromMaybe "." (cliRepo cli)
|
||||
, rcRemote = cliRemote cli
|
||||
, rcBranch = cliBranch cli
|
||||
let opts = applyDebounce mDebounceOverride (configToOptions cfg)
|
||||
pure (opts, Just cfgPath)
|
||||
Nothing -> do
|
||||
exists <- configFileExists
|
||||
if exists
|
||||
then do
|
||||
cfgPath <- defaultConfigPath
|
||||
cfg <- loadConfig cfgPath
|
||||
let opts = applyDebounce mDebounceOverride (configToOptions cfg)
|
||||
pure (opts, Just cfgPath)
|
||||
else
|
||||
pure
|
||||
( defaultOptions
|
||||
{ optRepos =
|
||||
[ defaultRepoConfig
|
||||
{ rcPath = fromMaybe "." (cliRepo cli)
|
||||
, rcRemote = cliRemote cli
|
||||
, rcBranch = cliBranch cli
|
||||
}
|
||||
]
|
||||
, optDebounceMs = fromMaybe 5000 mDebounceOverride
|
||||
}
|
||||
]
|
||||
, optDebounceMs = fromMaybe 5000 mDebounceOverride
|
||||
}
|
||||
, Nothing
|
||||
)
|
||||
case configSource of
|
||||
Just path ->
|
||||
hPutStrLn stderr ("Using config: " <> path)
|
||||
Nothing ->
|
||||
hPutStrLn stderr "No config file found, using single-repo mode"
|
||||
hPutStrLn stderr $
|
||||
"Converge watching "
|
||||
"Watching "
|
||||
<> show (length (optRepos options))
|
||||
<> " repo(s)"
|
||||
<> " (debounce: "
|
||||
@@ -104,3 +117,7 @@ main = do
|
||||
<> "ms)"
|
||||
mapM_ (\r -> hPutStrLn stderr (" - " <> rcPath r)) (optRepos options)
|
||||
runConverge options
|
||||
|
||||
applyDebounce :: Maybe Int -> Options -> Options
|
||||
applyDebounce (Just ms) opts = opts{optDebounceMs = ms}
|
||||
applyDebounce Nothing opts = opts
|
||||
|
||||
Reference in New Issue
Block a user