checkRefs validates refs against cat and returns all mismatches in order.
(cat *catalog, refs []ref)
| 24 | |
| 25 | // checkRefs validates refs against cat and returns all mismatches in order. |
| 26 | func 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 | } |
no test coverage detected