diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-03 00:59:48 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-03 00:59:48 +0400 |
commit | 65107192f9c5f8ff134362a7b9d37cb3f73dad7e (patch) | |
tree | c04f56cf4ec079a47f9bdb5d9cc73cbcfa2ca6d3 /examples/GetTorrent.hs | |
parent | 8815a137d8300d62a897154ec4fd02917d22bcb3 (diff) |
Add skeleton for gettorrent example
Diffstat (limited to 'examples/GetTorrent.hs')
-rw-r--r-- | examples/GetTorrent.hs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/examples/GetTorrent.hs b/examples/GetTorrent.hs new file mode 100644 index 00000000..a9d2a44f --- /dev/null +++ b/examples/GetTorrent.hs | |||
@@ -0,0 +1,37 @@ | |||
1 | module Main (main) where | ||
2 | import Data.Default | ||
3 | |||
4 | import Options.Applicative | ||
5 | import Data.Torrent.InfoHash | ||
6 | import Network.BitTorrent.Core | ||
7 | |||
8 | |||
9 | data Params = Params | ||
10 | { infohash :: InfoHash | ||
11 | , thisNode :: NodeAddr IPv4 | ||
12 | , bootNode :: NodeAddr IPv4 | ||
13 | } deriving Show | ||
14 | |||
15 | paramsParser :: Parser Params | ||
16 | paramsParser = Params | ||
17 | <$> option (long "infohash" <> short 'i' | ||
18 | <> metavar "SHA1" <> help "infohash of torrent file") | ||
19 | <*> option (long "node" <> short 'n' <> value def | ||
20 | <> metavar "NODE" <> help "this node address" | ||
21 | ) | ||
22 | <*> option (long "boot" <> short 'b' | ||
23 | <> metavar "NODE" <> help "bootstrap node address" | ||
24 | ) | ||
25 | |||
26 | programInfo :: ParserInfo Params | ||
27 | programInfo = info (helper <*> paramsParser) | ||
28 | ( fullDesc | ||
29 | <> progDesc "" | ||
30 | <> header "gettorrent - get torrent file by infohash" | ||
31 | ) | ||
32 | |||
33 | getTorrent :: Params -> IO () | ||
34 | getTorrent = print | ||
35 | |||
36 | main :: IO () | ||
37 | main = execParser programInfo >>= getTorrent | ||