diff options
author | joe <joe@jerkface.net> | 2017-09-15 06:22:10 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-09-15 06:22:10 -0400 |
commit | 12cbb3af2413dc28838ed271351dda16df8f7bdb (patch) | |
tree | 2db77a787e18a81a8369a8d73fee369d8826f064 /examples/Client.hs | |
parent | 362357c6d08cbd8dffa627a1e80199dcb9ba231f (diff) |
Separating dht-client library from bittorrent package.
Diffstat (limited to 'examples/Client.hs')
-rw-r--r-- | examples/Client.hs | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/examples/Client.hs b/examples/Client.hs deleted file mode 100644 index 26711676..00000000 --- a/examples/Client.hs +++ /dev/null | |||
@@ -1,74 +0,0 @@ | |||
1 | {-# LANGUAGE RankNTypes #-} | ||
2 | {-# LANGUAGE CPP #-} | ||
3 | {-# LANGUAGE ExistentialQuantification #-} | ||
4 | {-# LANGUAGE RecordWildCards #-} | ||
5 | module Main (main) where | ||
6 | import Control.Concurrent | ||
7 | import Control.Monad.Trans | ||
8 | import Data.Maybe | ||
9 | import Options.Applicative | ||
10 | import System.Environment | ||
11 | import System.Exit | ||
12 | import System.IO | ||
13 | import Text.Read | ||
14 | |||
15 | import Network.BitTorrent | ||
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 | ||
24 | |||
25 | {----------------------------------------------------------------------- | ||
26 | -- Command line arguments | ||
27 | -----------------------------------------------------------------------} | ||
28 | |||
29 | data TorrentBox = forall s. TorrentSource s => TorrentBox { unTorrentBox :: s } | ||
30 | |||
31 | data Args = Args | ||
32 | { topic :: TorrentBox | ||
33 | , contentDir :: FilePath | ||
34 | } | ||
35 | |||
36 | argsParser :: Parser Args | ||
37 | argsParser = Args <$> (TorrentBox <$> infohashP <|> TorrentBox <$> torrentP) | ||
38 | <*> destDirP | ||
39 | where | ||
40 | infohashP :: Parser InfoHash | ||
41 | infohashP = argument (maybeReader readMaybe) | ||
42 | (metavar "SHA1" <> help "infohash of torrent file") | ||
43 | |||
44 | torrentP :: Parser FilePath | ||
45 | torrentP = argument (maybeReader Just) | ||
46 | ( metavar "FILE" | ||
47 | <> help "A .torrent file" | ||
48 | ) | ||
49 | |||
50 | destDirP :: Parser FilePath | ||
51 | destDirP = argument (maybeReader Just) | ||
52 | ( metavar "DIR" | ||
53 | <> help "Directory to put content" | ||
54 | ) | ||
55 | |||
56 | argsInfo :: ParserInfo Args | ||
57 | argsInfo = info (helper <*> argsParser) | ||
58 | ( fullDesc | ||
59 | <> progDesc "A simple CLI bittorrent client" | ||
60 | <> header "foo" | ||
61 | ) | ||
62 | |||
63 | {----------------------------------------------------------------------- | ||
64 | -- Client | ||
65 | -----------------------------------------------------------------------} | ||
66 | |||
67 | run :: Args -> BitTorrent () | ||
68 | run (Args (TorrentBox t) dir) = do | ||
69 | h <- openHandle dir t | ||
70 | start h | ||
71 | liftIO $ threadDelay 10000000000 | ||
72 | |||
73 | main :: IO () | ||
74 | main = execParser argsInfo >>= simpleClient . run | ||