MCPcopy Index your code
hub / github.com/campoy/embedmd / parseCommand

Function parseCommand

embedmd/command.go:27–63  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

25}
26
27func parseCommand(s string) (*command, error) {
28 s = strings.TrimSpace(s)
29 if len(s) < 2 || s[0] != '(' || s[len(s)-1] != ')' {
30 return nil, errors.New("argument list should be in parenthesis")
31 }
32
33 args, err := fields(s[1 : len(s)-1])
34 if err != nil {
35 return nil, err
36 }
37 if len(args) == 0 {
38 return nil, errors.New("missing file name")
39 }
40
41 cmd := &command{path: args[0]}
42 args = args[1:]
43 if len(args) > 0 && args[0][0] != '/' {
44 cmd.lang, args = args[0], args[1:]
45 } else {
46 ext := filepath.Ext(cmd.path[1:])
47 if len(ext) == 0 {
48 return nil, errors.New("language is required when file has no extension")
49 }
50 cmd.lang = ext[1:]
51 }
52
53 switch {
54 case len(args) == 1:
55 cmd.start = &args[0]
56 case len(args) == 2:
57 cmd.start, cmd.end = &args[0], &args[1]
58 case len(args) > 2:
59 return nil, errors.New("too many arguments")
60 }
61
62 return cmd, nil
63}
64
65// fields returns a list of the groups of text separated by blanks,
66// keeping all text surrounded by / as a group.

Callers 2

parsingCmdFunction · 0.85
TestParseCommandFunction · 0.85

Calls 1

fieldsFunction · 0.85

Tested by 1

TestParseCommandFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…