ValidateCmd validates and reconciles a project without starting the UI.
(ch *cmdutil.Helper)
| 53 | |
| 54 | // ValidateCmd validates and reconciles a project without starting the UI. |
| 55 | func ValidateCmd(ch *cmdutil.Helper) *cobra.Command { |
| 56 | var verbose bool |
| 57 | var debug bool |
| 58 | var silent bool |
| 59 | var reset bool |
| 60 | var pullEnv bool |
| 61 | var logFormat string |
| 62 | var envVars []string |
| 63 | var environment string |
| 64 | var modelTimeoutSeconds uint32 |
| 65 | var outputFile string |
| 66 | |
| 67 | validateCmd := &cobra.Command{ |
| 68 | Use: "validate [<path>]", |
| 69 | Short: "Validate project resources", |
| 70 | Args: cobra.MaximumNArgs(1), |
| 71 | RunE: func(cmd *cobra.Command, args []string) error { |
| 72 | // first, validate and set the output format |
| 73 | outputFormat := ch.Printer.Format |
| 74 | switch outputFormat { |
| 75 | // supported formats |
| 76 | case printer.FormatHuman: |
| 77 | case printer.FormatJSON: |
| 78 | // override human output to console otherwise any printfs or printlns will be discarded |
| 79 | ch.Printer.OverrideHumanOutput(color.Output) |
| 80 | default: |
| 81 | return fmt.Errorf("only human and json output format is supported for validate command") |
| 82 | } |
| 83 | |
| 84 | if cmdutil.IsLocalRillRunning(cmd.Context()) { |
| 85 | return fmt.Errorf("`rill start` appears to be running on http://localhost:9009; stop it and rerun validate") |
| 86 | } |
| 87 | |
| 88 | var projectPath string |
| 89 | if len(args) > 0 { |
| 90 | var err error |
| 91 | projectPath, err = start.ResolveProjectPath(args[0]) |
| 92 | if err != nil { |
| 93 | return err |
| 94 | } |
| 95 | } else { |
| 96 | projectPath = "." |
| 97 | } |
| 98 | |
| 99 | if !local.IsProjectInit(projectPath) { |
| 100 | return fmt.Errorf("no Rill project found at %q (missing rill.yaml)", projectPath) |
| 101 | } |
| 102 | |
| 103 | envVarsMap, err := start.ParseVariables(envVars) |
| 104 | if err != nil { |
| 105 | return err |
| 106 | } |
| 107 | envVarsMap["rill.model.timeout_override"] = fmt.Sprintf("%d", modelTimeoutSeconds) |
| 108 | // Prevent resource updates when parse errors are present and surface the actual parser output instead of re-parsing here. |
| 109 | envVarsMap["rill.parser.skip_updates_if_parse_errors"] = "true" |
| 110 | |
| 111 | ch.Interactive = false |
| 112 | app, err := local.NewApp(cmd.Context(), &local.AppOptions{ |
no test coverage detected