parseRefs extracts every lark-cli command reference from text (a shortcut's Tips line, which may embed an "Example: lark-cli ..." command). It is deliberately format-agnostic: it keys on the "lark-cli" token whether it sits in a ```bash fence, an inline `code` span, or bare prose. Backslash line-con
(content string)
| 42 | // line-continuations are joined first so a multi-line invocation is parsed as |
| 43 | // one command; inline-code backticks and trailing # comments terminate it. |
| 44 | func parseRefs(content string) []ref { |
| 45 | var refs []ref |
| 46 | lines := strings.Split(content, "\n") |
| 47 | for i := 0; i < len(lines); i++ { |
| 48 | lineNo := i + 1 |
| 49 | logical := lines[i] |
| 50 | // Shell line continuation: a trailing backslash joins the next physical |
| 51 | // line. Without this, flags on the continuation lines of a multi-line |
| 52 | // `lark-cli ... \` example are never seen by the checker. |
| 53 | for endsWithBackslash(logical) && i+1 < len(lines) { |
| 54 | logical = strings.TrimRight(logical, " \t") |
| 55 | logical = logical[:len(logical)-1] // drop the trailing backslash |
| 56 | i++ |
| 57 | logical += " " + lines[i] |
| 58 | } |
| 59 | refs = append(refs, parseLine(logical, lineNo)...) |
| 60 | } |
| 61 | return refs |
| 62 | } |
| 63 | |
| 64 | func endsWithBackslash(s string) bool { |
| 65 | return strings.HasSuffix(strings.TrimRight(s, " \t"), `\`) |
no test coverage detected