Skip to content

Commit 21a527d

Browse files
committed
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 <[email protected]>
1 parent 45b6eb6 commit 21a527d

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

build/generate-man/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func main() {
2323
log.Fatal(err)
2424
}
2525

26-
cmd := cmd.Command(nil, "OPA")
26+
cmd := cmd.RootCommand
2727
cmd.Use = "opa [command]"
2828
cmd.DisableAutoGenTag = true
2929

cmd/commands.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import (
1010
iversion "github.com/open-policy-agent/opa/internal/version"
1111
)
1212

13+
// Backwards compatibility definition. Newer code should use Command.
14+
var RootCommand = Command(nil, "OPA")
15+
1316
// UserAgent lets you override the OPA UA sent with all the HTTP requests.
1417
// It's another vanity thing -- if you build your own version of OPA, you
1518
// may want to adjust this.

main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ func main() {
1919
}
2020
}() // orderly shutdown, run all defer routines
2121

22-
root := cmd.Command(nil, "OPA")
23-
if err := root.Execute(); err != nil {
22+
if err := cmd.RootCommand.Execute(); err != nil {
2423
var e *cmd.ExitError
2524
if errors.As(err, &e) {
2625
exit = e.Exit

0 commit comments

Comments
 (0)