From 9577747c3ad7ba380bc5f8d4cc6a4a5420bdacae Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Sun, 5 Jan 2014 00:30:38 +0400 Subject: Use exceptions instead of return value --- examples/MkTorrent.hs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'examples/MkTorrent.hs') diff --git a/examples/MkTorrent.hs b/examples/MkTorrent.hs index fea7ada5..9eda3a52 100644 --- a/examples/MkTorrent.hs +++ b/examples/MkTorrent.hs @@ -131,12 +131,11 @@ fields = [ ("announce", set announce <$> askURI) askAmend :: IO Amend askAmend = join $ T.putStrLn "Choose a field:" >> askChoice fields -amend :: AmendOpts -> IO Bool +amend :: AmendOpts -> IO () amend (AmendOpts tpath) = do t <- fromFile tpath a <- askAmend toFile tpath $ a t - return True {----------------------------------------------------------------------- -- Check command @@ -215,10 +214,8 @@ magnetInfo = info (helper <*> parser) modifier <$> torrentFile <*> switch ( long "detailed" ) -magnet :: MagnetOpts -> IO Bool -magnet MagnetOpts {..} = do - print . magnetLink =<< fromFile magnetFile; - return True +magnet :: MagnetOpts -> IO () +magnet MagnetOpts {..} = print . magnetLink =<< fromFile magnetFile where magnetLink = if detailed then detailedMagnet else simpleMagnet @@ -247,11 +244,10 @@ showTorrent ShowOpts {..} torrent | infoHashOnly = shows $ idInfoHash (tInfoDict torrent) | otherwise = shows $ pretty torrent -putTorrent :: ShowOpts -> IO Bool +putTorrent :: ShowOpts -> IO () putTorrent opts @ ShowOpts {..} = do torrent <- fromFile showPath `onException` putStrLn help putStrLn $ showTorrent opts torrent [] - return True where help = "Most likely this is not a valid .torrent file" @@ -351,7 +347,7 @@ parserInfo = info parser modifier -- Dispatch -----------------------------------------------------------------------} -run :: Command -> IO Bool +run :: Command -> IO () run (Amend opts) = amend opts --run (Check opts) = checkTorrent opts --run (Create opts) = createTorrent opts @@ -366,5 +362,4 @@ main :: IO () main = do Options {..} <- execParser parserInfo prepare globOpts - success <- run cmdOpts - if success then exitSuccess else exitFailure \ No newline at end of file + run cmdOpts -- cgit v1.2.3