From 62743d4b9164911c627aea4f01016ed75748806e Mon Sep 17 00:00:00 2001 From: Laukka Date: Tue, 14 Jan 2025 17:05:33 +0100 Subject: [PATCH] fixade bug med --help flagsen --- command/command.go | 3 --- command/head/head.go | 8 ++++---- command/ls/ls.go | 10 +++++----- command/rm/rm.go | 4 ++++ command/tail/tail.go | 8 ++++---- command/touch/touch.go | 24 ------------------------ command/whereareyou/whereareyou.go | 2 +- input_parser/input_parser.go | 13 ++++++------- 8 files changed, 24 insertions(+), 48 deletions(-) delete mode 100644 command/touch/touch.go diff --git a/command/command.go b/command/command.go index c0fb5b8..1b7e1bc 100644 --- a/command/command.go +++ b/command/command.go @@ -15,7 +15,6 @@ import ( "bbash/command/pwd" "bbash/command/rm" "bbash/command/tail" - "bbash/command/touch" "bbash/command/whereareyou" "bbash/environment" "bbash/input_parser" @@ -52,8 +51,6 @@ func Run_command(in input_parser.Input, env *environment.Env) { cat.Cat(in, env) case "head": head.Head(in, env) - case "touch": - touch.Touch(in, env) case "rm": rm.Rm(in, env) case "cp": diff --git a/command/head/head.go b/command/head/head.go index 830c0bb..cd84786 100644 --- a/command/head/head.go +++ b/command/head/head.go @@ -13,16 +13,16 @@ import ( func Head(in input_parser.Input, env *environment.Env) { flagsArray := []string{ - "n ", - "help ", + "n", + "help", } flagsDictionary := map[string]string{ "n": "-n displays the line numbers", "help": "-help shows this message", } if slices.Contains(in.Flags, "help") { - fmt.Printf("Lists Sources in the current working directory") - fmt.Printf("Supported flags are:") + fmt.Printf("Lists Sources in the current working directory\n") + fmt.Printf("Supported flags are:\n") for _, flag := range flagsArray { fmt.Println(flag + flagsDictionary[flag]) } // Print flags and there description diff --git a/command/ls/ls.go b/command/ls/ls.go index a033fcb..13fb779 100644 --- a/command/ls/ls.go +++ b/command/ls/ls.go @@ -10,18 +10,18 @@ import ( func Ls(in input_parser.Input, env *environment.Env) { flagsArray := []string{ - "a ", - "help ", + "a", + "help", } flagsDictionary := map[string]string{ "a": "-a shows hidden directories", "help": "-help shows this message", } if slices.Contains(in.Flags, "help") { - fmt.Printf("Lists Sources in the current working directory") - fmt.Printf("Supported flags are:") + fmt.Printf("Lists Sources in the current working directory\n") + fmt.Printf("Supported flags are:\n") for _, flag := range flagsArray { - fmt.Println(flag + flagsDictionary[flag]) + fmt.Println(flag + " " + flagsDictionary[flag]) } // Print flags and their description return } diff --git a/command/rm/rm.go b/command/rm/rm.go index c24b500..4d8b851 100644 --- a/command/rm/rm.go +++ b/command/rm/rm.go @@ -6,12 +6,16 @@ import ( "fmt" "os" "path/filepath" + "slices" ) func Rm(in input_parser.Input, env *environment.Env) { file_path := filepath.Join(env.Path, in.Args_raw) stat, err := os.Stat(file_path) if os.IsNotExist(err) { + if slices.Contains(in.Flags, "t") { + return + } fmt.Println(fmt.Sprintf("File does not exist")) return } diff --git a/command/tail/tail.go b/command/tail/tail.go index 9b5965f..764a4f5 100644 --- a/command/tail/tail.go +++ b/command/tail/tail.go @@ -15,16 +15,16 @@ import ( func Tail(in input_parser.Input, env *environment.Env) { flagsArray := []string{ - "n ", - "help ", + "n", + "help", } flagsDictionary := map[string]string{ "n": "-n displays the line numbers", "help": "-help shows this message", } if slices.Contains(in.Flags, "help") { - fmt.Printf("Lists Sources in the current working directory") - fmt.Printf("Supported flags are:") + fmt.Printf("Lists Sources in the current working directory\n") + fmt.Printf("Supported flags are:\n") for _, flag := range flagsArray { fmt.Println(flag + flagsDictionary[flag]) } // Print flags and there description diff --git a/command/touch/touch.go b/command/touch/touch.go deleted file mode 100644 index 00e379f..0000000 --- a/command/touch/touch.go +++ /dev/null @@ -1,24 +0,0 @@ -package touch - -import ( - "bbash/environment" - "bbash/input_parser" - "fmt" - "os" - "path/filepath" -) - -func Touch(in input_parser.Input, env *environment.Env) { - file_path := filepath.Join(env.Path, in.Args_raw) - _, err := os.Stat(file_path) - if !os.IsNotExist(err) { - fmt.Print(fmt.Sprintf("File alredy exist!")) - return - } - file, err := os.Create(file_path) - if err != nil { - fmt.Print(fmt.Sprintf("Error creating file: %s", err.Error())) - return - } - defer file.Close() -} diff --git a/command/whereareyou/whereareyou.go b/command/whereareyou/whereareyou.go index d08c186..e417039 100644 --- a/command/whereareyou/whereareyou.go +++ b/command/whereareyou/whereareyou.go @@ -7,5 +7,5 @@ import ( ) func Whereareyou(in input_parser.Input, env *environment.Env) { - fmt.Println("You're in the thick of it everybody knows!") + fmt.Print("You're in the thick of it everybody knows!") } diff --git a/input_parser/input_parser.go b/input_parser/input_parser.go index f2fab72..b84226a 100644 --- a/input_parser/input_parser.go +++ b/input_parser/input_parser.go @@ -4,10 +4,9 @@ import ( "bbash/environment" "bufio" "fmt" + "golang.org/x/term" "os" "strings" - - "golang.org/x/term" ) var prevGhostString string @@ -104,7 +103,7 @@ func input_str(env *environment.Env) string { case 4: // ^D input = "exit" goto loop_exit - case 8: // + case 8: // input_at := input[:cursor] input_after := input[cursor:] last_index := strings.LastIndex(input_at, " ") @@ -115,8 +114,8 @@ func input_str(env *environment.Env) string { input_at = input_at[:last_index] cursor = len(input_at) } - input = input_at+input_after - + input = input_at + input_after + case 9: // TAB input = AutoComplete(input, *env) cursor = len(input) @@ -129,14 +128,14 @@ func input_str(env *environment.Env) string { input_at = input_at[:len(input_at)-1] cursor-- } - input=input_at+input_after + input = input_at + input_after case 13: // Enter goto loop_exit default: input_at := input[:cursor] input_after := input[cursor:] input_at += string(r_rune) - input = input_at+input_after + input = input_at + input_after cursor++ } ghost_input := AutoCompleteHistory(input, *env)