Skip to content

Replace cardano-diffusion's ping parser with an identical local parser - #1413

Merged
Jimbo4350 merged 1 commit into
masterfrom
jordan/ping-parser-drop-network-cmdline-parser
Aug 13, 2026
Merged

Replace cardano-diffusion's ping parser with an identical local parser#1413
Jimbo4350 merged 1 commit into
masterfrom
jordan/ping-parser-drop-network-cmdline-parser

Conversation

@Jimbo4350

@Jimbo4350 Jimbo4350 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Changelog

- description: |
    Fixed `cardano-cli ping`'s dependency on the command line parser of `cardano-diffusion:ping`, which made the released package unbuildable with default cabal flags (it required a manual `optparse-applicative-fork` cabal flag set via `cabal.project`, which does not ship with the sdist). The parser is replaced with a behaviourally identical local one; the command line interface is unchanged.
  type:
    # - feature        # introduces a new feature
    # - breaking     # the API has changed in a breaking way
    # - compatible   # the API has changed but is non-breaking
    # - optimisation # measurable performance improvements
    # - refactoring  # QoL changes
    - bugfix         # fixes a defect
    # - test         # fixes/modifies tests
    # - maintenance  # not directly related to the code
    # - release      # related to a new release preparation
    # - documentation # change in code docs, haddocks...

Context

The cardano-cli-11.2.0.0 release cannot be added to CHaP: CHaP PR #1431 fails build-new-packages (CI run) because pPing = uncurry PingCmd <$> Ping.cmdlineParser mixes Parser types from two different packages: cardano-cli uses optparse-applicative-fork, while Ping.cmdlineParser is built against plain optparse-applicative unless the manual cabal flag optparse-applicative-fork of cardano-diffusion is set. This repo set that flag in cabal.project, but cabal.project does not ship with the sdist and manual flags are never flipped by the solver, so the released package is unbuildable for CHaP CI and for every downstream consumer with default flags.

The fix is to stop using Ping.cmdlineParser and give cardano-cli its own ping parser written against optparse-applicative-fork, so no optparse type crosses the package boundary and the flag becomes irrelevant. The package cardano-diffusion / flags: +optparse-applicative-fork stanza is removed from cabal.project to prove it: the build now succeeds with cardano-diffusion's default flags, exactly like CHaP CI builds it.

The command line interface is unchanged: the local parser is a verbatim copy (modulo qualification) of Cardano.Network.Ping.cmdlineParser — same options, readers, defaults and help text — so cardano-cli ping behaves exactly as it does on master. Ping/Command.hs, Ping/Run.hs and the golden help files are untouched relative to master; the whole change is confined to Ping/Option.hs plus tests.

The follow-up release cardano-cli-11.2.1.0 will supersede CHaP PR #1431 (the 11.2.0.0 sdist cannot be fixed in place). Once released, the network team can drop the optparse-applicative-fork flag from cardano-diffusion (added as a stopgap in ouroboros-network#5392).

How to trust this PR

  • The cabal.project no longer sets +optparse-applicative-fork for cardano-diffusion, so CI now builds cardano-diffusion:ping exactly as CHaP CI does — with plain optparse-applicative — and cardano-cli still compiles.
  • The golden help files (help.cli, help/ping.cli) are byte-identical to master's and the golden tests pass, so the rendered cardano-cli ping help output is unchanged.
  • The parser body in Ping/Option.hs is a line-for-line copy of pingOptsParser/argParser from Cardano.Network.Ping, so it can be reviewed by diffing the two side by side.
  • Test.Cli.Ping pins the parser's behaviour: the defaults (count, mainnet magic, text output, ping mode, _cardano._tcp SRV prefix, auto color, full hash), every option and its reader (--mode, --color accept exactly their three values), address classification (IP-literal-with-port vs domain-with-port vs file path vs SRV name), and rejected command lines — including the pre-11.2 spellings (--host, --unixsock, --port, --magic, -t, -Q), which stay gone.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated
  • Self-reviewed the diff

Copilot AI lite review requested due to automatic review settings August 12, 2026 14:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR restores cardano-cli ping’s flag-based interface by replacing the dependency on cardano-diffusion:ping’s command-line parser with a local optparse-applicative-fork-based parser, unblocking downstream builds (e.g., CHaP) that cannot flip manual cabal flags in released sdists.

Changes:

  • Introduces a local ping option parser supporting repeatable endpoints (--host, --unixsock, --srv) plus new flags (--color, --short-hash) and precedence rules (--query-versions over --tip).
  • Adds a dedicated Test.Cli.Ping test module to lock down endpoint-to-Address mapping and default option behavior.
  • Updates golden help output and removes the cardano-diffusion +optparse-applicative-fork flag override from cabal.project.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
cardano-cli/src/Cardano/CLI/EraIndependent/Ping/Option.hs Implements the local flag-based ping parser and endpoint-to-address conversion logic.
cardano-cli/test/cardano-cli-test/Test/Cli/Ping.hs Adds parser-focused tests for endpoints, defaults, and failure cases.
cardano-cli/test/cardano-cli-golden/files/golden/help/ping.cli Updates command-specific help text to reflect the restored flag interface.
cardano-cli/test/cardano-cli-golden/files/golden/help.cli Updates aggregated CLI help output for the ping command.
cardano-cli/cardano-cli.cabal Registers the new test module and adds needed test-suite dependencies.
cabal.project Removes the cardano-diffusion manual flag override to ensure default-flag buildability.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +44 to +51
pHost :: Opt.Parser PingEndPoint
pHost =
fmap HostEndPoint $
Opt.strOption $
mconcat
[ Opt.long "host"
, Opt.short 'h'
, Opt.metavar "HOST"
Comment on lines +20 to +24
parsePingCmd :: [String] -> Maybe PingCmd
parsePingCmd =
Opt.getParseResult
. Opt.execParserPure Opt.defaultPrefs (Opt.info pPing mempty)

@Jimbo4350 Jimbo4350 changed the title Replace cardano-diffusion's ping parser with a local flag-based parser Replace cardano-diffusion's ping parser with an identical local parser Aug 13, 2026
@Jimbo4350
Jimbo4350 force-pushed the jordan/ping-parser-drop-network-cmdline-parser branch 2 times, most recently from ff48d1c to 996c65e Compare August 13, 2026 14:43
cardano-cli used Ping.cmdlineParser from cardano-diffusion:ping, which
only type-checks when cardano-diffusion is built with its manual
optparse-applicative-fork cabal flag. That flag was set via
cabal.project, which does not ship with the sdist, so the released
package was unbuildable with default flags (CHaP CI rejected 11.2.0.0).

The parser is replaced with a verbatim local copy written against
optparse-applicative-fork: same options, readers, defaults and help
text, so the command line interface is unchanged. The cabal.project
flag stanza is removed, and Test.Cli.Ping pins the parser's defaults,
option readers, address classification and rejected command lines.
@Jimbo4350
Jimbo4350 force-pushed the jordan/ping-parser-drop-network-cmdline-parser branch from 996c65e to 8d29779 Compare August 13, 2026 15:48
@Jimbo4350
Jimbo4350 merged commit 8671a83 into master Aug 13, 2026
30 of 32 checks passed
@Jimbo4350
Jimbo4350 deleted the jordan/ping-parser-drop-network-cmdline-parser branch August 13, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants