-
Notifications
You must be signed in to change notification settings - Fork 38
feat(policy): change devel commands return to stdout #2308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,11 +55,7 @@ func newPolicyDevelopLintCmd() *cobra.Command { | |
return nil | ||
} | ||
|
||
// Print all validation errors | ||
for _, err := range result.Errors { | ||
logger.Error().Msg(err) | ||
} | ||
return fmt.Errorf("policy validation failed with %d issues", len(result.Errors)) | ||
return encodeResult(result) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the output when we do not have any violations? Do we return an empty violations array? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, here's the output
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. awesome, please merge :) |
||
}, | ||
} | ||
|
||
|
@@ -68,3 +64,19 @@ func newPolicyDevelopLintCmd() *cobra.Command { | |
cmd.Flags().StringVar(®alConfig, "regal-config", "", "Path to custom regal config (Default: https://github.com/chainloop-dev/chainloop/tree/main/app/cli/internal/policydevel/.regal.yaml)") | ||
return cmd | ||
} | ||
|
||
func encodeResult(result *action.PolicyLintResult) error { | ||
if result == nil { | ||
return nil | ||
} | ||
|
||
output := fmt.Sprintf("Found %d issues:\n", len(result.Errors)) | ||
|
||
for i, err := range result.Errors { | ||
output += fmt.Sprintf(" %d. %s\n", i+1, err) | ||
} | ||
|
||
fmt.Print(output) | ||
|
||
return fmt.Errorf("policy validation failed with %d issues", len(result.Errors)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this mean that now we support json output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, the text version didn't follow any structure so it would cause problems later on