MCPcopy Index your code
hub / github.com/larksuite/cli / readHTML5BlockPath

Function readHTML5BlockPath

shortcuts/doc/html5_block_resources.go:388–409  ·  view source on GitHub ↗
(runtime *common.RuntimeContext, pathValue string, label string)

Source from the content-addressed store, hash-verified

386}
387
388func readHTML5BlockPath(runtime *common.RuntimeContext, pathValue string, label string) (string, error) {
389 pathRaw := strings.TrimSpace(pathValue)
390 if !strings.HasPrefix(pathRaw, "@") {
391 return "", common.ValidationErrorf("%s %q must start with @, for example @widget.html", label, pathValue).WithParam("path")
392 }
393 relPath := strings.TrimSpace(strings.TrimPrefix(pathRaw, "@"))
394 if relPath == "" {
395 return "", common.ValidationErrorf("%s cannot be empty after @", label).WithParam("path")
396 }
397 clean := filepath.Clean(relPath)
398 if filepath.IsAbs(clean) || clean == "." || clean == ".." || strings.HasPrefix(clean, ".."+string(filepath.Separator)) {
399 return "", common.ValidationErrorf("%s %q must be a relative path within the current working directory", label, pathValue).WithParam("path")
400 }
401 if strings.ToLower(filepath.Ext(clean)) != ".html" {
402 return "", common.ValidationErrorf("%s %q must point to a .html file", label, pathValue).WithParam("path")
403 }
404 data, err := cmdutil.ReadInputFile(runtime.FileIO(), clean)
405 if err != nil {
406 return "", common.ValidationErrorf("%s %q cannot be read from the current working directory; check that the file exists relative to where lark-cli is running: %v", label, clean, err).WithParam("path").WithCause(err)
407 }
408 return string(data), nil
409}
410
411func hasProcessableHTML5Block(format string, content string) bool {
412 if !strings.Contains(content, "<html5-block") {

Callers 2

resolveReferenceMapPathsFunction · 0.85

Calls 5

ValidationErrorfFunction · 0.92
ReadInputFileFunction · 0.92
WithParamMethod · 0.80
FileIOMethod · 0.80
WithCauseMethod · 0.45

Tested by

no test coverage detected