// Splits a line into a command and its arguments
// e.g. ":a b c d ." will be split into ":a" and " b c d ."
547769
func splitLine(line string) (string, string) {
	var command, arguments string

	line = strings.TrimSpace(line)

	// An empty line/a line consisting of whitespace contains neither command nor arguments
	if len(line) > 0 {
		command = strings.Fields(line)[0]

		// A line containing only a command has no arguments
		if len(line) > len(command) {
			arguments = line[len(command):]
		}
	}

	return command, arguments
}
80839
func split(s string) <-chan string {
	ch := make(chan string)
	go func() {
		s = strings.Replace(s, " ", "", -1)
		if !strings.Contains(s, "(") {
			ch <- s
		} else {
			last := 0
			end := len(s)
			for info := range scan(s) {
				if last != info.openPos {
					ch <- s[last:info.openPos]
				}
				ch <- s[info.openPos:info.closePos]
				last = info.closePos
			}
			if last != end {
				ch <- s[last:]
			}
		}
		close(ch)
	}()
	return ch
}
554690
func Split(v string) (key, value string) {
	parts := strings.SplitN(v, "=", 2)
	switch len(parts) {
	case 2:
		value = parts[1]
		fallthrough

	case 1:
		key = parts[0]
	}
	return
}
1001018
func (b *stdBackend) command(opCode int, args interface{}) (interface{}, error) {
	cmd := &command{opCode, args, make(chan interface{})}
	b.commandC <- cmd
	resp, ok := <-cmd.respChan
	if !ok {
		return nil, errors.New(ErrMonitoringPanicked, errorMessages)
	}
	if err, ok := resp.(error); ok {
		return nil, err
	}
	return resp, nil
}
771335
func parseLine(line string) (cmd string, args string) {
  if idx := strings.Index(line, " "); idx > 0 {
    cmd = strings.ToUpper(line[:idx])
    args = strings.TrimSpace(line[idx+1:])
  } else {
    cmd = strings.ToUpper(line)
  }
  return
}
220938
func Command(command ...string) *exec.Cmd {
	name, arg := commandParts(command...)
	return exec.Command(name, arg...)
}
488661
func ParseCommandLine(v interface{}, args []string) error {
	app, err := NewCommandLineApp(v)
	if err != nil {
		return trace.Wrap(err)
	}
	if _, err := app.Parse(args); err != nil {
		return trace.Wrap(err)
	}
	return nil
}
1094336
func makeCmdLine(args []string) string {
	var s string
	for _, v := range args {
		if s != "" {
			s += " "
		}
		s += syscall.EscapeArg(v)
	}
	return s
}
28679
func parseCommandLine(input []string) ([]string, variables, error) {
	cmd, args := input[:1], input[1:]
	name := cmd[0]

	c := pprofCommands[name]
	if c == nil {
		// Attempt splitting digits on abbreviated commands (eg top10)
		if d := tailDigitsRE.FindString(name); d != "" && d != name {
			name = name[:len(name)-len(d)]
			cmd[0], args = name, append([]string{d}, args...)
			c = pprofCommands[name]
		}
	}
	if c == nil {
		return nil, nil, fmt.Errorf("unrecognized command: %q", name)
	}

	if c.hasParam {
		if len(args) == 0 {
			return nil, nil, fmt.Errorf("command %s requires an argument", name)
		}
		cmd = append(cmd, args[0])
		args = args[1:]
	}

	// Copy the variables as options set in the command line are not persistent.
	vcopy := pprofVariables.makeCopy()

	var focus, ignore string
	for i := 0; i < len(args); i++ {
		t := args[i]
		if _, err := strconv.ParseInt(t, 10, 32); err == nil {
			vcopy.set("nodecount", t)
			continue
		}
		switch t[0] {
		case '>':
			outputFile := t[1:]
			if outputFile == "" {
				i++
				if i >= len(args) {
					return nil, nil, fmt.Errorf("unexpected end of line after >")
				}
				outputFile = args[i]
			}
			vcopy.set("output", outputFile)
		case '-':
			if t == "--cum" || t == "-cum" {
				vcopy.set("cum", "t")
				continue
			}
			ignore = catRegex(ignore, t[1:])
		default:
			focus = catRegex(focus, t)
		}
	}

	if name == "tags" {
		updateFocusIgnore(vcopy, "tag", focus, ignore)
	} else {
		updateFocusIgnore(vcopy, "", focus, ignore)
	}

	if vcopy["nodecount"].intValue() == -1 && (name == "text" || name == "top") {
		vcopy.set("nodecount", "10")
	}

	return cmd, vcopy, nil
}
270499
func (f Files) Lines(path string) []string {
	if f == nil || f[path] == nil {
		return []string{}
	}

	return strings.Split(string(f[path]), "\n")
}
538074
func (c *CLI) SubcommandArgs() []string {
	c.once.Do(c.init)
	return c.subcommandArgs
}
1367099
func (cl Cmdline) ListAll() ([]string, error) {
	cmd := cl.commands.listAll()

	out, err := cl.runCommand(cmd, "List")
	if err != nil {
		return nil, errors.Trace(err)
	}
	out = strings.TrimSpace(out)

	if out == "" {
		return nil, nil
	}
	return strings.Split(out, "\n"), nil
}
642370
func prepareCmdArgs(command string, argv []string) []string {
	cmdArgv := []string{extensionPrefix + command}
	cmdSplit := strings.Split(argv[0], command+":")

	if len(cmdSplit) > 1 {
		cmdArgv = append(cmdArgv, cmdSplit[1])
	}

	return append(cmdArgv, argv[1:]...)
}
1106090
func (p *Pipelined) Command(args ...interface{}) error {
	err := p.conn.SendCommand(args...)
	if err == nil {
		p.times++
	}
	return err
}
1301620
func (c *CmdClause) Command(name, help string) *CmdClause {
	cmd := c.addCommand(name, help)
	cmd.parent = c
	return cmd
}
49257
func ParseCommandLine(args []string) (*CommandLine, error) {
	noTarget := NoTarget{}

	cl := CommandLine{
		Target: noTarget,
	}
	i := 0
	for len(args) > 0 {
		// Stop parsing after we have a target, as Python does.
		if cl.Target != noTarget {
			break
		}

		// Consume the next argument.
		arg := args[0]
		args = args[1:]
		i++

		if arg == "-" {
			// "-" instructs Python to load the script from STDIN.
			cl.Target = ScriptTarget{
				Path: "-",
			}
			continue
		}

		isFlag := false
		if !cl.FlagSeparator {
			arg, isFlag = trimPrefix(arg, "-")
		}

		if !isFlag {
			// The first positional argument is the path to the script, and all
			// subsequent arguments are script arguments.
			cl.Target = ScriptTarget{
				Path:             arg,
				FollowsSeparator: cl.FlagSeparator,
			}
			continue
		}

		// Note that at this point we've trimmed the preceding "-" from arg, so
		// this is really "--". If we encounter "--" that marks the end of
		// interpreter flag parsing; everything hereafter is considered positional
		// to the interpreter.
		if arg == "-" {
			cl.FlagSeparator = true
			continue
		}

		// Parse this flag and any remainder.
		fs := parsedFlagState{
			flag: arg,
			args: args,
		}
		for len(fs.flag) > 0 {
			if err := cl.parseSingleFlag(&fs); err != nil {
				return nil, errors.Annotate(err, "failed to parse Python flag #%d", i).
					InternalReason("arg(%q)", arg).Err()
			}
		}
		args = fs.args
	}

	// The remainder of arguments are for the script.
	cl.Args = append([]string(nil), args...)
	return &cl, nil
}
518193
func ReplaceArgument(command []string, argMutateFunc func(map[string]string) map[string]string) []string {
	argMap := ParseArgumentListToMap(command)

	// Save the first command (the executable) if we're sure it's not an argument (i.e. no --)
	var newCommand []string
	if len(command) > 0 && !strings.HasPrefix(command[0], "--") {
		newCommand = append(newCommand, command[0])
	}
	newArgMap := argMutateFunc(argMap)
	newCommand = append(newCommand, BuildArgumentListFromMap(newArgMap, map[string]string{})...)
	return newCommand
}