Browse Source

Replace `EitherT' with `ExceptT', widen dependencies

tags/v0.2.5.0^0
Peter J. Jones 8 months ago
parent
commit
dd0f0cdc13
Signed by: Peter Jones <pjones@devalot.com> GPG Key ID: 9DAFAA8D01941E49
8 changed files with 43 additions and 27 deletions
  1. 1
    0
      .gitignore
  2. 6
    0
      CHANGES.md
  3. 10
    1
      default.nix
  4. 9
    9
      src/Vimeta/Core/Config.hs
  5. 8
    8
      src/Vimeta/Core/Vimeta.hs
  6. 3
    3
      src/Vimeta/UI/CommandLine/Config.hs
  7. 5
    5
      vimeta.cabal
  8. 1
    1
      vimeta.nix

+ 1
- 0
.gitignore View File

@@ -3,3 +3,4 @@
3 3
 /build/.stack-work
4 4
 /cabal.project.local
5 5
 /dist-newstyle
6
+/result

+ 6
- 0
CHANGES.md View File

@@ -1,5 +1,11 @@
1 1
 # Version History
2 2
 
3
+## 0.2.5.0 (October 09, 2018)
4
+
5
+  - Update dependency versions
6
+
7
+  - Replace `EitherT` with `ExceptT`
8
+
3 9
 ## 0.2.4.0 (March 20, 2018)
4 10
 
5 11
   - Update dependency versions

+ 10
- 1
default.nix View File

@@ -5,8 +5,17 @@ let
5 5
   # building or while in a nix shell:
6 6
   extraPackages = with pkgs; [ atomicparsley ];
7 7
 
8
+  # Grab the latest TheMovieDB package:
9
+  themoviedb = fetchGit "git://git.devalot.com/themoviedb.git";
10
+
8 11
   # Helpful if you want to override any Haskell packages:
9
-  haskell = pkgs.haskellPackages;
12
+  haskell = pkgs.haskellPackages.override (orig: {
13
+    overrides = pkgs.lib.composeExtensions
14
+                  (orig.overrides or (_: _: {}))
15
+                  (self: super: with pkgs.haskell.lib; {
16
+                    themoviedb = self.callPackage "${themoviedb}/themoviedb.nix" { };
17
+                  });
18
+    });
10 19
 in
11 20
 
12 21
 # Load the local nix file and use the overrides from above:

+ 9
- 9
src/Vimeta/Core/Config.hs View File

@@ -25,9 +25,9 @@ module Vimeta.Core.Config
25 25
 -- Library imports:
26 26
 import Control.Applicative
27 27
 import Control.Monad
28
-import Control.Monad.IO.Class
29
-import Control.Monad.Trans.Either
30
-import Data.Aeson
28
+import Control.Monad.Except
29
+import Control.Monad.IO.Class (MonadIO, liftIO)
30
+import Data.Aeson hiding (encodeFile)
31 31
 import Data.Aeson.Types (typeMismatch)
32 32
 import Data.Text (Text)
33 33
 import Data.Yaml (decodeFileEither, encodeFile)
@@ -92,20 +92,20 @@ configFileName = getUserConfigFile "vimeta" "config.yml"
92 92
 
93 93
 --------------------------------------------------------------------------------
94 94
 -- | Read the configuration file and return a 'Config' value or an error.
95
-readConfig :: (MonadIO m) => EitherT String m Config
95
+readConfig :: (MonadIO m) => ExceptT String m Config
96 96
 readConfig = do
97 97
   filename <- liftIO configFileName
98 98
   exists   <- liftIO (doesFileExist filename)
99 99
 
100 100
   if exists
101 101
     then decodeConfig filename
102
-    else left $ missingFile filename
102
+    else throwError $ missingFile filename
103 103
 
104 104
   where
105
-    decodeConfig :: (MonadIO m) => FilePath -> EitherT String m Config
105
+    decodeConfig :: (MonadIO m) => FilePath -> ExceptT String m Config
106 106
     decodeConfig fn = do result <- liftIO $ decodeFileEither fn
107 107
                          case result of
108
-                           Left e  -> left (show e)
108
+                           Left e  -> throwError (show e)
109 109
                            Right a -> return a
