40 lines
894 B
Go
40 lines
894 B
Go
package ls
|
|
|
|
import (
|
|
"bbash/environment"
|
|
"bbash/input_parser"
|
|
"fmt"
|
|
"os"
|
|
"slices"
|
|
)
|
|
|
|
func Ls(in input_parser.Input, env *environment.Env) {
|
|
flagsArray := []string{
|
|
"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\n")
|
|
fmt.Printf("Supported flags are:\n")
|
|
for _, flag := range flagsArray {
|
|
fmt.Println(flag + " " + flagsDictionary[flag])
|
|
} // Print flags and their description
|
|
return
|
|
}
|
|
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] == '.') && !(slices.Contains(in.Flags, "a")) {
|
|
continue
|
|
} // allows for hidden directories
|
|
fmt.Print(f.Name())
|
|
fmt.Println()
|
|
}
|
|
}
|