From 84b23ccedd1d02206a431004ec04f62a9da68a29 Mon Sep 17 00:00:00 2001 From: Philip Conrad Date: Thu, 31 Jul 2025 12:55:34 -0400 Subject: [PATCH] bugfix: Add back default cmd.RootCommand definition. (#7811) This commit fixes an issue when upgrading codebases to OPA v1.7.0. In PR #7797, we introduced the ability to provide "branding" information in OPA commands and help messages, which would allow easier customized OPA distributions in the future. However, this changeset removed the public symbol `cmd.RootCommand`, and required refactoring to use `cmd.Command`, which breaks automated upgrades, such as those done by Dependabot. This PR adds back the missing symbol, with the original/default "OPA" branding provided. This should allow existing codebases to upgrade without requiring any code changes. Signed-off-by: Philip Conrad --- build/generate-man/generate.go | 2 +- cmd/commands.go | 3 +++ main.go | 3 +-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/build/generate-man/generate.go b/build/generate-man/generate.go index e16e6930fd..cc14db0c34 100644 --- a/build/generate-man/generate.go +++ b/build/generate-man/generate.go @@ -23,7 +23,7 @@ func main() { log.Fatal(err) } - cmd := cmd.Command(nil, "OPA") + cmd := cmd.RootCommand cmd.Use = "opa [command]" cmd.DisableAutoGenTag = true diff --git a/cmd/commands.go b/cmd/commands.go index 7db65b5f8f..dcd8cdb827 100644 --- a/cmd/commands.go +++ b/cmd/commands.go @@ -10,6 +10,9 @@ import ( iversion "github.com/open-policy-agent/opa/internal/version" ) +// Backwards compatibility definition. Newer code should use Command. +var RootCommand = Command(nil, "OPA") + // UserAgent lets you override the OPA UA sent with all the HTTP requests. // It's another vanity thing -- if you build your own version of OPA, you // may want to adjust this. diff --git a/main.go b/main.go index 8fc400e700..eaa60b3a37 100644 --- a/main.go +++ b/main.go @@ -19,8 +19,7 @@ func main() { } }() // orderly shutdown, run all defer routines - root := cmd.Command(nil, "OPA") - if err := root.Execute(); err != nil { + if err := cmd.RootCommand.Execute(); err != nil { var e *cmd.ExitError if errors.As(err, &e) { exit = e.Exit