Skip to content

[Feature] Export an OpenCLI-compliant command description with --cli-schema #5263

Description

@arturcic

Feature request

Add gitversion --cli-schema to export an OpenCLI-compliant JSON description of GitVersion's command-line interface.

Tools should be able to discover GitVersion's commands, arguments, options, and invocation rules without scraping --help output or maintaining a separate command catalog. This would support generated documentation, shell completion, CLI compatibility checks, and integrations such as MCP wrappers.

Proposed behavior

gitversion --cli-schema
gitversion --cli-schema > gitversion.opencli.json
  • Write one complete OpenCLI JSON document to stdout and exit successfully.
  • Export the full command tree, including the root command, supported subcommands, built-in help/version options, and the schema option itself.
  • Make --cli-schema available recursively. When supplied to a subcommand, export the same full document; document this behavior explicitly so consumers do not need to reconstruct a partial command path.
  • Allow export outside a Git repository, without a configuration file, and without supplying the selected command's normally required operands.
  • Treat export as an informational operation: do not calculate a repository version, fetch or normalize a repository, load repository configuration, create caches, migrate configuration, or update files.
  • Keep stdout free of logs, banners, and version-calculation output. Report export failures on stderr with a nonzero exit code.
  • Keep output deterministic for a given GitVersion build. info.version identifies the GitVersion executable version, rather than a version calculated from the current repository.

These invocation and execution rules are proposed GitVersion behavior. OpenCLI defines the description format; it does not require a particular export flag.

OpenCLI contract

Target the published OpenCLI specification, currently proposal version 0.1. Record the exact specification revision used during implementation, since the proposal can evolve without the displayed version changing.

  • Emit the required opencli, info, and command fields, including info.title, info.version, and required command/argument/option names.
  • Use the specified case-sensitive field names and arrays for commands, options, arguments, aliases, and other collections. Preserve normative array ordering, especially positional arguments.
  • Accurately describe aliases, descriptions, hidden status, required status, option arguments, argument arity, statically known accepted values, and recursive options. Map unlimited arity to OpenCLI's representation rather than exposing an implementation-specific integer limit.
  • Represent flag options and options that consume values correctly. Optional value-taking options and repeated arguments need particular attention.
  • Ensure declared parsing conventions reflect GitVersion's actual behavior. Explicitly override OpenCLI defaults where those defaults do not match the parser.
  • Add application metadata and, where supported, documented examples, exit codes, and interactive behavior through explicit metadata rather than inference from handler execution.
  • Follow OpenCLI directly rather than assuming the .NET SDK's --cli-schema JSON format is already equivalent.

Implementation direction and scope

The shipped CLI already defines a System.CommandLine command tree in src/GitVersion.App/ArgumentParser.cs. Introduce an adapter that walks those existing definitions and serializes OpenCLI objects, with explicit supplemental metadata for information the command model does not provide.

Handle schema export before normal argument/configuration validation and command execution. Avoid maintaining a second handwritten list of commands and options, and avoid executing handlers or environment-dependent default factories to discover metadata.

The initial target is the shipped System.CommandLine CLI under src/. Integration with the experimental new-cli/ tree and support for the legacy compatibility parser should be assessed separately and documented rather than assumed. Existing help, version calculation, configuration schema generation, and build-agent outputs should retain their behavior. This feature describes the CLI interface; it does not replace the JSON schemas for GitVersion.yml.

Acceptance criteria

  • The root and supported subcommand invocations of --cli-schema produce a complete, parseable OpenCLI JSON document and exit with code 0.
  • Export works from an empty directory with no Git repository/configuration and bypasses required operands for the selected command.
  • Representative cases cover aliases, flags, value-taking options, optional values, required and repeated arguments, accepted values, hidden entries, and recursive options.
  • Output agrees with the actual registered command tree and preserves positional argument order.
  • Conformance is checked against the pinned OpenCLI specification; any machine-readable validation schema is verified against the normative text rather than treated as the sole authority.
  • Integration tests verify clean stdout, deterministic output, executable version metadata, and absence of repository/configuration/file side effects.
  • Existing help/version, normal commands, and build-agent output behavior pass relevant regression checks.
  • Documentation explains invocation, output format/specification revision, subcommand behavior, supported parser mode, and that OpenCLI remains a proposal.

References

Triage — 2026-09-29

  • Classification: additive CLI feature.
  • Delivery milestone: 7.0.x; additive CLI capability for v7.0. Complete it or explicitly defer it before the v7.0 release-readiness decision.
  • Tracking: standalone delivery issue under the v7 roadmap (#5137), rather than the experimental new-CLI umbrella.
  • Initial scope: the shipped System.CommandLine parser under src/; no legacy-parser implementation requirement.
  • Dependencies: no confirmed blocking dependency. The current shipped command tree is sufficient to implement the exporter; removal of the legacy parser (v7.1: remove legacy argument parser and v6 configuration runtime #5188), managed Git work, and completion of the experimental CLI ([Feature] New CLI #2275) are not prerequisites.
  • Before implementation: pin the OpenCLI proposal revision and review the metadata mapping and informational execution path. Existing acceptance criteria define conformance, output purity, deterministic metadata, and regression coverage.

Activity

  1. added this to the 7.1.x milestone on Sep 29, 2026
  2. modified the milestones: 7.1.x, 7.0.x on Sep 29, 2026
  3. added theissue type on Sep 29, 2026
  4. modified the milestones: 7.0.x, 7.0.0 on Nov 15, 2026
  5. github-actions commented on Nov 17, 2026

    @github-actions

    🎉 This issue has been resolved in version 7.0.0 🎉
    The release is available on:

    Your GitReleaseManager bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions