(runtime *common.RuntimeContext, spec markdownDiffSpec)
| 64 | } |
| 65 | |
| 66 | func validateMarkdownDiffSpec(runtime *common.RuntimeContext, spec markdownDiffSpec) error { |
| 67 | if err := validate.ResourceName(spec.FileToken, "--file-token"); err != nil { |
| 68 | return markdownValidationParamError("--file-token", "%s", err).WithCause(err) |
| 69 | } |
| 70 | if spec.FromVersion != "" { |
| 71 | if err := validateMarkdownDiffVersionValue(spec.FromVersion, "--from-version"); err != nil { |
| 72 | return err |
| 73 | } |
| 74 | } |
| 75 | if spec.ToVersion != "" { |
| 76 | if err := validateMarkdownDiffVersionValue(spec.ToVersion, "--to-version"); err != nil { |
| 77 | return err |
| 78 | } |
| 79 | } |
| 80 | if spec.FilePath != "" { |
| 81 | if _, err := validate.SafeInputPath(spec.FilePath); err != nil { |
| 82 | return markdownValidationParamError("--file", "unsafe file path: %s", err).WithCause(err) |
| 83 | } |
| 84 | if err := validateMarkdownFileName(spec.FilePath, "--file"); err != nil { |
| 85 | return err |
| 86 | } |
| 87 | } |
| 88 | if spec.ContextLines < 0 { |
| 89 | return markdownValidationParamError("--context-lines", "--context-lines must be >= 0") |
| 90 | } |
| 91 | if spec.Format != "" && spec.Format != "json" && spec.Format != "pretty" { |
| 92 | return markdownValidationParamError("--format", "markdown +diff only supports --format json or pretty") |
| 93 | } |
| 94 | if spec.FilePath == "" { |
| 95 | if spec.FromVersion == "" && spec.ToVersion == "" { |
| 96 | return markdownValidationError("specify --from-version, or both --from-version and --to-version, or use --file for remote vs local diff"). |
| 97 | WithParams( |
| 98 | markdownInvalidParam("--from-version", "required; specify one"), |
| 99 | markdownInvalidParam("--to-version", "required; specify one"), |
| 100 | markdownInvalidParam("--file", "required; specify one"), |
| 101 | ) |
| 102 | } |
| 103 | if spec.FromVersion == "" && spec.ToVersion != "" { |
| 104 | return markdownValidationParamError("--to-version", "--to-version requires --from-version") |
| 105 | } |
| 106 | return nil |
| 107 | } |
| 108 | if spec.ToVersion != "" { |
| 109 | return markdownValidationParamError("--to-version", "--to-version is not supported together with --file") |
| 110 | } |
| 111 | return nil |
| 112 | } |
| 113 | |
| 114 | func validateMarkdownDiffVersionValue(value, flagName string) error { |
| 115 | value = strings.TrimSpace(value) |
no test coverage detected