MCPcopy
hub / github.com/larksuite/cli / validateMarkdownDiffSpec

Function validateMarkdownDiffSpec

shortcuts/markdown/markdown_diff.go:66–112  ·  view source on GitHub ↗
(runtime *common.RuntimeContext, spec markdownDiffSpec)

Source from the content-addressed store, hash-verified

64}
65
66func 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
114func validateMarkdownDiffVersionValue(value, flagName string) error {
115 value = strings.TrimSpace(value)

Callers 1

markdown_diff.goFile · 0.85

Calls 9

ResourceNameFunction · 0.92
SafeInputPathFunction · 0.92
validateMarkdownFileNameFunction · 0.85
markdownValidationErrorFunction · 0.85
markdownInvalidParamFunction · 0.85
WithParamsMethod · 0.80
WithCauseMethod · 0.45

Tested by

no test coverage detected