aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--anissue.cabal5
-rw-r--r--app/Main.hs2
-rw-r--r--app/Settings.hs43
3 files changed, 49 insertions, 1 deletions
diff --git a/anissue.cabal b/anissue.cabal
index fbf2485..188a418 100644
--- a/anissue.cabal
+++ b/anissue.cabal
@@ -85,6 +85,7 @@ executable anissue
Issue.TypedValue
Parallel
Process
+ Settings
TreeGrepper.FileType
TreeGrepper.Match
TreeGrepper.Result
@@ -108,7 +109,9 @@ executable anissue
terminal-size,
text,
time,
- typed-process
+ typed-process,
+ xdg-basedir,
+ yaml
-- Directories containing source files.
hs-source-dirs: app
diff --git a/app/Main.hs b/app/Main.hs
index 274bfa4..3e9dc1d 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -459,6 +459,7 @@ import Prettyprinter ((<+>))
import Prettyprinter qualified as P
import Prettyprinter.Render.Terminal qualified as P
import Process (proc, sh_, textInput)
+import Settings (Settings (..), readSettings)
import System.Console.Terminal.Size qualified as Terminal
import System.Exit (ExitCode (ExitFailure), exitWith)
import System.IO (hClose, hFlush)
@@ -600,6 +601,7 @@ die s = do
main :: IO ()
main = do
+ settings <- readSettings
O.execParser (O.info (options <**> O.helper) O.idm) >>= \case
Options {colorize, noPager, width, command = List {sort, filters, files}} -> do
let withinPath issue = if null files then True else any (\file -> file `isPrefixOf` issue.file) files
diff --git a/app/Settings.hs b/app/Settings.hs
new file mode 100644
index 0000000..116a3d2
--- /dev/null
+++ b/app/Settings.hs
@@ -0,0 +1,43 @@
+module Settings
+ ( Settings,
+ readSettings,
+ )
+where
+
+import Data.Aeson qualified as A
+import Data.Yaml (decodeFileThrow)
+import GHC.Generics (Generic)
+import System.Directory (doesFileExist)
+import System.Environment.XDG.BaseDir (getSystemConfigFiles, getUserConfigFile)
+
+data Settings = Settings
+ {
+ }
+ deriving (Show, Generic)
+
+instance Semigroup Settings where
+ _ <> _ = Settings {}
+
+instance Monoid Settings where
+ mempty = Settings {}
+
+instance A.FromJSON Settings
+
+instance A.ToJSON Settings
+
+readSettings :: IO Settings
+readSettings =
+ fmap mconcat
+ . mapM
+ ( \fp ->
+ doesFileExist fp >>= \case
+ True -> decodeFileThrow fp
+ False -> pure mempty
+ )
+ =<< concat
+ <$> sequence
+ [ getSystemConfigFiles "anissue" "settings.yaml",
+ ((: []) <$> getUserConfigFile "anissue" "settings.yaml"),
+ -- TODO Read settings from Git base dir
+ pure ["./anissue.yaml"]
+ ]