110 110
 
111 111
     missingFile :: FilePath -> String
@@ -113,14 +113,14 @@ readConfig = do
113 113
                      "to create " ++ fn
114 114
 
115 115
 --------------------------------------------------------------------------------
116
-writeConfig :: (MonadIO m) => Config -> EitherT String m FilePath
116
+writeConfig :: (MonadIO m) => Config -> ExceptT String m FilePath
117 117
 writeConfig c = do
118 118
   (filename, exists) <- liftIO $ do
119 119
     fn <- configFileName
120 120
     ex <- doesFileExist fn
121 121
     return (fn, ex)
122 122
 
123
-  when exists $ left (existError filename)
123
+  when exists $ throwError (existError filename)
124 124
 
125 125
   liftIO (createDirectoryIfMissing True (takeDirectory filename))
126 126
   liftIO (encodeFile filename c)

+ 8
- 8
src/Vimeta/Core/Vimeta.hs View File

@@ -33,8 +33,8 @@ module Vimeta.Core.Vimeta
33 33
 -- Library imports:
34 34
 import Control.Applicative
35 35
 import Control.Exception
36
+import Control.Monad.Except
36 37
 import Control.Monad.Reader
37
-import Control.Monad.Trans.Either
38 38
 import Data.Text (Text)
39 39
 import qualified Data.Text.IO as Text
40 40
 import Network.API.TheMovieDB (TheMovieDB, Key, runTheMovieDBWithManager)
@@ -64,13 +64,13 @@ data Context = Context
64 64
 
65 65
 --------------------------------------------------------------------------------
66 66
 newtype Vimeta m a =
67
-  Vimeta {unV :: ReaderT Context (EitherT String m) a}
67
+  Vimeta {unV :: ReaderT Context (ExceptT String m) a}
68 68
   deriving (Functor, Applicative, Monad, MonadIO, MonadReader Context)
69 69
 
70 70
 --------------------------------------------------------------------------------
71 71
 -- | Terminate a 'Vimeta' session with an error message.
72 72
 die :: (Monad m) => String -> Vimeta m a
73
-die message = Vimeta $ lift (left message)
73
+die message = Vimeta $ lift (throwError message)
74 74
 
75 75
 --------------------------------------------------------------------------------
76 76
 runIO :: (MonadIO m) => IO a -> Vimeta m a
@@ -109,12 +109,12 @@ verbose msg = do
109 109
   when okay $ liftIO $ Text.hPutStrLn (ctxVerboseH context) msg
110 110
 
111 111
 --------------------------------------------------------------------------------
112
-loadTMDBConfig :: (MonadIO m) => Manager -> Key -> EitherT String m TheMovieDB.Configuration
112
+loadTMDBConfig :: (MonadIO m) => Manager -> Key -> ExceptT String m TheMovieDB.Configuration
113 113
 loadTMDBConfig manager key = do
114 114
   result <- cacheTMDBConfig (liftIO $ runTheMovieDBWithManager manager key TheMovieDB.config)
115 115
 
116 116
   case result of
117
-    Left e  -> left (show e)
117
+    Left e  -> throwError (show e)
118 118
     Right c -> return c
119 119
 
120 120
 --------------------------------------------------------------------------------
@@ -125,7 +125,7 @@ execVimetaWithContext :: Context
125 125
                       -> Vimeta m a
126 126
                       -> m (Either String a)
127 127
 execVimetaWithContext context vimeta =
128
-  runEitherT $ runReaderT (unV vimeta) context
128
+  runExceptT $ runReaderT (unV vimeta) context
129 129
 
130 130
 --------------------------------------------------------------------------------
131 131
 -- | Run a 'Vimeta' operation after loading the configuration file
@@ -134,11 +134,11 @@ execVimeta :: (MonadIO m)
134 134
            => (Config -> Config)  -- ^ Modify configuration before running.
135 135
            -> Vimeta m a          -- ^ The Vimeta value to execute.
136 136
            -> m (Either String a) -- ^ The result.
137
-execVimeta cf vimeta = runEitherT $ do
137
+execVimeta cf vimeta = runExceptT $ do
138 138
   config <- cf <$> readConfig
