INNER CODE UNIT · Go

splitInputIntoCommands

kubecolor/kubecolor · internal/cmd/imagegen/main.go:281

func splitInputIntoCommands(input string) ([]Command, error) {
	if !strings.HasPrefix(input, "$") {
		return nil, fmt.Errorf(`expected first line to start with '$ ...'`)
	}

	lines := strings.Split(input, "\n")

	var commands []Command
	var currentCommand Command

	for _, line := range lines {
		if cmdline, ok := strings.CutPrefix(line, "$"); ok {
			// new command
			cmdline = strings.TrimSpace(cmdline)
			if currentCommand.Exe != "" {
				currentCommand.Input = strings.TrimSpace(currentCommand.Input)
				commands = append(commands, currentCommand)
			}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…