Skip to content

Commit

Permalink
Replace EitherT' with ExceptT', widen dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
pjones committed Oct 9, 2018
1 parent b93503e commit dd0f0cd
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/build/.stack-work
/cabal.project.local
/dist-newstyle
/result
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 10 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 9 additions & 9 deletions src/Vimeta/Core/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -92,35 +92,35 @@ 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
missingFile fn = "no config file found, use the `config' command " ++
"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)
Expand Down
16 changes: 8 additions & 8 deletions src/Vimeta/Core/Vimeta.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

--------------------------------------------------------------------------------
Expand All @@ -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
Expand All @@ -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'.
Expand Down
6 changes: 3 additions & 3 deletions src/Vimeta/UI/CommandLine/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
10 changes: 5 additions & 5 deletions vimeta.cabal
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion vimeta.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}:
mkDerivation {
pname = "vimeta";
version = "0.2.4.0";
version = "0.2.5.0";
src = ./.;
isLibrary = true;
isExecutable = true;
Expand Down

0 comments on commit dd0f0cd

Please sign in to comment.