added flags to the parser and ls

This commit is contained in:
Laukka 2025-01-12 14:22:47 +01:00
parent 84f321389a
commit 7cec7f8604
2 changed files with 7 additions and 5 deletions

View File

@ -36,7 +36,9 @@ func parse(input string) Input {
var flags []string
var args []string
for _, arg := range split[1:] {
if arg[0:2] == "--" {
if len(arg) == 1 && arg[0] == '-' {
continue
} else if arg[0:2] == "--" {
var result = strings.TrimSpace(arg)
flags = append(flags, string(result[2:]))
continue
@ -79,7 +81,7 @@ func input_str(env *environment.Env) string {
for {
r_rune, _, err := reader.ReadRune()
if err != nil {
fmt.Print(fmt.Sprintf("Error reading user input: ", err.Error()))
fmt.Print(fmt.Sprintf("Error reading user input: %s", err.Error()))
}
switch r_rune {
case 3: // ^C
@ -116,7 +118,7 @@ func input_str(env *environment.Env) string {
fmt.Print(" > ")
fmt.Print(input)
}
loop_exit:
loop_exit:
term.Restore(int(std_fd), term_restore)
fmt.Println()
return input

View File

@ -7,14 +7,14 @@ import (
)
func TestParse(t *testing.T) {
test := parse("ls -abcd hej -ee tbtry --help")
test := parse("ls -abcd hej -ee tbtry --help - -o")
fmt.Println(test.Instruction)
fmt.Println(test.Args)
fmt.Println(test.Flags)
}
func TestInput(t *testing.T) {
input := input_str(&environment.Env{})
fmt.Println(input)
}