MCPcopy Index your code
hub / github.com/abiosoft/ishell / read

Method read

ishell.go:291–333  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

289}
290
291func (s *Shell) read() ([]string, error) {
292 s.rawArgs = nil
293 heredoc := false
294 eof := ""
295 // heredoc multiline
296 lines, err := s.readMultiLinesFunc(func(line string) bool {
297 if !heredoc {
298 if strings.Contains(line, "<<") {
299 s := strings.SplitN(line, "<<", 2)
300 if eof = strings.TrimSpace(s[1]); eof != "" {
301 heredoc = true
302 return true
303 }
304 }
305 } else {
306 return line != eof
307 }
308 return strings.HasSuffix(strings.TrimSpace(line), "\\")
309 })
310
311 s.rawArgs = strings.Fields(lines)
312
313 if heredoc {
314 s := strings.SplitN(lines, "<<", 2)
315 args, err1 := shlex.Split(s[0])
316
317 arg := strings.TrimSuffix(strings.SplitN(s[1], "\n", 2)[1], eof)
318 args = append(args, arg)
319 if err1 != nil {
320 return args, err1
321 }
322 return args, err
323 }
324
325 lines = strings.Replace(lines, "\\\n", " \n", -1)
326
327 args, err1 := shlex.Split(lines)
328 if err1 != nil {
329 return args, err1
330 }
331
332 return args, err
333}
334
335func (s *Shell) readMultiLinesFunc(f func(string) bool) (string, error) {
336 var lines bytes.Buffer

Callers 1

runMethod · 0.95

Calls 1

readMultiLinesFuncMethod · 0.95

Tested by

no test coverage detected