Browse Source

Replace `EitherT' with `ExceptT', widen dependencies

tags/v0.2.5.0^0
Peter J. Jones 10 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 @@
/build/.stack-work
/cabal.project.local
/dist-newstyle
/result

+ 6
- 0
CHANGES.md View File

@@ -1,5 +1,11 @@
# Version History

## 0.2.5.0 (October 09, 2018)

- Update dependency versions

- Replace `EitherT` with `ExceptT`

## 0.2.4.0 (March 20, 2018)

- Update dependency versions

+ 10
- 1
default.nix View File

@@ -5,8 +5,17 @@ let
# building or while in a nix shell:
extraPackages = with pkgs; [ atomicparsley ];

# Grab the latest TheMovieDB package:
themoviedb = fetchGit "git://git.devalot.com/themoviedb.git";

# Helpful if you want to override any Haskell packages:
haskell = pkgs.haskellPackages;
haskell = pkgs.haskellPackages.override (orig: {
overrides = pkgs.lib.composeExtensions
(orig.overrides or (_: _: {}))
(self: super: with pkgs.haskell.lib; {
themoviedb = self.callPackage "${themoviedb}/themoviedb.nix" { };
});
});
in

# 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
-- Library imports:
import Control.Applicative
import Control.Monad
import Control.Monad.IO.Class
import Control.Monad.Trans.Either
import Data.Aeson
import Control.Monad.Except
import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.Aeson hiding (encodeFile)
import Data.Aeson.Types (typeMismatch)
import Data.Text (Text)
import Data.Yaml (decodeFileEither, encodeFile)
@@ -92,20 +92,20 @@ configFileName = getUserConfigFile "vimeta" "config.yml"

--------------------------------------------------------------------------------
-- | Read the configuration file and return a 'Config' value or an error.
readConfig :: (MonadIO m) => EitherT String m Config
readConfig :: (MonadIO m) => ExceptT String m Config
readConfig = do
filename <- liftIO configFileName
exists <- liftIO (doesFileExist filename)

if exists
then decodeConfig filename
else left $ missingFile filename
else throwError $ missingFile filename

where
decodeConfig :: (MonadIO m) => FilePath -> EitherT String m Config
decodeConfig :: (MonadIO m) => FilePath -> ExceptT String m Config
decodeConfig fn = do result <- liftIO $ decodeFileEither fn
case result of
Left e -> left (show e)
Left e -> throwError (show e)
Right a -> return a

missingFile :: FilePath -> String
@@ -113,14 +113,14 @@ readConfig = do
"to create " ++ fn

--------------------------------------------------------------------------------
writeConfig :: (MonadIO m) => Config -> EitherT String m FilePath
writeConfig :: (MonadIO m) => Config -> ExceptT String m FilePath
writeConfig c = do
(filename, exists) <- liftIO $ do
fn <- configFileName
ex <- doesFileExist fn
return (fn, ex)

when exists $ left (existError filename)
when exists $ throwError (existError filename)

liftIO (createDirectoryIfMissing True (takeDirectory filename))
liftIO (encodeFile filename c)

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

@@ -33,8 +33,8 @@ module Vimeta.Core.Vimeta
-- Library imports:
import Control.Applicative
import Control.Exception
import Control.Monad.Except
import Control.Monad.Reader
import Control.Monad.Trans.Either
import Data.Text (Text)
import qualified Data.Text.IO as Text
import Network.API.TheMovieDB (TheMovieDB, Key, runTheMovieDBWithManager)
@@ -64,13 +64,13 @@ data Context = Context

--------------------------------------------------------------------------------
newtype Vimeta m a =
Vimeta {unV :: ReaderT Context (EitherT String m) a}
Vimeta {unV :: ReaderT Context (ExceptT String m) a}
deriving (Functor, Applicative, Monad, MonadIO, MonadReader Context)

--------------------------------------------------------------------------------
-- | Terminate a 'Vimeta' session with an error message.
die :: (Monad m) => String -> Vimeta m a
die message = Vimeta $ lift (left message)
die message = Vimeta $ lift (throwError message)

--------------------------------------------------------------------------------
runIO :: (MonadIO m) => IO a -> Vimeta m a
@@ -109,12 +109,12 @@ verbose msg = do
when okay $ liftIO $ Text.hPutStrLn (ctxVerboseH context) msg

