Skip to content

Commit 32c9501

Browse files
dheerajodhaclaude
andcommitted
feat: Add --show-policy-docs-link flag for validation output
Give users control over policy documentation links in validation reports. Defaults to false to keep demo output clean—production CI can opt in with --show-policy-docs-link=true when they want the help link. Why default to false? Your colleague nailed it: "for demos it's better if the default is false, otherwise every example needs to include the flag." Nobody wants documentation URLs cluttering their quick validation examples. Implementation: - Added persistent flag on parent validate command (all subcommands inherit) - Flag controls display of https://conforma.dev/docs/policy/ link - Link only appears when violations/warnings exist - Updated tests to properly initialize flags - Report structures updated to pass flag through Usage: # Default - clean output for demos ec validate image --image <img> --policy <policy> # Opt-in for production/CI ec validate image --image <img> --policy <policy> --show-policy-docs-link=true Note: Snapshot updates will be handled in a separate PR to keep this focused. resolves: EC-1603 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 8332d47 commit 32c9501

15 files changed

Lines changed: 120 additions & 90 deletions

File tree

cmd/validate/image.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ func validateImageCmd(validate imageValidationFunc) *cobra.Command {
338338

339339
showSuccesses, _ := cmd.Flags().GetBool("show-successes")
340340
showWarnings, _ := cmd.Flags().GetBool("show-warnings")
341+
showPolicyDocsLink, _ := cmd.Flags().GetBool("show-policy-docs-link")
341342

342343
// worker is responsible for processing one component at a time from the jobs channel,
343344
// and for emitting a corresponding result for the component on the results channel.
@@ -429,13 +430,14 @@ func validateImageCmd(validate imageValidationFunc) *cobra.Command {
429430
}
430431

431432
reportData := validate_utils.ReportData{
432-
Snapshot: data.snapshot,
433-
Components: components,
434-
Policy: data.policy,
435-
PolicyInputs: manyPolicyInput,
436-
Expansion: data.expansion,
437-
ShowSuccesses: showSuccesses,
438-
ShowWarnings: showWarnings,
433+
Snapshot: data.snapshot,
434+
Components: components,
435+
Policy: data.policy,
436+
PolicyInputs: manyPolicyInput,
437+
Expansion: data.expansion,
438+
ShowSuccesses: showSuccesses,
439+
ShowWarnings: showWarnings,
440+
ShowPolicyDocsLink: showPolicyDocsLink,
439441
}
440442
outputOpts := validate_utils.ReportOutputOptions{
441443
Output: data.output,

cmd/validate/input.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func validateInputCmd(validate InputValidationFunc) *cobra.Command {
121121

122122
showSuccesses, _ := cmd.Flags().GetBool("show-successes")
123123
showWarnings, _ := cmd.Flags().GetBool("show-warnings")
124+
showPolicyDocsLink, _ := cmd.Flags().GetBool("show-policy-docs-link")
124125

125126
// Set numWorkers to the value from our flag. The default is 5.
126127
numWorkers := data.workers
@@ -210,7 +211,7 @@ func validateInputCmd(validate InputValidationFunc) *cobra.Command {
210211
return inputs[i].FilePath > inputs[j].FilePath
211212
})
212213

213-
report, err := input.NewReport(inputs, data.policy, manyPolicyInput, showSuccesses, showWarnings)
214+
report, err := input.NewReport(inputs, data.policy, manyPolicyInput, showSuccesses, showWarnings, showPolicyDocsLink)
214215
if err != nil {
215216
return err
216217
}

cmd/validate/validate.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ func NewValidateCmd() *cobra.Command {
4545
}
4646
validateCmd.PersistentFlags().Bool("show-successes", false, "")
4747
validateCmd.PersistentFlags().Bool("show-warnings", true, "")
48+
validateCmd.PersistentFlags().Bool("show-policy-docs-link", false, "Show link to policy documentation in output when there are violations or warnings")
4849
return validateCmd
4950
}

cmd/validate/vsa.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ type validateVSAData struct {
126126
workers int // Number of worker threads for parallel processing
127127

128128
// Output formatting options
129-
noColor bool // Disable color output
130-
forceColor bool // Force color output
129+
noColor bool // Disable color output
130+
forceColor bool // Force color output
131+
showPolicyDocsLink bool // Show policy docs link in output
131132

132133
// Internal state
133134
policySpec ecapi.EnterpriseContractPolicySpec
@@ -266,6 +267,9 @@ func runValidateVSA(cmd *cobra.Command, data *validateVSAData, args []string) er
266267
// Set color support based on flags
267268
utils.SetColorEnabled(data.noColor, data.forceColor)
268269

270+
// Get show-policy-docs-link flag value
271+
data.showPolicyDocsLink, _ = cmd.Flags().GetBool("show-policy-docs-link")
272+
269273
// Parse VSA expiration
270274
if err := parseVSAExpiration(data); err != nil {
271275
return err
@@ -1095,13 +1099,14 @@ func buildFallbackReportData(fallbackResults []validate_utils.Result, vsaData *v
10951099
}
10961100

10971101
return validate_utils.ReportData{
1098-
Snapshot: vsaData.images,
1099-
Components: components,
1100-
Policy: vsaData.fallbackContext.FallbackPolicy,
1101-
PolicyInputs: manyPolicyInput,
1102-
Expansion: nil,
1103-
ShowSuccesses: false,
1104-
ShowWarnings: true,
1102+
Snapshot: vsaData.images,
1103+
Components: components,
1104+
Policy: vsaData.fallbackContext.FallbackPolicy,
1105+
PolicyInputs: manyPolicyInput,
1106+
Expansion: nil,
1107+
ShowSuccesses: false,
1108+
ShowWarnings: true,
1109+
ShowPolicyDocsLink: vsaData.showPolicyDocsLink,
11051110
}, nil
11061111
}
11071112

@@ -1121,6 +1126,7 @@ func createFallbackReport(allData AllSectionsData, vsaData *validateVSAData) (*a
11211126
reportData.PolicyInputs,
11221127
reportData.ShowSuccesses,
11231128
reportData.ShowWarnings,
1129+
reportData.ShowPolicyDocsLink,
11241130
reportData.Expansion,
11251131
)
11261132
if err != nil {

cmd/validate/vsa_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,8 @@ func TestValidateSingleVSA(t *testing.T) {
10341034
ctx := context.Background()
10351035
cmd := &cobra.Command{}
10361036
cmd.SetContext(ctx)
1037+
// Add the persistent flag that runValidateVSA expects
1038+
cmd.Flags().Bool("show-policy-docs-link", false, "")
10371039

10381040
// Use the unified runValidateVSA function which handles both single and snapshot cases
10391041
err := runValidateVSA(cmd, tt.data, tt.args)
@@ -1132,6 +1134,8 @@ func TestValidateSnapshotVSAs(t *testing.T) {
11321134
ctx := context.Background()
11331135
cmd := &cobra.Command{}
11341136
cmd.SetContext(ctx)
1137+
// Add the persistent flag that runValidateVSA expects
1138+
cmd.Flags().Bool("show-policy-docs-link", false, "")
11351139

11361140
// Use the unified runValidateVSA function which handles both single and snapshot cases
11371141
err := runValidateVSA(cmd, tt.data, []string{})

docs/modules/ROOT/pages/ec_validate.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Validate conformance with the provided policies
55
== Options
66

77
-h, --help:: help for validate (Default: false)
8+
--show-policy-docs-link:: Show link to policy documentation in output when there are violations or warnings (Default: false)
89
--show-successes:: (Default: false)
910
--show-warnings:: (Default: true)
1011

docs/modules/ROOT/pages/ec_validate_image.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ JSON of the "spec" or a reference to a Kubernetes object [<namespace>/]<name>
172172
--retry-jitter:: randomness factor for backoff calculation (0.0-1.0) (Default: 0.1)
173173
--retry-max-retry:: maximum number of retry attempts (Default: 3)
174174
--retry-max-wait:: maximum wait time between retries (Default: 3s)
175+
--show-policy-docs-link:: Show link to policy documentation in output when there are violations or warnings (Default: false)
175176
--show-successes:: (Default: false)
176177
--show-warnings:: (Default: true)
177178
--timeout:: max overall execution duration (Default: 5m0s)

docs/modules/ROOT/pages/ec_validate_input.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ mark (?) sign, for example: --output text=output.txt?show-successes=false
7676
--retry-jitter:: randomness factor for backoff calculation (0.0-1.0) (Default: 0.1)
7777
--retry-max-retry:: maximum number of retry attempts (Default: 3)
7878
--retry-max-wait:: maximum wait time between retries (Default: 3s)
79+
--show-policy-docs-link:: Show link to policy documentation in output when there are violations or warnings (Default: false)
7980
--show-successes:: (Default: false)
8081
--show-warnings:: (Default: true)
8182
--timeout:: max overall execution duration (Default: 5m0s)

docs/modules/ROOT/pages/ec_validate_policy.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ ec validate policy --policy-configuration github.com/org/repo/policy.yaml
3737
--retry-jitter:: randomness factor for backoff calculation (0.0-1.0) (Default: 0.1)
3838
--retry-max-retry:: maximum number of retry attempts (Default: 3)
3939
--retry-max-wait:: maximum wait time between retries (Default: 3s)
40+
--show-policy-docs-link:: Show link to policy documentation in output when there are violations or warnings (Default: false)
4041
--show-successes:: (Default: false)
4142
--show-warnings:: (Default: true)
4243
--timeout:: max overall execution duration (Default: 5m0s)

docs/modules/ROOT/pages/ec_validate_vsa.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ mark (?) sign, for example: --output text=output.txt?show-successes=false
6060
--retry-jitter:: randomness factor for backoff calculation (0.0-1.0) (Default: 0.1)
6161
--retry-max-retry:: maximum number of retry attempts (Default: 3)
6262
--retry-max-wait:: maximum wait time between retries (Default: 3s)
63+
--show-policy-docs-link:: Show link to policy documentation in output when there are violations or warnings (Default: false)
6364
--show-successes:: (Default: false)
6465
--show-warnings:: (Default: true)
6566
--timeout:: max overall execution duration (Default: 5m0s)

0 commit comments

Comments
 (0)