Adjust whitespaces

This commit is contained in:
Rnhmjoj 2014-11-22 15:52:47 +01:00
parent 4f497ae881
commit 8902c819c4

69
Main.hs
View File

@ -13,44 +13,45 @@ import System.Process
import Json import Json
data Name = Name data Name = Name
{ name :: String { name :: String
, url :: String , url :: String
, local :: Bool , local :: Bool
, block :: Bool , block :: Bool
, raw :: Bool , raw :: Bool
} deriving (Show) } deriving (Show)
parser :: ParserSpec Name parser :: ParserSpec Name
parser = Name parser = Name
`parsedBy` reqPos "name" `Descr` "Namecoin name id" `parsedBy` reqPos "name" `Descr` "Namecoin name id"
`andBy` optPos "http://dns.dnschain.net/" "url" `Descr` "Use custom dnschain API url" `andBy` optPos "http://dns.dnschain.net/" "url"
`andBy` boolFlag "local" `Descr` "Use local namecoind db" `Descr` "Use custom dnschain API url"
`andBy` boolFlag "block" `Descr` "Show blockchain data (require local connecton)" `andBy` boolFlag "local" `Descr` "Use local namecoind db"
`andBy` boolFlag "raw" `Descr` "Print raw JSON data" `andBy` boolFlag "block" `Descr` "Show blockchain data (require local connecton)"
`andBy` boolFlag "raw" `Descr` "Print raw JSON data"
main :: IO () main :: IO ()
main = mkApp parser >>= flip runApp exec main = mkApp parser >>= flip runApp exec
exec :: Name -> IO () exec :: Name -> IO ()
exec args@Name{..} = exec args@Name{..} =
if local if local
then do then do
out <- readProcess "namecoind" ["name_show", name] "" out <- readProcess "namecoind" ["name_show", name] ""
case decode $ C.pack out of case decode (C.pack out) of
Just res -> do Just res -> do
putStrLn $ repr value putStrLn (repr value)
when block $ putStrLn (repr extra) when block $ putStrLn (repr extra)
where where
value = fromJust . decode . C.pack $ res |: "value" value = fromJust . decode . C.pack $ res |: "value"
extra = toJSON $ delete "value" res extra = toJSON $ delete "value" res
Nothing -> putStrLn "Error parsing data" Nothing -> putStrLn "Error parsing data"
else do else do
req <- get (url ++ name) req <- get (url ++ name)
print args let body = req ^. responseBody
let body = req ^. responseBody if raw
if raw then print body
then print body else putStrLn $
else case decode body of case decode body of
Just res -> putStrLn $ repr res Just res -> repr res
Nothing -> putStrLn "Error parsing data" Nothing -> "Error parsing data"