Skip to content

Commit

Permalink
Cleanup some dryrun details
Browse files Browse the repository at this point in the history
Adds a launch.json configuration for running/debugging the cli. Also
more correctly silences the usage doc: if inputs are incorrect, it is
helpful to print the doc.

Signed-off-by: Justin Kulikauskas <[email protected]>
  • Loading branch information
JustinKuli authored and openshift-merge-bot[bot] committed Oct 3, 2024
1 parent 489b1a3 commit ae2abbc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@
"MANAGED_CONFIG": "${userHome}/git/governance-policy-framework/kubeconfig_managed",
"KUBECONFIG": "${userHome}/git/governance-policy-framework/kubeconfig_managed",
}
},
// Set inputs in the args section.
{
"name": "Launch dryrun (instructions in launch.json)",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/dryrun/main.go",
"console": "integratedTerminal",
"args": [
"-p",
"${workspaceFolder}/pkg/dryrun/testdata/test_basic_noncompliant/policy.yaml",
"${workspaceFolder}/pkg/dryrun/testdata/test_basic_noncompliant/input_1.yaml",
]
}
]
}
5 changes: 0 additions & 5 deletions cmd/dryrun/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package main

import (
"errors"
"os"

"open-cluster-management.io/config-policy-controller/pkg/dryrun"
Expand All @@ -12,10 +11,6 @@ import (
func main() {
err := dryrun.Execute()
if err != nil {
if errors.Is(err, dryrun.ErrNonCompliant) {
os.Exit(2)
}

os.Exit(1)
}
}
3 changes: 1 addition & 2 deletions pkg/dryrun/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ func (d *DryRunner) GetCmd() *cobra.Command {
RunE: mappings.GenerateMappings,
})

cmd.SetOut(os.Stdout) // sets default output to stdout, otherwise it is stderr
cmd.SilenceUsage = true // otherwise all errors will be followed by the usage doc
cmd.SetOut(os.Stdout) // sets default output to stdout, otherwise it is stderr

return cmd
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/dryrun/dryrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ import (
)

func (d *DryRunner) dryRun(cmd *cobra.Command, args []string) error {
// The "usage" output will still be emitted if a required flag is missing,
// or if an unknown flag was passed.
cmd.SilenceUsage = true

cfgPolicy, err := d.readPolicy(cmd)
if err != nil {
return fmt.Errorf("unable to read input policy: %w", err)
Expand Down

0 comments on commit ae2abbc

Please sign in to comment.