summaryrefslogtreecommitdiff
path: root/examples/Client.hs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/Client.hs')
-rw-r--r--examples/Client.hs15
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 #-}
4module Main (main) where 5module Main (main) where
5import Control.Concurrent 6import Control.Concurrent
6import Control.Monad.Trans 7import Control.Monad.Trans
8import Data.Maybe
7import Options.Applicative 9import Options.Applicative
8import System.Environment 10import System.Environment
9import System.Exit 11import System.Exit
@@ -12,6 +14,13 @@ import Text.Read
12 14
13import Network.BitTorrent 15import 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)
20maybeReader f = eitherReader (maybe (Left ":(") Right . f)
21#else
22maybeReader 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 )