MCPcopy Create free account
hub / github.com/larksuite/cli / checkRefs

Function checkRefs

cmd/cmdexample_check_test.go:26–60  ·  view source on GitHub ↗

checkRefs validates refs against cat and returns all mismatches in order.

(cat *catalog, refs []ref)

Source from the content-addressed store, hash-verified

24
25// checkRefs validates refs against cat and returns all mismatches in order.
26func checkRefs(cat *catalog, refs []ref) []finding {
27 var out []finding
28 for _, r := range refs {
29 path, n, ok := cat.longestPrefix(r.words)
30 if !ok {
31 attempted := strings.Join(r.words, " ")
32 out = append(out, finding{
33 line: r.line, raw: r.raw, kind: unknownCommand,
34 path: attempted, suggest: cat.suggestCommand(attempted),
35 })
36 continue
37 }
38 // Leftover words after a group node are an unknown subcommand (e.g. a
39 // mistyped method like "batch_modify_message"). After a leaf they are
40 // positionals (e.g. "api GET /path"), so only groups trigger this.
41 if n < len(r.words) && cat.isGroup(path) {
42 attempted := strings.Join(r.words, " ")
43 out = append(out, finding{
44 line: r.line, raw: r.raw, kind: unknownCommand,
45 path: attempted, suggest: cat.suggestCommand(attempted),
46 })
47 continue
48 }
49 for _, f := range r.flags {
50 if cat.hasFlag(path, f) {
51 continue
52 }
53 out = append(out, finding{
54 line: r.line, raw: r.raw, kind: unknownFlag,
55 path: path, flag: f, suggest: cat.suggestFlag(path, f),
56 })
57 }
58 }
59 return out
60}

Callers 3

TestCmdExampleCheckFunction · 0.85

Calls 5

longestPrefixMethod · 0.80
suggestCommandMethod · 0.80
isGroupMethod · 0.80
suggestFlagMethod · 0.80
hasFlagMethod · 0.45

Tested by

no test coverage detected