summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-01-06 00:38:07 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-01-06 00:38:07 +0400
commit8916f4938f27078743f3f62376759f16bcda2f20 (patch)
tree4f233033ed61103943c8c76d489eef34c7a95e3c /examples
parenta95d2aab3f8b11b681cd19c89322e485150dc647 (diff)
Fix warnings in MkTorrent utility
Diffstat (limited to 'examples')
-rw-r--r--examples/MkTorrent.hs34
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
29import Data.Torrent.Bitfield as BF 29import Data.Torrent.Bitfield as BF
30import Data.Torrent.Piece 30import Data.Torrent.Piece
31import Data.Torrent.Layout 31import Data.Torrent.Layout
32import Data.Torrent.Magnet hiding (Magnet (Magnet)) 32import Data.Torrent.Magnet hiding (Magnet)
33import Data.Torrent.Magnet (Magnet)
34import System.Torrent.Storage 33import 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
47question :: Show a => Text -> Maybe a -> IO () 46question :: Show a => Text -> Maybe a -> IO ()
48question q def = do 47question 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
70askURI :: IO URI 69askURI :: IO URI
71askURI = do 70askURI = 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
77askFreeform :: IO Text 76askFreeform :: IO Text
78askFreeform = do 77askFreeform = 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
84askInRange :: Int -> Int -> IO Int 83askInRange :: Int -> Int -> IO Int
85askInRange a b = do 84askInRange 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
109torrentFile :: Parser FilePath 108torrentFile :: Parser FilePath
110torrentFile = argument Just 109torrentFile = 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
156checkInfo = info (helper <*> parser) modifier 155checkInfo = 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
292putTorrent :: ShowOpts -> IO () 292putTorrent :: ShowOpts -> IO ()
293putTorrent opts @ ShowOpts {..} = do 293putTorrent 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