Skip to content

Commit ae2abbc

Browse files
Cleanup some dryrun details
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]>
1 parent 489b1a3 commit ae2abbc

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

.vscode/launch.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@
9494
"MANAGED_CONFIG": "${userHome}/git/governance-policy-framework/kubeconfig_managed",
9595
"KUBECONFIG": "${userHome}/git/governance-policy-framework/kubeconfig_managed",
9696
}
97+
},
98+
// Set inputs in the args section.
99+
{
100+
"name": "Launch dryrun (instructions in launch.json)",
101+
"type": "go",
102+
"request": "launch",
103+
"mode": "auto",
104+
"program": "${workspaceFolder}/cmd/dryrun/main.go",
105+
"console": "integratedTerminal",
106+
"args": [
107+
"-p",
108+
"${workspaceFolder}/pkg/dryrun/testdata/test_basic_noncompliant/policy.yaml",
109+
"${workspaceFolder}/pkg/dryrun/testdata/test_basic_noncompliant/input_1.yaml",
110+
]
97111
}
98112
]
99113
}

cmd/dryrun/main.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
package main
44

55
import (
6-
"errors"
76
"os"
87

98
"open-cluster-management.io/config-policy-controller/pkg/dryrun"
@@ -12,10 +11,6 @@ import (
1211
func main() {
1312
err := dryrun.Execute()
1413
if err != nil {
15-
if errors.Is(err, dryrun.ErrNonCompliant) {
16-
os.Exit(2)
17-
}
18-
1914
os.Exit(1)
2015
}
2116
}

pkg/dryrun/cmd.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ func (d *DryRunner) GetCmd() *cobra.Command {
8989
RunE: mappings.GenerateMappings,
9090
})
9191

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

9594
return cmd
9695
}

pkg/dryrun/dryrun.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ import (
4444
)
4545

4646
func (d *DryRunner) dryRun(cmd *cobra.Command, args []string) error {
47+
// The "usage" output will still be emitted if a required flag is missing,
48+
// or if an unknown flag was passed.
49+
cmd.SilenceUsage = true
50+
4751
cfgPolicy, err := d.readPolicy(cmd)
4852
if err != nil {
4953
return fmt.Errorf("unable to read input policy: %w", err)

0 commit comments

Comments
 (0)