diff options
-rw-r--r-- | examples/MkTorrent.hs | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/examples/MkTorrent.hs b/examples/MkTorrent.hs index 49856f9b..16e1e245 100644 --- a/examples/MkTorrent.hs +++ b/examples/MkTorrent.hs | |||
@@ -29,8 +29,7 @@ import Data.Torrent | |||
29 | import Data.Torrent.Bitfield as BF | 29 | import Data.Torrent.Bitfield as BF |
30 | import Data.Torrent.Piece | 30 | import Data.Torrent.Piece |
31 | import Data.Torrent.Layout | 31 | import Data.Torrent.Layout |
32 | import Data.Torrent.Magnet hiding (Magnet (Magnet)) | 32 | import Data.Torrent.Magnet hiding (Magnet) |
33 | import Data.Torrent.Magnet (Magnet) | ||
34 | import System.Torrent.Storage | 33 | import System.Torrent.Storage |
35 | 34 | ||
36 | 35 | ||
@@ -45,9 +44,9 @@ instance Read URI where | |||
45 | f (Just u) = [(u, "")] | 44 | f (Just u) = [(u, "")] |
46 | 45 | ||
47 | question :: Show a => Text -> Maybe a -> IO () | 46 | question :: Show a => Text -> Maybe a -> IO () |
48 | question q def = do | 47 | question q defVal = do |
49 | T.putStrLn q | 48 | T.putStrLn q |
50 | case def of | 49 | case defVal of |
51 | Nothing -> return () | 50 | Nothing -> return () |
52 | Just v -> T.putStrLn $ "[default: " <> T.pack (show v) <> "]" | 51 | Just v -> T.putStrLn $ "[default: " <> T.pack (show v) <> "]" |
53 | 52 | ||
@@ -69,22 +68,22 @@ askMaybe q = question q (Just False) >> getReply | |||
69 | 68 | ||
70 | askURI :: IO URI | 69 | askURI :: IO URI |
71 | askURI = do | 70 | askURI = do |
72 | str <- P.getLine | 71 | s <- P.getLine |
73 | case parseURI str of | 72 | case parseURI s of |
74 | Nothing -> T.putStrLn "incorrect URI" >> askURI | 73 | Nothing -> T.putStrLn "incorrect URI" >> askURI |
75 | Just u -> return u | 74 | Just u -> return u |
76 | 75 | ||
77 | askFreeform :: IO Text | 76 | askFreeform :: IO Text |
78 | askFreeform = do | 77 | askFreeform = do |
79 | str <- T.getLine | 78 | s <- T.getLine |
80 | if T.null str | 79 | if T.null s |
81 | then askFreeform | 80 | then askFreeform |
82 | else return str | 81 | else return s |
83 | 82 | ||
84 | askInRange :: Int -> Int -> IO Int | 83 | askInRange :: Int -> Int -> IO Int |
85 | askInRange a b = do | 84 | askInRange a b = do |
86 | str <- T.getLine | 85 | s <- T.getLine |
87 | case T.decimal str of | 86 | case T.decimal s of |
88 | Left msg -> do | 87 | Left msg -> do |
89 | P.putStrLn msg | 88 | P.putStrLn msg |
90 | askInRange a b | 89 | askInRange a b |
@@ -99,8 +98,8 @@ askChoice kvs = do | |||
99 | forM_ (L.zip [1 :: Int ..] $ L.map fst kvs) $ \(i, lbl) -> do | 98 | forM_ (L.zip [1 :: Int ..] $ L.map fst kvs) $ \(i, lbl) -> do |
100 | T.putStrLn $ " " <> T.pack (show i) <> ") " <> lbl | 99 | T.putStrLn $ " " <> T.pack (show i) <> ") " <> lbl |
101 | T.putStrLn "Your choice?" | 100 | T.putStrLn "Your choice?" |
102 | ix <- askInRange 1 (succ (L.length kvs)) | 101 | n <- askInRange 1 (succ (L.length kvs)) |
103 | return $ snd (kvs !! pred ix) | 102 | return $ snd (kvs !! pred n) |
104 | 103 | ||
105 | {----------------------------------------------------------------------- | 104 | {----------------------------------------------------------------------- |
106 | -- Helpers | 105 | -- Helpers |
@@ -108,7 +107,7 @@ askChoice kvs = do | |||
108 | 107 | ||
109 | torrentFile :: Parser FilePath | 108 | torrentFile :: Parser FilePath |
110 | torrentFile = argument Just | 109 | torrentFile = argument Just |
111 | ( metavar "FILE" | 110 | ( metavar "TORRENT_FILE_PATH" |
112 | <> help "A .torrent file" | 111 | <> help "A .torrent file" |
113 | ) | 112 | ) |
114 | 113 | ||
@@ -156,10 +155,11 @@ checkInfo :: ParserInfo CheckOpts | |||
156 | checkInfo = info (helper <*> parser) modifier | 155 | checkInfo = info (helper <*> parser) modifier |
157 | where | 156 | where |
158 | modifier = progDesc "Validate integrity of torrent data" | 157 | modifier = progDesc "Validate integrity of torrent data" |
158 | <> header "append +RTS -N$NUMBER_OF_CORES -RTS for parallel execution" | ||
159 | parser = CheckOpts | 159 | parser = CheckOpts |
160 | <$> torrentFile | 160 | <$> torrentFile |
161 | <*> argument Just | 161 | <*> argument Just |
162 | ( metavar "PATH" | 162 | ( metavar "CONTENT_DIR_PATH" |
163 | <> value "." | 163 | <> value "." |
164 | <> help "Content directory or a single file" | 164 | <> help "Content directory or a single file" |
165 | ) | 165 | ) |
@@ -291,10 +291,10 @@ showTorrent ShowOpts {..} torrent | |||
291 | 291 | ||
292 | putTorrent :: ShowOpts -> IO () | 292 | putTorrent :: ShowOpts -> IO () |
293 | putTorrent opts @ ShowOpts {..} = do | 293 | putTorrent opts @ ShowOpts {..} = do |
294 | torrent <- fromFile showPath `onException` putStrLn help | 294 | torrent <- fromFile showPath `onException` putStrLn msg |
295 | putStrLn $ showTorrent opts torrent [] | 295 | putStrLn $ showTorrent opts torrent [] |
296 | where | 296 | where |
297 | help = "Most likely this is not a valid .torrent file" | 297 | msg = "Torrent file is either invalid or do not exist" |
298 | 298 | ||
299 | {----------------------------------------------------------------------- | 299 | {----------------------------------------------------------------------- |
300 | -- Command | 300 | -- Command |