fixade bug med --help flagsen
This commit is contained in:
parent
2a594eac1d
commit
62743d4b91
@ -15,7 +15,6 @@ import (
|
|||||||
"bbash/command/pwd"
|
"bbash/command/pwd"
|
||||||
"bbash/command/rm"
|
"bbash/command/rm"
|
||||||
"bbash/command/tail"
|
"bbash/command/tail"
|
||||||
"bbash/command/touch"
|
|
||||||
"bbash/command/whereareyou"
|
"bbash/command/whereareyou"
|
||||||
"bbash/environment"
|
"bbash/environment"
|
||||||
"bbash/input_parser"
|
"bbash/input_parser"
|
||||||
@ -52,8 +51,6 @@ func Run_command(in input_parser.Input, env *environment.Env) {
|
|||||||
cat.Cat(in, env)
|
cat.Cat(in, env)
|
||||||
case "head":
|
case "head":
|
||||||
head.Head(in, env)
|
head.Head(in, env)
|
||||||
case "touch":
|
|
||||||
touch.Touch(in, env)
|
|
||||||
case "rm":
|
case "rm":
|
||||||
rm.Rm(in, env)
|
rm.Rm(in, env)
|
||||||
case "cp":
|
case "cp":
|
||||||
|
|||||||
@ -13,16 +13,16 @@ import (
|
|||||||
|
|
||||||
func Head(in input_parser.Input, env *environment.Env) {
|
func Head(in input_parser.Input, env *environment.Env) {
|
||||||
flagsArray := []string{
|
flagsArray := []string{
|
||||||
"n ",
|
"n",
|
||||||
"help ",
|
"help",
|
||||||
}
|
}
|
||||||
flagsDictionary := map[string]string{
|
flagsDictionary := map[string]string{
|
||||||
"n": "-n displays the line numbers",
|
"n": "-n displays the line numbers",
|
||||||
"help": "-help shows this message",
|
"help": "-help shows this message",
|
||||||
}
|
}
|
||||||
if slices.Contains(in.Flags, "help") {
|
if slices.Contains(in.Flags, "help") {
|
||||||
fmt.Printf("Lists Sources in the current working directory")
|
fmt.Printf("Lists Sources in the current working directory\n")
|
||||||
fmt.Printf("Supported flags are:")
|
fmt.Printf("Supported flags are:\n")
|
||||||
for _, flag := range flagsArray {
|
for _, flag := range flagsArray {
|
||||||
fmt.Println(flag + flagsDictionary[flag])
|
fmt.Println(flag + flagsDictionary[flag])
|
||||||
} // Print flags and there description
|
} // Print flags and there description
|
||||||
|
|||||||
@ -10,18 +10,18 @@ import (
|
|||||||
|
|
||||||
func Ls(in input_parser.Input, env *environment.Env) {
|
func Ls(in input_parser.Input, env *environment.Env) {
|
||||||
flagsArray := []string{
|
flagsArray := []string{
|
||||||
"a ",
|
"a",
|
||||||
"help ",
|
"help",
|
||||||
}
|
}
|
||||||
flagsDictionary := map[string]string{
|
flagsDictionary := map[string]string{
|
||||||
"a": "-a shows hidden directories",
|
"a": "-a shows hidden directories",
|
||||||
"help": "-help shows this message",
|
"help": "-help shows this message",
|
||||||
}
|
}
|
||||||
if slices.Contains(in.Flags, "help") {
|
if slices.Contains(in.Flags, "help") {
|
||||||
fmt.Printf("Lists Sources in the current working directory")
|
fmt.Printf("Lists Sources in the current working directory\n")
|
||||||
fmt.Printf("Supported flags are:")
|
fmt.Printf("Supported flags are:\n")
|
||||||
for _, flag := range flagsArray {
|
for _, flag := range flagsArray {
|
||||||
fmt.Println(flag + flagsDictionary[flag])
|
fmt.Println(flag + " " + flagsDictionary[flag])
|
||||||
} // Print flags and their description
|
} // Print flags and their description
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,12 +6,16 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Rm(in input_parser.Input, env *environment.Env) {
|
func Rm(in input_parser.Input, env *environment.Env) {
|
||||||
file_path := filepath.Join(env.Path, in.Args_raw)
|
file_path := filepath.Join(env.Path, in.Args_raw)
|
||||||
stat, err := os.Stat(file_path)
|
stat, err := os.Stat(file_path)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
|
if slices.Contains(in.Flags, "t") {
|
||||||
|
return
|
||||||
|
}
|
||||||
fmt.Println(fmt.Sprintf("File does not exist"))
|
fmt.Println(fmt.Sprintf("File does not exist"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,16 +15,16 @@ import (
|
|||||||
|
|
||||||
func Tail(in input_parser.Input, env *environment.Env) {
|
func Tail(in input_parser.Input, env *environment.Env) {
|
||||||
flagsArray := []string{
|
flagsArray := []string{
|
||||||
"n ",
|
"n",
|
||||||
"help ",
|
"help",
|
||||||
}
|
}
|
||||||
flagsDictionary := map[string]string{
|
flagsDictionary := map[string]string{
|
||||||
"n": "-n displays the line numbers",
|
"n": "-n displays the line numbers",
|
||||||
"help": "-help shows this message",
|
"help": "-help shows this message",
|
||||||
}
|
}
|
||||||
if slices.Contains(in.Flags, "help") {
|
if slices.Contains(in.Flags, "help") {
|
||||||
fmt.Printf("Lists Sources in the current working directory")
|
fmt.Printf("Lists Sources in the current working directory\n")
|
||||||
fmt.Printf("Supported flags are:")
|
fmt.Printf("Supported flags are:\n")
|
||||||
for _, flag := range flagsArray {
|
for _, flag := range flagsArray {
|
||||||
fmt.Println(flag + flagsDictionary[flag])
|
fmt.Println(flag + flagsDictionary[flag])
|
||||||
} // Print flags and there description
|
} // Print flags and there description
|
||||||
|
|||||||
@ -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()
|
|
||||||
}
|
|
||||||
@ -7,5 +7,5 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Whereareyou(in input_parser.Input, env *environment.Env) {
|
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!")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,10 +4,9 @@ import (
|
|||||||
"bbash/environment"
|
"bbash/environment"
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"golang.org/x/term"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/term"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var prevGhostString string
|
var prevGhostString string
|
||||||
@ -104,7 +103,7 @@ func input_str(env *environment.Env) string {
|
|||||||
case 4: // ^D
|
case 4: // ^D
|
||||||
input = "exit"
|
input = "exit"
|
||||||
goto loop_exit
|
goto loop_exit
|
||||||
case 8: // <CTR><BACKSPACE>
|
case 8: // <CTR><BACKSPACE>
|
||||||
input_at := input[:cursor]
|
input_at := input[:cursor]
|
||||||
input_after := input[cursor:]
|
input_after := input[cursor:]
|
||||||
last_index := strings.LastIndex(input_at, " ")
|
last_index := strings.LastIndex(input_at, " ")
|
||||||
@ -115,7 +114,7 @@ func input_str(env *environment.Env) string {
|
|||||||
input_at = input_at[:last_index]
|
input_at = input_at[:last_index]
|
||||||
cursor = len(input_at)
|
cursor = len(input_at)
|
||||||
}
|
}
|
||||||
input = input_at+input_after
|
input = input_at + input_after
|
||||||
|
|
||||||
case 9: // TAB
|
case 9: // TAB
|
||||||
input = AutoComplete(input, *env)
|
input = AutoComplete(input, *env)
|
||||||
@ -129,14 +128,14 @@ func input_str(env *environment.Env) string {
|
|||||||
input_at = input_at[:len(input_at)-1]
|
input_at = input_at[:len(input_at)-1]
|
||||||
cursor--
|
cursor--
|
||||||
}
|
}
|
||||||
input=input_at+input_after
|
input = input_at + input_after
|
||||||
case 13: // Enter
|
case 13: // Enter
|
||||||
goto loop_exit
|
goto loop_exit
|
||||||
default:
|
default:
|
||||||
input_at := input[:cursor]
|
input_at := input[:cursor]
|
||||||
input_after := input[cursor:]
|
input_after := input[cursor:]
|
||||||
input_at += string(r_rune)
|
input_at += string(r_rune)
|
||||||
input = input_at+input_after
|
input = input_at + input_after
|
||||||
cursor++
|
cursor++
|
||||||
}
|
}
|
||||||
ghost_input := AutoCompleteHistory(input, *env)
|
ghost_input := AutoCompleteHistory(input, *env)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user