Compare commits

..

No commits in common. "4ed189affedcd1a1ea7f2d87dd4ce7fe2b9cbc0c" and "7dc7def780bf77832dd63379689a3f123d7e0483" have entirely different histories.

9 changed files with 30 additions and 83 deletions

8
.idea/.gitignore generated vendored
View File

@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

9
.idea/bbash.iml generated
View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

8
.idea/modules.xml generated
View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/bbash.iml" filepath="$PROJECT_DIR$/.idea/bbash.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated
View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -12,9 +12,11 @@ func Cat(in input_parser.Input, env *environment.Env) {
file := filepath.Join(env.Path, in.Args)
bytea_str, err := os.ReadFile(file)
if err != nil {
fmt.Print(fmt.Sprintf("Lilla råttan åt upp din kod", err.Error()))
fmt.Print(fmt.Sprintf("Error opening file: %s", err.Error()))
return
}
fmt.Print(string(bytea_str))
}

View File

@ -21,7 +21,6 @@ import (
"path/filepath"
"strings"
)
var path_command map[string]string
func Init(env *environment.Env) {
@ -32,37 +31,24 @@ func Init(env *environment.Env) {
func Run_command(in input_parser.Input, env *environment.Env) {
switch in.Instruction {
case "pwd":
pwd.Pwd(in, env)
case "echo":
echo.Echo(in, env)
case "ls":
ls.Ls(in, env, "flags")
case "cd":
cd.Cd(in, env)
case "man":
man.Man(in, env)
case "cat":
cat.Cat(in, env)
case "head":
head.Head(in, env)
case "touch":
touch.Touch(in, env)
case "rm":
rm.Rm(in, env)
case "cp":
cp.Cp(in, env)
case "mv":
mv.Mv(in, env)
case "help":
help.Help(in, env)
default:
if !run_by_path(in, env) {
fmt.Println(fmt.Sprintf("No such command! (%s)", in.Instruction))
}
case "pwd": pwd.Pwd(in, env)
case "echo": echo.Echo(in, env)
case "ls": ls.Ls(in, env)
case "cd": cd.Cd(in, env)
case "man": man.Man(in, env)
case "cat": cat.Cat(in, env)
case "head": head.Head(in, env)
case "touch": touch.Touch(in, env)
case "rm": rm.Rm(in, env)
case "cp": cp.Cp(in, env)
case "mv": mv.Mv(in,env)
case "help": help.Help(in,env)
default:
if !run_by_path(in, env) {
fmt.Println(fmt.Sprintf("No such command! (%s)", in.Instruction))
}
}
}
// Returns if anything was run or not
func run_by_path(in input_parser.Input, env *environment.Env) bool {
instr, errB := path_command[in.Instruction]
@ -74,7 +60,7 @@ func run_by_path(in input_parser.Input, env *environment.Env) bool {
print(string(output))
return true
}
func init_path(env *environment.Env) {
path := strings.Split(env.Env["PATH"], ":")
for _, a_path := range path {
@ -97,7 +83,7 @@ func recursive_executable_finder(path string) {
path_command[f.Name()] = filepath.Join(path, f.Name())
}
}
func is_executable(name string) bool {
func is_executable( name string) bool {
return true
stat, _ := os.Stat(name)
mode := stat.Mode()

View File

@ -1,12 +1,12 @@
package echo
import (
"bbash/environment"
"bbash/input_parser"
"fmt"
"bbash/environment"
)
func Echo(in input_parser.Input, _ *environment.Env) {
fmt.Print(in.Args)
// fungerar inte om råttan åt din kod
}

View File

@ -1,9 +1,9 @@
package help
import (
"bbash/environment"
"bbash/input_parser"
"fmt"
"bbash/environment"
)
func Help(in input_parser.Input, _ *environment.Env) {
@ -12,7 +12,7 @@ func Help(in input_parser.Input, _ *environment.Env) {
The options are:
pwd: Output current working directory
echo: Echoes the input argument
ls: Lists Sources in the current working directory
ls: List Sources in the current working directory
cd: Change to directory given in the argument
man: Manual for the terminal options
cat: Outputs the contents of the given file
@ -24,3 +24,5 @@ mv: Moves a given file. Argument: <source> <destination>
help: Prints this message
`)
}

View File

@ -5,29 +5,17 @@ import (
"bbash/input_parser"
"fmt"
"os"
"strings"
)
var flagsArray []string = []string{"a ", "help "}
var flagsDictionary map[string]string = map[string]string{"a": "-a shows hidden directories", "help": "-help shows this message"}
func Ls(in input_parser.Input, env *environment.Env, flags string) {
if flags == "help" || flags == "-help" {
fmt.Printf("Lists Sources in the current working directory")
fmt.Printf("Supported flags are")
for i := 0; i < len(flagsArray); i++ {
fmt.Println(flagsArray[i] + flagsDictionary[flagsArray[i]])
} // this prints all flags and their description
}
func Ls(in input_parser.Input, env *environment.Env) {
fs, err := os.ReadDir(env.Path)
if err != nil {
fmt.Print(fmt.Sprintf("Error opening directory %s", env.Path))
}
for _, f := range fs {
if (f.Name()[0] == '.') && (strings.Contains(flags, "a")) {
continue
} // allows for hidden directories
fmt.Print(f.Name())
fmt.Println()
}
}