{-# LANGUAGE TypeApplications #-}
module Cardano.CLI.Options.Ping
( parsePingCmd
)
where
import Cardano.CLI.Commands.Ping
import Cardano.CLI.EraBased.Options.Common (integralReader)
import qualified Cardano.Network.Ping as CNP
import Control.Applicative ((<|>))
import qualified Options.Applicative as Opt
import qualified Prettyprinter as PP
parsePingCmd :: Opt.Parser PingCmd
parsePingCmd :: Parser PingCmd
parsePingCmd =
Mod CommandFields PingCmd -> Parser PingCmd
forall a. Mod CommandFields a -> Parser a
Opt.hsubparser (Mod CommandFields PingCmd -> Parser PingCmd)
-> Mod CommandFields PingCmd -> Parser PingCmd
forall a b. (a -> b) -> a -> b
$
[Mod CommandFields PingCmd] -> Mod CommandFields PingCmd
forall a. Monoid a => [a] -> a
mconcat
[ String -> Mod CommandFields PingCmd
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
Opt.metavar String
"ping"
, String -> ParserInfo PingCmd -> Mod CommandFields PingCmd
forall a. String -> ParserInfo a -> Mod CommandFields a
Opt.command String
"ping" (ParserInfo PingCmd -> Mod CommandFields PingCmd)
-> ParserInfo PingCmd -> Mod CommandFields PingCmd
forall a b. (a -> b) -> a -> b
$
Parser PingCmd -> InfoMod PingCmd -> ParserInfo PingCmd
forall a. Parser a -> InfoMod a -> ParserInfo a
Opt.info Parser PingCmd
pPing (InfoMod PingCmd -> ParserInfo PingCmd)
-> InfoMod PingCmd -> ParserInfo PingCmd
forall a b. (a -> b) -> a -> b
$
Maybe Doc -> InfoMod PingCmd
forall a. Maybe Doc -> InfoMod a
Opt.progDescDoc (Maybe Doc -> InfoMod PingCmd) -> Maybe Doc -> InfoMod PingCmd
forall a b. (a -> b) -> a -> b
$
Doc -> Maybe Doc
forall a. a -> Maybe a
Just (Doc -> Maybe Doc) -> Doc -> Maybe Doc
forall a b. (a -> b) -> a -> b
$
[Doc] -> Doc
forall a. Monoid a => [a] -> a
mconcat
[ forall a ann. Pretty a => a -> Doc ann
PP.pretty @String String
"Ping a cardano node either using node-to-node or node-to-client protocol. "
, forall a ann. Pretty a => a -> Doc ann
PP.pretty @String String
"It negotiates a handshake and keeps sending keep alive messages."
]
]
pHost :: Opt.Parser String
pHost :: Parser String
pHost =
Mod OptionFields String -> Parser String
forall s. IsString s => Mod OptionFields s -> Parser s
Opt.strOption (Mod OptionFields String -> Parser String)
-> Mod OptionFields String -> Parser String
forall a b. (a -> b) -> a -> b
$
[Mod OptionFields String] -> Mod OptionFields String
forall a. Monoid a => [a] -> a
mconcat
[ String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
Opt.long String
"host"
, Char -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => Char -> Mod f a
Opt.short Char
'h'
, String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
Opt.metavar String
"HOST"
, String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
Opt.help String
"Hostname/IP, e.g. relay.iohk.example."
]
pUnixSocket :: Opt.Parser String
pUnixSocket :: Parser String
pUnixSocket =
Mod OptionFields String -> Parser String
forall s. IsString s => Mod OptionFields s -> Parser s
Opt.strOption (Mod OptionFields String -> Parser String)
-> Mod OptionFields String -> Parser String
forall a b. (a -> b) -> a -> b
$
[Mod OptionFields String] -> Mod OptionFields String
forall a. Monoid a => [a] -> a
mconcat
[ String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
Opt.long String
"unixsock"
, Char -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => Char -> Mod f a
Opt.short Char
'u'
, String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
Opt.metavar String
"SOCKET"
, String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
Opt.help String
"Unix socket, e.g. file.socket."
]
pEndPoint :: Opt.Parser EndPoint
pEndPoint :: Parser EndPoint
pEndPoint = (String -> EndPoint) -> Parser String -> Parser EndPoint
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> EndPoint
HostEndPoint Parser String
pHost Parser EndPoint -> Parser EndPoint -> Parser EndPoint
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (String -> EndPoint) -> Parser String -> Parser EndPoint
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> EndPoint
UnixSockEndPoint Parser String
pUnixSocket
pPing :: Opt.Parser PingCmd
pPing :: Parser PingCmd
pPing =
Word32
-> EndPoint
-> String
-> Word32
-> Bool
-> Bool
-> Bool
-> Bool
-> PingCmd
PingCmd
(Word32
-> EndPoint
-> String
-> Word32
-> Bool
-> Bool
-> Bool
-> Bool
-> PingCmd)
-> Parser Word32
-> Parser
(EndPoint
-> String -> Word32 -> Bool -> Bool -> Bool -> Bool -> PingCmd)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ( ReadM Word32 -> Mod OptionFields Word32 -> Parser Word32
forall a. ReadM a -> Mod OptionFields a -> Parser a
Opt.option ReadM Word32
forall a. (Typeable a, Integral a, Bits a) => ReadM a
integralReader (Mod OptionFields Word32 -> Parser Word32)
-> Mod OptionFields Word32 -> Parser Word32
forall a b. (a -> b) -> a -> b
$
[Mod OptionFields Word32] -> Mod OptionFields Word32
forall a. Monoid a => [a] -> a
mconcat
[ String -> Mod OptionFields Word32
forall (f :: * -> *) a. HasName f => String -> Mod f a
Opt.long String
"count"
, Char -> Mod OptionFields Word32
forall (f :: * -> *) a. HasName f => Char -> Mod f a
Opt.short Char
'c'
, String -> Mod OptionFields Word32
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
Opt.metavar String
"COUNT"
, String -> Mod OptionFields Word32
forall (f :: * -> *) a. String -> Mod f a
Opt.help (String -> Mod OptionFields Word32)
-> String -> Mod OptionFields Word32
forall a b. (a -> b) -> a -> b
$
[String] -> String
forall a. Monoid a => [a] -> a
mconcat
[ String
"Stop after sending count requests and receiving count responses. "
, String
"If this option is not specified, ping will operate until interrupted. "
]
, Word32 -> Mod OptionFields Word32
forall (f :: * -> *) a. HasValue f => a -> Mod f a
Opt.value Word32
forall a. Bounded a => a
maxBound
]
)
Parser
(EndPoint
-> String -> Word32 -> Bool -> Bool -> Bool -> Bool -> PingCmd)
-> Parser EndPoint
-> Parser
(String -> Word32 -> Bool -> Bool -> Bool -> Bool -> PingCmd)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser EndPoint
pEndPoint
Parser
(String -> Word32 -> Bool -> Bool -> Bool -> Bool -> PingCmd)
-> Parser String
-> Parser (Word32 -> Bool -> Bool -> Bool -> Bool -> PingCmd)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ( Mod OptionFields String -> Parser String
forall s. IsString s => Mod OptionFields s -> Parser s
Opt.strOption (Mod OptionFields String -> Parser String)
-> Mod OptionFields String -> Parser String
forall a b. (a -> b) -> a -> b
$
[Mod OptionFields String] -> Mod OptionFields String
forall a. Monoid a => [a] -> a
mconcat
[ String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
Opt.long String
"port"
, Char -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => Char -> Mod f a
Opt.short Char
'p'
, String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
Opt.metavar String
"PORT"
, String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
Opt.help String
"Port number, e.g. 1234."
, String -> Mod OptionFields String
forall (f :: * -> *) a. HasValue f => a -> Mod f a
Opt.value String
"3001"
]
)
Parser (Word32 -> Bool -> Bool -> Bool -> Bool -> PingCmd)
-> Parser Word32
-> Parser (Bool -> Bool -> Bool -> Bool -> PingCmd)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ( ReadM Word32 -> Mod OptionFields Word32 -> Parser Word32
forall a. ReadM a -> Mod OptionFields a -> Parser a
Opt.option ReadM Word32
forall a. (Typeable a, Integral a, Bits a) => ReadM a
integralReader (Mod OptionFields Word32 -> Parser Word32)
-> Mod OptionFields Word32 -> Parser Word32
forall a b. (a -> b) -> a -> b
$
[Mod OptionFields Word32] -> Mod OptionFields Word32
forall a. Monoid a => [a] -> a
mconcat
[ String -> Mod OptionFields Word32
forall (f :: * -> *) a. HasName f => String -> Mod f a
Opt.long String
"magic"
, Char -> Mod OptionFields Word32
forall (f :: * -> *) a. HasName f => Char -> Mod f a
Opt.short Char
'm'
, String -> Mod OptionFields Word32
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
Opt.metavar String
"MAGIC"
, String -> Mod OptionFields Word32
forall (f :: * -> *) a. String -> Mod f a
Opt.help String
"Network magic."
, Word32 -> Mod OptionFields Word32
forall (f :: * -> *) a. HasValue f => a -> Mod f a
Opt.value Word32
CNP.mainnetMagic
]
)
Parser (Bool -> Bool -> Bool -> Bool -> PingCmd)
-> Parser Bool -> Parser (Bool -> Bool -> Bool -> PingCmd)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ( Mod FlagFields Bool -> Parser Bool
Opt.switch (Mod FlagFields Bool -> Parser Bool)
-> Mod FlagFields Bool -> Parser Bool
forall a b. (a -> b) -> a -> b
$
[Mod FlagFields Bool] -> Mod FlagFields Bool
forall a. Monoid a => [a] -> a
mconcat
[ String -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => String -> Mod f a
Opt.long String
"json"
, Char -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => Char -> Mod f a
Opt.short Char
'j'
, String -> Mod FlagFields Bool
forall (f :: * -> *) a. String -> Mod f a
Opt.help String
"JSON output flag."
]
)
Parser (Bool -> Bool -> Bool -> PingCmd)
-> Parser Bool -> Parser (Bool -> Bool -> PingCmd)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ( Mod FlagFields Bool -> Parser Bool
Opt.switch (Mod FlagFields Bool -> Parser Bool)
-> Mod FlagFields Bool -> Parser Bool
forall a b. (a -> b) -> a -> b
$
[Mod FlagFields Bool] -> Mod FlagFields Bool
forall a. Monoid a => [a] -> a
mconcat
[ String -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => String -> Mod f a
Opt.long String
"quiet"
, Char -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => Char -> Mod f a
Opt.short Char
'q'
, String -> Mod FlagFields Bool
forall (f :: * -> *) a. String -> Mod f a
Opt.help String
"Quiet flag, CSV/JSON only output"
]
)
Parser (Bool -> Bool -> PingCmd)
-> Parser Bool -> Parser (Bool -> PingCmd)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ( Mod FlagFields Bool -> Parser Bool
Opt.switch (Mod FlagFields Bool -> Parser Bool)
-> Mod FlagFields Bool -> Parser Bool
forall a b. (a -> b) -> a -> b
$
[Mod FlagFields Bool] -> Mod FlagFields Bool
forall a. Monoid a => [a] -> a
mconcat
[ String -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => String -> Mod f a
Opt.long String
"query-versions"
, Char -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => Char -> Mod f a
Opt.short Char
'Q'
, String -> Mod FlagFields Bool
forall (f :: * -> *) a. String -> Mod f a
Opt.help
String
"Query the supported protocol versions using the handshake protocol and terminate the connection."
]
)
Parser (Bool -> PingCmd) -> Parser Bool -> Parser PingCmd
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ( Mod FlagFields Bool -> Parser Bool
Opt.switch (Mod FlagFields Bool -> Parser Bool)
-> Mod FlagFields Bool -> Parser Bool
forall a b. (a -> b) -> a -> b
$
[Mod FlagFields Bool] -> Mod FlagFields Bool
forall a. Monoid a => [a] -> a
mconcat
[ String -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => String -> Mod f a
Opt.long String
"tip"
, Char -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => Char -> Mod f a
Opt.short Char
't'
, String -> Mod FlagFields Bool
forall (f :: * -> *) a. String -> Mod f a
Opt.help String
"Request tip then exit."
]
)