Skip to content

Commit

Permalink
unixsoc depend on handshake-only
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-lipski committed Dec 18, 2023
1 parent 8a0c9f7 commit c52dc8a
Showing 1 changed file with 84 additions and 25 deletions.
109 changes: 84 additions & 25 deletions cardano-cli/src/Cardano/CLI/Run/Ping.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ data PingCmd = PingCmd

pingClient :: Tracer IO CNP.LogMsg -> Tracer IO String -> PingCmd -> [CNP.NodeVersion] -> AddrInfo -> IO ()
pingClient stdout stderr cmd = CNP.pingClient stdout stderr opts
where opts = CNP.PingOpts
where
opts = CNP.PingOpts
{ CNP.pingOptsQuiet = pingCmdQuiet cmd
, CNP.pingOptsJson = pingCmdJson cmd
, CNP.pingOptsCount = pingCmdCount cmd
, CNP.pingOptsHost = maybeHostEndPoint (pingCmdEndPoint cmd)
, CNP.pingOptsUnixSock = maybeUnixSockEndPoint (pingCmdEndPoint cmd)
, CNP.pingOptsHost = maybeHostEndPoint $ pingCmdEndPoint cmd
, CNP.pingOptsUnixSock = maybeUnixSockEndPoint $ pingCmdEndPoint cmd
, CNP.pingOptsPort = pingCmdPort cmd
, CNP.pingOptsMagic = pingCmdMagic cmd
, CNP.pingOptsHandshakeQuery = pingOptsHandshakeQuery cmd
Expand Down Expand Up @@ -136,47 +137,97 @@ parsePingCmd = Opt.hsubparser $ mconcat
]
]

pHost :: Opt.Parser String
pHost =
Opt.strOption $ mconcat
pHost :: Bool -> Opt.Parser EndPoint
pHost internal = fmap HostEndPoint
( Opt.strOption $ mconcat
[ Opt.long "host"
, Opt.short 'h'
, Opt.metavar "HOST"
, Opt.help "Hostname/IP, e.g. relay.iohk.example."
]
, if internal then Opt.internal else mempty
])

pHandshakeOnly :: Opt.Parser ()
pHandshakeOnly =
( Opt.flag' () $ mconcat
[ Opt.long "handshake-only"
, Opt.help "Perform only the handshake process without sending a ping."
])

Check notice

Code scanning / HLint

Redundant bracket Note

cardano-cli/src/Cardano/CLI/Run/Ping.hs:(152,3)-(155,6): Suggestion: Redundant bracket
  
Found:
  (Opt.flag' ()
     $ mconcat
         [Opt.long "handshake-only",
          Opt.help
            "Perform only the handshake process without sending a ping."])
  
Perhaps:
  Opt.flag' ()
    $ mconcat
        [Opt.long "handshake-only",
         Opt.help
           "Perform only the handshake process without sending a ping."]

pUnixSocket :: Opt.Parser String
pUnixSocket =
Opt.strOption $ mconcat
pUnixSocket :: Opt.Parser EndPoint
pUnixSocket = fmap UnixSockEndPoint
( Opt.strOption $ mconcat
[ Opt.long "unixsock"
, Opt.short 'u'
, Opt.metavar "SOCKET"
, Opt.help "Unix socket, e.g. file.socket."
]

pEndPoint :: Opt.Parser EndPoint
pEndPoint = fmap HostEndPoint pHost <|> fmap UnixSockEndPoint pUnixSocket
, Opt.help $ mconcat
[ "Unix socket, e.g. file.socket. "
, "Requires the --hanshake-only flag. "
]
])

