summaryrefslogtreecommitdiff
path: root/examples/MkTorrent.hs
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-01-05 00:30:38 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-01-05 00:30:38 +0400
commit9577747c3ad7ba380bc5f8d4cc6a4a5420bdacae (patch)
tree32e2352ffcdf725a04dddcda62724cd8806e8da9 /examples/MkTorrent.hs
parente611467a3bd8b46367fed030a9286031faaa547d (diff)
Use exceptions instead of return value
Diffstat (limited to 'examples/MkTorrent.hs')
-rw-r--r--examples/MkTorrent.hs17
1 files changed, 6 insertions, 11 deletions
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)
131askAmend :: IO Amend 131askAmend :: IO Amend
132askAmend = join $ T.putStrLn "Choose a field:" >> askChoice fields 132askAmend = join $ T.putStrLn "Choose a field:" >> askChoice fields
133 133
134amend :: AmendOpts -> IO Bool 134amend :: AmendOpts -> IO ()
135amend (AmendOpts tpath) = do 135amend (AmendOpts tpath) = do
136 t <- fromFile tpath 136 t <- fromFile tpath
137 a <- askAmend 137 a <- askAmend
138 toFile tpath $ a t 138 toFile tpath $ a t
139 return True
140 139
141{----------------------------------------------------------------------- 140{-----------------------------------------------------------------------
142-- Check command 141-- Check command
@@ -215,10 +214,8 @@ magnetInfo = info (helper <*> parser) modifier
215 <$> torrentFile 214 <$> torrentFile
216 <*> switch ( long "detailed" ) 215 <*> switch ( long "detailed" )
217 216
218magnet :: MagnetOpts -> IO Bool 217magnet :: MagnetOpts -> IO ()
219magnet MagnetOpts {..} = do 218magnet MagnetOpts {..} = print . magnetLink =<< fromFile magnetFile
220 print . magnetLink =<< fromFile magnetFile;
221 return True
222 where 219 where
223 magnetLink = if detailed then detailedMagnet else simpleMagnet 220 magnetLink = if detailed then detailedMagnet else simpleMagnet
224 221
@@ -247,11 +244,10 @@ showTorrent ShowOpts {..} torrent
247 | infoHashOnly = shows $ idInfoHash (tInfoDict torrent) 244 | infoHashOnly = shows $ idInfoHash (tInfoDict torrent)
248 | otherwise = shows $ pretty torrent 245 | otherwise = shows $ pretty torrent
249 246
250putTorrent :: ShowOpts -> IO Bool 247putTorrent :: ShowOpts -> IO ()
251putTorrent opts @ ShowOpts {..} = do 248putTorrent opts @ ShowOpts {..} = do
252 torrent <- fromFile showPath `onException` putStrLn help 249 torrent <- fromFile showPath `onException` putStrLn help
253 putStrLn $ showTorrent opts torrent [] 250 putStrLn $ showTorrent opts torrent []
254 return True
255 where 251 where
256 help = "Most likely this is not a valid .torrent file" 252 help = "Most likely this is not a valid .torrent file"
257 253
@@ -351,7 +347,7 @@ parserInfo = info parser modifier
351-- Dispatch 347-- Dispatch
352-----------------------------------------------------------------------} 348-----------------------------------------------------------------------}
353 349
354run :: Command -> IO Bool 350run :: Command -> IO ()
355run (Amend opts) = amend opts 351run (Amend opts) = amend opts
356--run (Check opts) = checkTorrent opts 352--run (Check opts) = checkTorrent opts
357--run (Create opts) = createTorrent opts 353--run (Create opts) = createTorrent opts
@@ -366,5 +362,4 @@ main :: IO ()
366main = do 362main = do
367 Options {..} <- execParser parserInfo 363 Options {..} <- execParser parserInfo
368 prepare globOpts 364 prepare globOpts
369 success <- run cmdOpts 365 run cmdOpts
370 if success then exitSuccess else exitFailure \ No newline at end of file