String returns the arguments as a shell command, quoting arguments with spaces.
()
| 313 | // String returns the arguments as a shell command, quoting arguments with |
| 314 | // spaces. |
| 315 | func (a Args) String() string { |
| 316 | if len(a) == 0 { |
| 317 | return "" |
| 318 | } |
| 319 | |
| 320 | sb := &strings.Builder{} |
| 321 | a.writeQuoted(sb, fmt.Sprint(a[0])) |
| 322 | if len(a) == 1 { |
| 323 | return sb.String() |
| 324 | } |
| 325 | |
| 326 | for _, arg := range a[1:] { |
| 327 | sb.WriteByte(' ') |
| 328 | a.writeQuoted(sb, fmt.Sprint(arg)) |
| 329 | } |
| 330 | return sb.String() |
| 331 | } |
| 332 | |
| 333 | func (Args) writeQuoted(dst *strings.Builder, str string) { |
| 334 | needsQuote := strings.ContainsAny(str, ";\"'()$|&><` \t\r\n\\#{~*?[=") |
nothing calls this directly
no test coverage detected