Skip to content

Commit

Permalink
docs: #70 update dev validate cmd comments and cli output.
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-winberry committed Apr 2, 2024
1 parent 51f9e9c commit 1c44236
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/cmd/dev/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ var validateOpts = &ValidateFlags{}
func init() {
validateCmd := &cobra.Command{
Use: "validate",
Short: "Validate Resources from a Lula Validation Manifest",
Short: "Run an individual Lula validation.",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
config.SkipLogFile = true
},
Long: "TODO: Add long description here.",
Long: "Run an individual Lula validation for quick testing and debugging of a Lula Validation. This command is intended for development purposes only.",
Example: validateHelp,
Run: func(cmd *cobra.Command, args []string) {
spinner := message.NewProgressSpinner("Validating %s", validateOpts.InputFile)
Expand All @@ -48,15 +48,19 @@ func init() {
message.Fatalf(err, "error running dev validate: %v", err)
}

// Write the validation result to a file if an output file is provided
// Otherwise, print the result to the debug console
err = writeValidation(validation, validateOpts.OutputFile)
if err != nil {
message.Fatalf(err, "error writing result: %v", err)
}

result := validation.Result.Failing == 0
// If the expected result is not equal to the actual result, return an error
if validateOpts.ExpectedResult != result {
message.Fatalf(fmt.Errorf("validation failed"), "expected result to be %t got %t", validateOpts.ExpectedResult, result)
}
// Print the number of passing and failing results
message.Infof("Validation completed with %d passing and %d failing results", validation.Result.Passing, validation.Result.Failing)
},
}
Expand All @@ -65,14 +69,14 @@ func init() {

validateCmd.Flags().StringVarP(&validateOpts.InputFile, "input-file", "f", "", "the path to a validation manifest file")
validateCmd.Flags().StringVarP(&validateOpts.OutputFile, "output-file", "o", "", "the path to write the validation with results")
validateCmd.Flags().BoolVarP(&validateOpts.ExpectedResult, "expected-result", "e", true, "the expected result of the validation")
validateCmd.Flags().BoolVarP(&validateOpts.ExpectedResult, "expected-result", "e", true, "the expected result of the validation (-e=false for failing result)")

validateCmd.MarkFlagRequired("input-file")
}

// DevValidate runs a validation using a lula validation manifest instead of an oscal file.
// It returns the validation result.
// or an error if the validation fails.
// Successful if the validation is evaluated. Returns the validation result.
// Returns an error if it fails to run the validation.
func DevValidate(ctx context.Context, inputFile string) (validation types.Validation, err error) {
// Return an error if the input file is empty or not a yaml file
if inputFile == "" || !strings.HasSuffix(inputFile, ".yaml") {
Expand Down

0 comments on commit 1c44236

Please sign in to comment.