This is an education project that attempts to reimplement the GNU coreutils in Go. You can find the full manual here:
https://www.gnu.org/software/coreutils/manual/coreutils.html
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
694 B
42 lines
694 B
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
|
|
})
|
|
}
|
|
}
|
|
|