ls is working now.

master
Zed A. Shaw 6 days ago
parent e687198a3d
commit 80d7f6d1a3
  1. 3
      ls/.gitignore
  2. 4
      ls/Makefile
  3. 3
      ls/go.mod
  4. 42
      ls/main.go

3
ls/.gitignore vendored

@ -0,0 +1,3 @@
ls
ls.exe
*.out

@ -0,0 +1,4 @@
build:
go build .

@ -0,0 +1,3 @@
module lcthw.dev/go/go-coreutils/ls
go 1.25.3

@ -0,0 +1,42 @@
package main
import (
"fmt"
"io/fs"
"path/filepath"
"flag"
)
func main() {
var recurse bool
flag.BoolVar(&recurse, "R", false, "recursive listing")
flag.Parse()
paths := flag.Args()
if len(paths) == 0 {
paths = append(paths, ".")
}
for _, what := range paths {
if flag.NArg() > 1 {
fmt.Printf("\n%s:\n", what)
}
filepath.WalkDir(what, func (path string, d fs.DirEntry, err error) error {
if path == what { return nil }
if d.IsDir() && recurse {
fmt.Printf("\n%s:\n", path)
} else if d.IsDir() {
fmt.Printf("%s\n", filepath.Base(path))
return fs.SkipDir
} else {
fmt.Printf("%s\n", filepath.Base(path))
}
return nil
})
}
}
Loading…
Cancel
Save