Do some order
This commit is contained in:
parent
28ec0bc1e5
commit
113e08365e
29
Main.hs
29
Main.hs
@ -6,13 +6,12 @@ import Data.Maybe (fromJust)
|
|||||||
import Data.HashMap.Strict (delete)
|
import Data.HashMap.Strict (delete)
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
|
|
||||||
import qualified Data.ByteString.Lazy.Char8 as C
|
|
||||||
import System.Console.ArgParser
|
import System.Console.ArgParser
|
||||||
import System.Process
|
import System.Process
|
||||||
|
import qualified Data.ByteString.Lazy.Char8 as C
|
||||||
import Json
|
import Json
|
||||||
|
|
||||||
|
|
||||||
data ProgArgs = ProgArgs
|
data ProgArgs = ProgArgs
|
||||||
{ name :: String
|
{ name :: String
|
||||||
, url :: String
|
, url :: String
|
||||||
@ -21,6 +20,7 @@ data ProgArgs = ProgArgs
|
|||||||
, raw :: Bool
|
, raw :: Bool
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
|
|
||||||
parser :: ParserSpec ProgArgs
|
parser :: ParserSpec ProgArgs
|
||||||
parser = ProgArgs
|
parser = ProgArgs
|
||||||
`parsedBy` reqPos "name" `Descr` "Namecoin name id"
|
`parsedBy` reqPos "name" `Descr` "Namecoin name id"
|
||||||
@ -30,12 +30,25 @@ parser = ProgArgs
|
|||||||
`andBy` boolFlag "block" `Descr` "Show blockchain data (require local connecton)"
|
`andBy` boolFlag "block" `Descr` "Show blockchain data (require local connecton)"
|
||||||
`andBy` boolFlag "raw" `Descr` "Print raw JSON data"
|
`andBy` boolFlag "raw" `Descr` "Print raw JSON data"
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = interface >>= flip runApp exec
|
||||||
|
|
||||||
|
|
||||||
|
exec :: ProgArgs -> IO ()
|
||||||
|
exec args@ProgArgs{..} =
|
||||||
|
if dnschain
|
||||||
|
then handleDnschain url name raw
|
||||||
|
else handleLocal name block
|
||||||
|
|
||||||
|
|
||||||
handleLocal :: String -> Bool -> IO ()
|
handleLocal :: String -> Bool -> IO ()
|
||||||
handleLocal name block = do
|
handleLocal name block = do
|
||||||
out <- readProcess "namecoind" ["name_show", name] ""
|
out <- readProcess "namecoind" ["name_show", name] ""
|
||||||
@ -48,6 +61,7 @@ handleLocal name block = do
|
|||||||
extra = toJSON $ delete "value" res
|
extra = toJSON $ delete "value" res
|
||||||
Nothing -> putStrLn "Error parsing data"
|
Nothing -> putStrLn "Error parsing data"
|
||||||
|
|
||||||
|
|
||||||
handleDnschain :: String -> String -> Bool -> IO ()
|
handleDnschain :: String -> String -> Bool -> IO ()
|
||||||
handleDnschain url name raw = do
|
handleDnschain url name raw = do
|
||||||
req <- get (url ++ name)
|
req <- get (url ++ name)
|
||||||
@ -58,12 +72,3 @@ handleDnschain url name raw = do
|
|||||||
case decode body of
|
case decode body of
|
||||||
Just res -> repr res
|
Just res -> repr res
|
||||||
Nothing -> "Error parsing data"
|
Nothing -> "Error parsing data"
|
||||||
|
|
||||||
exec :: ProgArgs -> IO ()
|
|
||||||
exec args@ProgArgs{..} =
|
|
||||||
if dnschain
|
|
||||||
then handleDnschain url name raw
|
|
||||||
else handleLocal name block
|
|
||||||
|
|
||||||
main :: IO ()
|
|
||||||
main = interface >>= flip runApp exec
|
|
Loading…
Reference in New Issue
Block a user