pPing :: Opt.Parser PingCmd
pPing = PingCmd
pPingNoHandshakeOnly :: Opt.Parser PingCmd
pPingNoHandshakeOnly = PingCmd
<$> ( Opt.option Opt.auto $ mconcat
[ Opt.long "count"
, Opt.short 'c'
, Opt.metavar "COUNT"
[ Opt.long "count"
, Opt.short 'c'
, Opt.metavar "COUNT"
, Opt.help $ mconcat
[ "Stop after sending count requests and receiving count responses. "
, "If this option is not specified, ping will operate until interrupted. "
]
, Opt.value maxBound
]
)
<*> (pHost False)

Check notice

Code scanning / HLint

Redundant bracket Note

cardano-cli/src/Cardano/CLI/Run/Ping.hs:182:7-19: Suggestion: Redundant bracket
  
Found:
  PingCmd
    <$>
      (Opt.option Opt.auto
         $ mconcat
             [Opt.long "count", Opt.short 'c', Opt.metavar "COUNT",
              Opt.help
                $ mconcat
                    ["Stop after sending count requests and receiving count responses.  ",
                     "If this option is not specified, ping will operate until interrupted.  "],
              Opt.value maxBound])
    <> (pHost False)
  
Perhaps:
  PingCmd
    <$>
      (Opt.option Opt.auto
         $ mconcat
             [Opt.long "count", Opt.short 'c', Opt.metavar "COUNT",
              Opt.help
                $ mconcat
                    ["Stop after sending count requests and receiving count responses.  ",
                     "If this option is not specified, ping will operate until interrupted.  "],
              Opt.value maxBound])
    <> pHost False
<*> ( Opt.strOption $ mconcat
[ Opt.long "port"
, Opt.short 'p'
, Opt.metavar "PORT"
, Opt.help "Port number, e.g. 1234."
, Opt.value "3001"
]
)
<*> ( Opt.option Opt.auto $ mconcat
[ Opt.long "magic"
, Opt.short 'm'
, Opt.metavar "MAGIC"
, Opt.help "Network magic."
, Opt.value CNP.mainnetMagic
]
)
<*> ( Opt.switch $ mconcat
[ Opt.long "json"
, Opt.short 'j'
, Opt.help "JSON output flag."
]
)
<*> ( Opt.switch $ mconcat
[ Opt.long "quiet"
, Opt.short 'q'
, Opt.help "Quiet flag, CSV/JSON only output"
]
)
<*> ( Opt.switch $ mconcat
[ Opt.long "query-versions"
, Opt.short 'Q'
, Opt.help $ mconcat
[ "Stop after sending count requests and receiving count responses. "
, "If this option is not specified, ping will operate until interrupted. "
[ "Query the supported protocol versions using the handshake protocol and terminate the connection. "
, "(deprecated; use under --handshake-only instead)."
]
, Opt.value maxBound
]
)
<*> pEndPoint

pPingHanshakeOnly :: Opt.Parser PingCmd
pPingHanshakeOnly = PingCmd 0
<$> (pHandshakeOnly *> ((pHost True) <|> pUnixSocket))

Check notice

Code scanning / HLint

Redundant bracket Note

cardano-cli/src/Cardano/CLI/Run/Ping.hs:223:27-38: Suggestion: Redundant bracket
  
Found:
  (pHost True) <|> pUnixSocket
  
Perhaps:
  pHost True <|> pUnixSocket
<*> ( Opt.strOption $ mconcat
[ Opt.long "port"
, Opt.short 'p'
, Opt.metavar "PORT"
, Opt.help "Port number, e.g. 1234."
, Opt.value "3001"
, Opt.internal
]
)
<*> ( Opt.option Opt.auto $ mconcat
Expand All @@ -185,23 +236,31 @@ pPing = PingCmd
, Opt.metavar "MAGIC"
, Opt.help "Network magic."
, Opt.value CNP.mainnetMagic
, Opt.internal
]
)
<*> ( Opt.switch $ mconcat
[ Opt.long "json"
, Opt.short 'j'
, Opt.help "JSON output flag."
, Opt.internal
]
)
<*> ( Opt.switch $ mconcat
[ Opt.long "quiet"
, Opt.short 'q'
, Opt.help "Quiet flag, CSV/JSON only output"
, Opt.internal
]
)
<*> ( Opt.switch $ mconcat
[ Opt.long "query-versions"
, Opt.short 'Q'
, Opt.help "Query the supported protocol versions using the handshake protocol and terminate the connection."
, Opt.help "Query the supported protocol versions using the handshake protocol and terminate the connection. "
, Opt.internal
]
)


pPing :: Opt.Parser PingCmd
pPing = pPingNoHandshakeOnly <|> pPingHanshakeOnly

0 comments on commit c52dc8a

Please sign in to comment.