MCPcopy
hub / github.com/urfave/cli / parseArgsFromStdin

Method parseArgsFromStdin

command_run.go:14–89  ·  command_run.go::Command.parseArgsFromStdin
()

Source from the content-addressed store, hash-verified

12type helpShownKey struct{}
13
14func (cmd *Command) parseArgsFromStdin() ([]string, error) {
15 type state int
16 const (
17 stateSearchForToken state = -1
18 stateSearchForString state = 0
19 )
20
21 st := stateSearchForToken
22 linenum := 1
23 token := ""
24 args := []string{}
25
26 breader := bufio.NewReader(cmd.Reader)
27
28outer:
29 for {
30 ch, _, err := breader.ReadRune()
31 if err == io.EOF {
32 switch st {
33 case stateSearchForToken:
34 if token != "--" {
35 args = append(args, token)
36 }
37 case stateSearchForString:
38 // make sure string is not empty
39 for _, t := range token {
40 if !unicode.IsSpace(t) {
41 args = append(args, token)
42 }
43 }
44 }
45 break outer
46 }
47 if err != nil {
48 return nil, err
49 }
50 switch st {
51 case stateSearchForToken:
52 if unicode.IsSpace(ch) || ch == '"' {
53 if ch == '\n' {
54 linenum++
55 }
56 if token != "" {
57 // end the processing here
58 if token == "--" {
59 break outer
60 }
61 args = append(args, token)
62 token = ""
63 }
64 if ch == '"' {
65 st = stateSearchForString
66 }
67 continue
68 }
69 token += string(ch)
70 case stateSearchForString:
71 if ch != '"' {

Callers 1

runMethod · 0.95

Calls 1

tracefFunction · 0.85

Tested by

no test coverage detected