diff options
Diffstat (limited to 'examples/Client.hs')
-rw-r--r-- | examples/Client.hs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/examples/Client.hs b/examples/Client.hs index abf62657..26711676 100644 --- a/examples/Client.hs +++ b/examples/Client.hs | |||
@@ -1,9 +1,11 @@ | |||
1 | {-# LANGUAGE RankNTypes #-} | 1 | {-# LANGUAGE RankNTypes #-} |
2 | {-# LANGUAGE CPP #-} | ||
2 | {-# LANGUAGE ExistentialQuantification #-} | 3 | {-# LANGUAGE ExistentialQuantification #-} |
3 | {-# LANGUAGE RecordWildCards #-} | 4 | {-# LANGUAGE RecordWildCards #-} |
4 | module Main (main) where | 5 | module Main (main) where |
5 | import Control.Concurrent | 6 | import Control.Concurrent |
6 | import Control.Monad.Trans | 7 | import Control.Monad.Trans |
8 | import Data.Maybe | ||
7 | import Options.Applicative | 9 | import Options.Applicative |
8 | import System.Environment | 10 | import System.Environment |
9 | import System.Exit | 11 | import System.Exit |
@@ -12,6 +14,13 @@ import Text.Read | |||
12 | 14 | ||
13 | import Network.BitTorrent | 15 | import Network.BitTorrent |
14 | 16 | ||
17 | #if MIN_VERSION_optparse_applicative(0,13,0) | ||
18 | -- maybeReader imported from Options.Applicative.Builder | ||
19 | #elif MIN_VERSION_optparse_applicative(0,11,0) | ||
20 | maybeReader f = eitherReader (maybe (Left ":(") Right . f) | ||
21 | #else | ||
22 | maybeReader f = f | ||
23 | #endif | ||
15 | 24 | ||
16 | {----------------------------------------------------------------------- | 25 | {----------------------------------------------------------------------- |
17 | -- Command line arguments | 26 | -- Command line arguments |
@@ -29,17 +38,17 @@ argsParser = Args <$> (TorrentBox <$> infohashP <|> TorrentBox <$> torrentP) | |||
29 | <*> destDirP | 38 | <*> destDirP |
30 | where | 39 | where |
31 | infohashP :: Parser InfoHash | 40 | infohashP :: Parser InfoHash |
32 | infohashP = argument readMaybe | 41 | infohashP = argument (maybeReader readMaybe) |
33 | (metavar "SHA1" <> help "infohash of torrent file") | 42 | (metavar "SHA1" <> help "infohash of torrent file") |
34 | 43 | ||
35 | torrentP :: Parser FilePath | 44 | torrentP :: Parser FilePath |
36 | torrentP = argument Just | 45 | torrentP = argument (maybeReader Just) |
37 | ( metavar "FILE" | 46 | ( metavar "FILE" |
38 | <> help "A .torrent file" | 47 | <> help "A .torrent file" |
39 | ) | 48 | ) |
40 | 49 | ||
41 | destDirP :: Parser FilePath | 50 | destDirP :: Parser FilePath |
42 | destDirP = argument Just | 51 | destDirP = argument (maybeReader Just) |
43 | ( metavar "DIR" | 52 | ( metavar "DIR" |
44 | <> help "Directory to put content" | 53 | <> help "Directory to put content" |
45 | ) | 54 | ) |