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