Skip to content

Vet command should support structured output formats #249

@atsai1220

Description

@atsai1220

Feature Request

Is your feature request related to a problem? Please describe:
Currently the vet command outputs either a successful message or lines of error messages and file paths to stdout. This can be problematic to parse when using vet during CI because the output is not structured.

Describe the feature you'd like:
I would like to a flag that can configure the output format of vet. For example, --output=table|json|csv so that we can leverage vet to continuously validate our files in our pipeline and then propagate the messages up to the user from structured text.

Describe alternatives you've considered:
We've considered parsing the outputs from vet line-by-line but having a consistent structure will make this easier.

Teachability, Documentation, Adoption, Migration Strategy:
The command could be like the following

Before

kcl vet --format yaml --schema AppConfig samples/example-app-1.yaml kcl/schemas.k

EvaluationError
 --> path/to/my/file.yaml:3:9
  |
3 | app_name: "test"
  |         ^ Instance check failed
  |

  --> /kcl/schemas.k:13:1
   |
13 |     regex.match(app_name, r"\[(.+?)\]")
   |  Check failed on the condition
   |

After

kcl vet --format yaml --schema AppConfig samples/example-app-1.yaml kcl/schemas.k --output json

{
  "errorType": "EvaluationError",
  "file": "path/to/my/file.yaml",
  "line": 3,
  "column": 9,
  "details": {
    "errorMessage": "Instance check failed",
    "codeSnippet": "app_name: \"test\""
  },
  "schema": {
    "filepath": "/kcl/schemas.k",
    "lineInFile": 13,
    "columnInFile": 1,
    "additionalDetails": "Check failed on the condition"
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions