From 71a61b854f4c75bde2bd8d64aeba20062e1ace25 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Mon, 11 May 2015 00:01:30 +0200 Subject: [PATCH] Small restyle --- src/Main.hs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index 12b440d..f4b98d0 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -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 $