diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-05 00:30:38 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-05 00:30:38 +0400 |
commit | 9577747c3ad7ba380bc5f8d4cc6a4a5420bdacae (patch) | |
tree | 32e2352ffcdf725a04dddcda62724cd8806e8da9 /examples/MkTorrent.hs | |
parent | e611467a3bd8b46367fed030a9286031faaa547d (diff) |
Use exceptions instead of return value
Diffstat (limited to 'examples/MkTorrent.hs')
-rw-r--r-- | examples/MkTorrent.hs | 17 |
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) | |||
131 | askAmend :: IO Amend | 131 | askAmend :: IO Amend |
132 | askAmend = join $ T.putStrLn "Choose a field:" >> askChoice fields | 132 | askAmend = join $ T.putStrLn "Choose a field:" >> askChoice fields |
133 | 133 | ||
134 | amend :: AmendOpts -> IO Bool | 134 | amend :: AmendOpts -> IO () |
135 | amend (AmendOpts tpath) = do | 135 | amend (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 | ||
218 | magnet :: MagnetOpts -> IO Bool | 217 | magnet :: MagnetOpts -> IO () |
219 | magnet MagnetOpts {..} = do | 218 | magnet 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 | ||
250 | putTorrent :: ShowOpts -> IO Bool | 247 | putTorrent :: ShowOpts -> IO () |
251 | putTorrent opts @ ShowOpts {..} = do | 248 | putTorrent 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 | ||
354 | run :: Command -> IO Bool | 350 | run :: Command -> IO () |
355 | run (Amend opts) = amend opts | 351 | run (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 () | |||
366 | main = do | 362 | main = 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 | ||