Small restyle

This commit is contained in:
rnhmjoj 2015-05-11 00:01:30 +02:00
parent ae5069b3ad
commit 71a61b854f

View File

@ -3,6 +3,7 @@
import Json
import Control.Lens
import Control.Monad (when)
import Network.Wreq (get, responseBody)
import Data.Aeson (decode, toJSON)
import Data.Maybe (fromJust)
@ -30,7 +31,7 @@ parser = ProgArgs
interface :: IO (CmdLnInterface ProgArgs)
interface =
(`setAppDescr` "Query the namecoin blockchain") <$>
(`setAppDescr` "Query the namecoin blockchain") .
(`setAppEpilog` "Stat rosa pristina nomine, nomina nuda tenemus.") <$>
mkApp parser
@ -40,25 +41,24 @@ main = interface >>= flip runApp exec
exec :: ProgArgs -> IO ()
exec ProgArgs{..} =
if dnschain
then handleDnschain url name raw
else handleLocal name block
then doDnschain url name raw
else doLocal name block
handleLocal :: String -> Bool -> IO ()
handleLocal name block = do
doLocal :: String -> Bool -> IO ()
doLocal name block = do
out <- readProcess "namecoind" ["name_show", name] ""
case decode (pack out) of
Nothing -> putStrLn "Error parsing data"
Just res -> do
pprint $ reparse (res |: "value")
if block then pprint extra else return ()
when block (pprint extra)
where
reparse = fromJust . decode . pack
extra = toJSON (delete "value" res)
Nothing -> putStrLn "Error parsing data"
handleDnschain :: String -> String -> Bool -> IO ()
handleDnschain url name raw = do
req <- get (url ++ name)
let body = req ^. responseBody
doDnschain :: String -> String -> Bool -> IO ()
doDnschain url name raw = do
body <- (^. responseBody) <$> get (url ++ name)
if raw
then print body
else putStrLn $