139 139
   manager <- liftIO $ newManager tlsManagerSettings
140 140
   tc <- loadTMDBConfig manager (configTMDBKey config)
141
-  EitherT $ execVimetaWithContext (Context manager config tc stdout) vimeta
141
+  ExceptT $ execVimetaWithContext (Context manager config tc stdout) vimeta
142 142
 
143 143
 --------------------------------------------------------------------------------
144 144
 -- | Simple wrapper around 'execVimeta'.

+ 3
- 3
src/Vimeta/UI/CommandLine/Config.hs View File

@@ -20,7 +20,7 @@ module Vimeta.UI.CommandLine.Config
20 20
 
21 21
 --------------------------------------------------------------------------------
22 22
 import Control.Monad
23
-import Control.Monad.Trans.Either
23
+import Control.Monad.Except
24 24
 import Data.Monoid
25 25
 import Data.Text (Text)
26 26
 import qualified Data.Text as Text
@@ -62,7 +62,7 @@ run opts = do
62 62
                  Nothing -> def
63 63
                  Just k  -> def {configTMDBKey = k}
64 64
 
65
-  result <- runEitherT (app opts config)
65
+  result <- runExceptT (app opts config)
66 66
 
67 67
   case result of
68 68
     Left e         -> byline Error e >> exitFailure
@@ -74,7 +74,7 @@ run opts = do
74 74
     byline rt = void . runByline . reportLn rt . text . Text.pack
75 75
 
76 76
 --------------------------------------------------------------------------------
77
-app :: Options -> Config -> EitherT String IO (Maybe String)
77
+app :: Options -> Config -> ExceptT String IO (Maybe String)
78 78
 app opts config = do
79 79
   filename <- writeConfig config
80 80
 

+ 5
- 5
vimeta.cabal View File

@@ -1,6 +1,6 @@
1 1
 --------------------------------------------------------------------------------
2 2
 name:          vimeta
3
-version:       0.2.4.0
3
+version:       0.2.5.0
4 4
 synopsis:      Frontend for video metadata tagging tools
5 5
 homepage:      http://github.com/pjones/vimeta
6 6
 bug-reports:   http://github.com/pjones/vimeta/issues
@@ -70,10 +70,10 @@ library
70 70
     ghc-options: -Werror
71 71
 
72 72
   build-depends: base                 >= 4.6    && < 5.0
73
-               , aeson                >= 0.8    && < 1.4
73
+               , aeson                >= 0.8    && < 1.5
74 74
                , byline               >= 0.1    && < 1.0
75 75
                , bytestring           >= 0.10   && < 0.11
76
-               , containers           >= 0.5    && < 0.6
76
+               , containers           >= 0.5    && < 0.7
77 77
                , directory            >= 1.2    && < 1.4
78 78
                , either               >= 4.3    && < 6
79 79
                , filepath             >= 1.3    && < 1.5
@@ -85,14 +85,14 @@ library
85 85
                , optparse-applicative >= 0.11   && < 0.15
86 86
                , parsec               >= 3.1    && < 3.2
87 87
                , process              >= 1.1    && < 1.7
88
-               , temporary            >= 1.1    && < 1.3
88
+               , temporary            >= 1.1    && < 1.4
89 89
                , text                 >= 0.11   && < 1.3
90 90
                , themoviedb           >= 1.1    && < 1.2
91 91
                , time                 >= 1.2    && < 1.10
92 92
                , time-locale-compat   >= 0.1    && < 0.2
93 93
                , transformers         >= 0.3    && < 0.6
94 94
                , xdg-basedir          >= 0.2    && < 0.3
95
-               , yaml                 >= 0.8    && < 0.9
95
+               , yaml                 >= 0.8    && < 0.10
96 96
 
97 97
 --------------------------------------------------------------------------------
98 98
 executable vimeta

+ 1
- 1
vimeta.nix View File

@@ -6,7 +6,7 @@
6 6
 }:
7 7
 mkDerivation {
8 8
   pname = "vimeta";
9
-  version = "0.2.4.0";
9
+  version = "0.2.5.0";
10 10
   src = ./.;
11 11
   isLibrary = true;
12 12
   isExecutable = true;

Loading…
Cancel
Save