Skip to content

A Path to v2.0#482

Open
tomasaschan wants to merge 7 commits into
masterfrom
a-path-to-v2
Open

A Path to v2.0#482
tomasaschan wants to merge 7 commits into
masterfrom
a-path-to-v2

Conversation

@tomasaschan

Copy link
Copy Markdown
Collaborator

There are a lot of things in this library that I'd love to fix - but most of the fixes become a lot more complicated to execute on, because we also need to maintain backwards compatibility. (The response to release v1.0.8 shows that this is clearly important to at least some, loud, part of the community.)

I no longer want to keep adding //nolint comments to allow for keeping code compatible with Go 1.12, released in 2019 with the last minor release published in 2020. I no longer want to fight to keep APIs and behavior consistent across umpteen almost but not quite identical implementations of parsing flag values to slices of various primitive types. I no longer want to keep names like Blacklist in the public API.

I'm opening this PR in very early draft to start carving a path to a new major version of this library, that allows us to fix all of the above without breaking semver promises. Before this is actually released, it is likely also a good idea to move it to an import path that is not tied to a single Github user's account - but we have to start somewhere. As a first step, I just want to have CI in place to start iterating.

@tomasaschan tomasaschan marked this pull request as ready for review June 26, 2026 09:58
tomasaschan and others added 2 commits June 26, 2026 12:35
Run Go's own flag package test suite against pflag v2 (dot-imported as
"flag") to keep the drop-in-replacement promise honest. The suite is the
spec for v2: as the package is currently empty, every failure is an
implementation gap to close (see v2/conformance/README.md for the gap
list / TODO).

The suite is build-tagged "conformance" so it does not affect the normal
`go test ./...` run, and is Go-version aware: a separate copy of upstream
flag_test.go is vendored per minor version, each pinned with a build
constraint (e.g. go1.26 && !go1.27), so the CI matrix tests each
supported Go release against that release's own flag tests and upstream
changes surface as diffs. hack/sync.sh regenerates the copies (also wired
to `go generate ./conformance/...`); a guard test fails loudly if the
running toolchain has no vendored copy.

Adds a non-blocking conformance-v2 CI job (continue-on-error until v2 is
complete).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add the second conformance promise (POSIX/GNU argument syntax) alongside
the vendored stdlib flag suite, plus the machinery to reconcile the two
when they conflict.

- gnuposix_test.go: hand-written suite keyed to the POSIX Utility Syntax
  Guidelines (1-14) and the GNU long-option extensions. No reusable
  Go-native POSIX corpus exists to vendor, so each case cites the rule it
  checks.

- divergences.json: single source of truth cataloguing the intentional
  differences between pflag and the stdlib flag package. POSIX wins, so
  the listed stdlib tests are *expected* to fail; each entry names them
  and the rule that overrides them. Categories: posix-overrides-stdlib,
  pflag-design-differs, pflag-omits-gnu-feature, not-implemented-yet.

- hack/oracle: reads `go test -json` and gates CI on the catalogue rather
  than raw pass/fail: green iff failures match the documented set exactly
  (catches regressions and silently-resolved divergences). The top-level
  "status" field tolerates a build failure while "bootstrapping" so CI is
  green during v2 build-out; "not-implemented-yet" entries are lenient
  (tolerated when failing, retirable when they start passing).

- internal/divergence: catalogue types + parsing, shared by the manifest
  test and the oracle (no build tag, no v2 dependency).

CI conformance-v2 job now pipes the suite through the oracle and drops
continue-on-error; it is green now (bootstrapping) and tightens to
enforcing once v2 compiles.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant