bbash/input_parser/input_parser.go
Tobias P.L Wennberg 15eeadf5d3 initial
2025-01-10 13:29:56 +01:00

37 lines
624 B
Go

package input_parser
import (
"bufio"
"log"
"os"
"strings"
)
type Input struct {
// The instruction a.k.a first argument
Instruction string
// The args, currently just the string after the instruction
Args string
}
func Parse() Input {
reader := bufio.NewReader(os.Stdin)
input, err := reader.ReadString('\n')
if err != nil {
log.Fatal(err.Error())
}
split := strings.SplitN(string(input), " ", 2)
instruction := strings.TrimSpace(split[0])
var arg string
if len(split) == 2 {
arg = strings.TrimSpace(split[1])
} else {
arg = ""
}
return Input {
Instruction: instruction,
Args: arg,
}
}