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

Function validateMarkdownSpec

shortcuts/markdown/helpers.go:83–149  ·  view source on GitHub ↗
(runtime *common.RuntimeContext, spec markdownUploadSpec, requireName bool)

Source from the content-addressed store, hash-verified

81}
82
83func validateMarkdownSpec(runtime *common.RuntimeContext, spec markdownUploadSpec, requireName bool) error {
84 switch {
85 case spec.ContentSet && spec.FileSet:
86 return markdownValidationError("--content and --file are mutually exclusive").
87 WithParams(markdownInvalidParam("--content", "mutually exclusive"), markdownInvalidParam("--file", "mutually exclusive"))
88 case !spec.ContentSet && !spec.FileSet:
89 return markdownValidationError("specify exactly one of --content or --file").
90 WithParams(markdownInvalidParam("--content", "required; specify exactly one"), markdownInvalidParam("--file", "required; specify exactly one"))
91 }
92
93 if markdownFlagExplicitlyEmpty(runtime, "folder-token") {
94 return markdownValidationParamError("--folder-token", "--folder-token cannot be empty; omit it to upload into Drive root folder")
95 }
96 if markdownFlagExplicitlyEmpty(runtime, "wiki-token") {
97 return markdownValidationParamError("--wiki-token", "--wiki-token cannot be empty; provide a valid wiki node token or omit the flag entirely")
98 }
99 targets := 0
100 if spec.FolderToken != "" {
101 targets++
102 }
103 if spec.WikiToken != "" {
104 targets++
105 }
106 if targets > 1 {
107 return markdownValidationError("--folder-token and --wiki-token are mutually exclusive").
108 WithParams(markdownInvalidParam("--folder-token", "mutually exclusive"), markdownInvalidParam("--wiki-token", "mutually exclusive"))
109 }
110 if spec.FolderToken != "" {
111 if err := validate.ResourceName(spec.FolderToken, "--folder-token"); err != nil {
112 return markdownValidationParamError("--folder-token", "%s", err).WithCause(err)
113 }
114 }
115 if spec.WikiToken != "" {
116 if err := validate.ResourceName(spec.WikiToken, "--wiki-token"); err != nil {
117 return markdownValidationParamError("--wiki-token", "%s", err).WithCause(err)
118 }
119 }
120
121 if requireName && spec.ContentSet {
122 if strings.TrimSpace(spec.FileName) == "" {
123 return markdownValidationParamError("--name", "--name is required when using --content")
124 }
125 if err := validateMarkdownFileName(spec.FileName, "--name"); err != nil {
126 return err
127 }
128 }
129
130 if spec.FileSet {
131 if strings.TrimSpace(spec.FilePath) == "" {
132 return markdownValidationParamError("--file", "--file cannot be empty")
133 }
134 if _, err := validate.SafeInputPath(spec.FilePath); err != nil {
135 return markdownValidationParamError("--file", "unsafe file path: %s", err).WithCause(err)
136 }
137 if err := validateMarkdownFileName(filepath.Base(spec.FilePath), "--file"); err != nil {
138 return err
139 }
140 }

Callers 2

markdown_create.goFile · 0.85

Calls 10

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

Tested by

no test coverage detected