firstNonFlagLiteral returns the literal value of the first word in ws that does not start with "-", or "" if none qualifies. Known limitation: no flag-arity knowledge. For programs whose global flags take a separate-word value ("git -C path verb", "kubectl -n ns verb", "docker --context X verb"), t
(ws []*syntax.Word)
| 98 | // verb in those cases need per-program awareness; this function does |
| 99 | // not provide it. |
| 100 | func firstNonFlagLiteral(ws []*syntax.Word) string { |
| 101 | for _, w := range ws { |
| 102 | lit := wordLiteral(w) |
| 103 | if lit == "" || strings.HasPrefix(lit, "-") { |
| 104 | continue |
| 105 | } |
| 106 | return lit |
| 107 | } |
| 108 | return "" |
| 109 | } |