--------------------------------------------------------------------------------
loadTMDBConfig :: (MonadIO m) => Manager -> Key -> EitherT String m TheMovieDB.Configuration
loadTMDBConfig :: (MonadIO m) => Manager -> Key -> ExceptT String m TheMovieDB.Configuration
loadTMDBConfig manager key = do
result <- cacheTMDBConfig (liftIO $ runTheMovieDBWithManager manager key TheMovieDB.config)

case result of
Left e -> left (show e)
Left e -> throwError (show e)
Right c -> return c

--------------------------------------------------------------------------------
@@ -125,7 +125,7 @@ execVimetaWithContext :: Context
-> Vimeta m a
-> m (Either String a)
execVimetaWithContext context vimeta =
runEitherT $ runReaderT (unV vimeta) context
runExceptT $ runReaderT (unV vimeta) context

--------------------------------------------------------------------------------
-- | Run a 'Vimeta' operation after loading the configuration file
@@ -134,11 +134,11 @@ execVimeta :: (MonadIO m)
=> (Config -> Config) -- ^ Modify configuration before running.
-> Vimeta m a -- ^ The Vimeta value to execute.
-> m (Either String a) -- ^ The result.
execVimeta cf vimeta = runEitherT $ do
execVimeta cf vimeta = runExceptT $ do
config <- cf <$> readConfig
manager <- liftIO $ newManager tlsManagerSettings
tc <- loadTMDBConfig manager (configTMDBKey config)
EitherT $ execVimetaWithContext (Context manager config tc stdout) vimeta
ExceptT $ execVimetaWithContext (Context manager config tc stdout) vimeta

--------------------------------------------------------------------------------
-- | Simple wrapper around 'execVimeta'.

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

@@ -20,7 +20,7 @@ module Vimeta.UI.CommandLine.Config

--------------------------------------------------------------------------------
import Control.Monad
import Control.Monad.Trans.Either
import Control.Monad.Except
import Data.Monoid
import Data.Text (Text)
import qualified Data.Text as Text
@@ -62,7 +62,7 @@ run opts = do
Nothing -> def
Just k -> def {configTMDBKey = k}

result <- runEitherT (app opts config)
result <- runExceptT (app opts config)

case result of
Left e -> byline Error e >> exitFailure
@@ -74,7 +74,7 @@ run opts = do
byline rt = void . runByline . reportLn rt . text . Text.pack

--------------------------------------------------------------------------------
app :: Options -> Config -> EitherT String IO (Maybe String)
app :: Options -> Config -> ExceptT String IO (Maybe String)
app opts config = do
filename <- writeConfig config


+ 5
- 5
vimeta.cabal View File

@@ -1,6 +1,6 @@
--------------------------------------------------------------------------------
name: vimeta
version: 0.2.4.0
version: 0.2.5.0
synopsis: Frontend for video metadata tagging tools
homepage: http://github.com/pjones/vimeta
bug-reports: http://github.com/pjones/vimeta/issues
@@ -70,10 +70,10 @@ library
ghc-options: -Werror

build-depends: base >= 4.6 && < 5.0
, aeson >= 0.8 && < 1.4
, aeson >= 0.8 && < 1.5
, byline >= 0.1 && < 1.0
, bytestring >= 0.10 && < 0.11
, containers >= 0.5 && < 0.6
, containers >= 0.5 && < 0.7
, directory >= 1.2 && < 1.4
, either >= 4.3 && < 6
, filepath >= 1.3 && < 1.5
@@ -85,14 +85,14 @@ library
, optparse-applicative >= 0.11 && < 0.15
, parsec >= 3.1 && < 3.2
, process >= 1.1 && < 1.7
, temporary >= 1.1 && < 1.3
, temporary >= 1.1 && < 1.4
, text >= 0.11 && < 1.3
, themoviedb >= 1.1 && < 1.2
, time >= 1.2 && < 1.10
, time-locale-compat >= 0.1 && < 0.2
, transformers >= 0.3 && < 0.6
, xdg-basedir >= 0.2 && < 0.3
, yaml >= 0.8 && < 0.9
, yaml >= 0.8 && < 0.10

--------------------------------------------------------------------------------
executable vimeta

+ 1
- 1
vimeta.nix View File

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

Loading…
Cancel
Save