Compare commits
No commits in common. "4ed189affedcd1a1ea7f2d87dd4ce7fe2b9cbc0c" and "7dc7def780bf77832dd63379689a3f123d7e0483" have entirely different histories.
4ed189affe
...
7dc7def780
8
.idea/.gitignore
generated
vendored
8
.idea/.gitignore
generated
vendored
@ -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
9
.idea/bbash.iml
generated
@ -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
8
.idea/modules.xml
generated
@ -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
6
.idea/vcs.xml
generated
@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@ -12,9 +12,11 @@ func Cat(in input_parser.Input, env *environment.Env) {
|
|||||||
file := filepath.Join(env.Path, in.Args)
|
file := filepath.Join(env.Path, in.Args)
|
||||||
bytea_str, err := os.ReadFile(file)
|
bytea_str, err := os.ReadFile(file)
|
||||||
if err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
fmt.Print(string(bytea_str))
|
fmt.Print(string(bytea_str))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,6 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var path_command map[string]string
|
var path_command map[string]string
|
||||||
|
|
||||||
func Init(env *environment.Env) {
|
func Init(env *environment.Env) {
|
||||||
@ -32,37 +31,24 @@ func Init(env *environment.Env) {
|
|||||||
|
|
||||||
func Run_command(in input_parser.Input, env *environment.Env) {
|
func Run_command(in input_parser.Input, env *environment.Env) {
|
||||||
switch in.Instruction {
|
switch in.Instruction {
|
||||||
case "pwd":
|
case "pwd": pwd.Pwd(in, env)
|
||||||
pwd.Pwd(in, env)
|
case "echo": echo.Echo(in, env)
|
||||||
case "echo":
|
case "ls": ls.Ls(in, env)
|
||||||
echo.Echo(in, env)
|
case "cd": cd.Cd(in, env)
|
||||||
case "ls":
|
case "man": man.Man(in, env)
|
||||||
ls.Ls(in, env, "flags")
|
case "cat": cat.Cat(in, env)
|
||||||
case "cd":
|
case "head": head.Head(in, env)
|
||||||
cd.Cd(in, env)
|
case "touch": touch.Touch(in, env)
|
||||||
case "man":
|
case "rm": rm.Rm(in, env)
|
||||||
man.Man(in, env)
|
case "cp": cp.Cp(in, env)
|
||||||
case "cat":
|
case "mv": mv.Mv(in,env)
|
||||||
cat.Cat(in, env)
|
case "help": help.Help(in,env)
|
||||||
case "head":
|
default:
|
||||||
head.Head(in, env)
|
if !run_by_path(in, env) {
|
||||||
case "touch":
|
fmt.Println(fmt.Sprintf("No such command! (%s)", in.Instruction))
|
||||||
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
|
// Returns if anything was run or not
|
||||||
func run_by_path(in input_parser.Input, env *environment.Env) bool {
|
func run_by_path(in input_parser.Input, env *environment.Env) bool {
|
||||||
instr, errB := path_command[in.Instruction]
|
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))
|
print(string(output))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func init_path(env *environment.Env) {
|
func init_path(env *environment.Env) {
|
||||||
path := strings.Split(env.Env["PATH"], ":")
|
path := strings.Split(env.Env["PATH"], ":")
|
||||||
for _, a_path := range 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())
|
path_command[f.Name()] = filepath.Join(path, f.Name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func is_executable(name string) bool {
|
func is_executable( name string) bool {
|
||||||
return true
|
return true
|
||||||
stat, _ := os.Stat(name)
|
stat, _ := os.Stat(name)
|
||||||
mode := stat.Mode()
|
mode := stat.Mode()
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
package echo
|
package echo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bbash/environment"
|
|
||||||
"bbash/input_parser"
|
"bbash/input_parser"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"bbash/environment"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Echo(in input_parser.Input, _ *environment.Env) {
|
func Echo(in input_parser.Input, _ *environment.Env) {
|
||||||
fmt.Print(in.Args)
|
fmt.Print(in.Args)
|
||||||
// fungerar inte om råttan åt din kod
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
package help
|
package help
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bbash/environment"
|
|
||||||
"bbash/input_parser"
|
"bbash/input_parser"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"bbash/environment"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Help(in input_parser.Input, _ *environment.Env) {
|
func Help(in input_parser.Input, _ *environment.Env) {
|
||||||
@ -12,7 +12,7 @@ func Help(in input_parser.Input, _ *environment.Env) {
|
|||||||
The options are:
|
The options are:
|
||||||
pwd: Output current working directory
|
pwd: Output current working directory
|
||||||
echo: Echoes the input argument
|
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
|
cd: Change to directory given in the argument
|
||||||
man: Manual for the terminal options
|
man: Manual for the terminal options
|
||||||
cat: Outputs the contents of the given file
|
cat: Outputs the contents of the given file
|
||||||
@ -24,3 +24,5 @@ mv: Moves a given file. Argument: <source> <destination>
|
|||||||
help: Prints this message
|
help: Prints this message
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -5,29 +5,17 @@ import (
|
|||||||
"bbash/input_parser"
|
"bbash/input_parser"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var flagsArray []string = []string{"a ", "help "}
|
func Ls(in input_parser.Input, env *environment.Env) {
|
||||||
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
|
|
||||||
}
|
|
||||||
fs, err := os.ReadDir(env.Path)
|
fs, err := os.ReadDir(env.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Print(fmt.Sprintf("Error opening directory %s", env.Path))
|
fmt.Print(fmt.Sprintf("Error opening directory %s", env.Path))
|
||||||
}
|
}
|
||||||
for _, f := range fs {
|
for _, f := range fs {
|
||||||
if (f.Name()[0] == '.') && (strings.Contains(flags, "a")) {
|
|
||||||
continue
|
|
||||||
} // allows for hidden directories
|
|
||||||
fmt.Print(f.Name())
|
fmt.Print(f.Name())
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user