This commit is contained in:
Colin Marc 2014-10-23 14:13:42 +02:00
Родитель 48bbac024b
Коммит aa76fc4a6d
2 изменённых файлов: 18 добавлений и 10 удалений

Просмотреть файл

@ -4,9 +4,10 @@ import (
"fmt"
"github.com/colinmarc/hdfs"
"os"
"strings"
)
func ls(paths []string, all, long bool) {
func ls(paths []string, long, all bool) {
paths, nn, err := normalizePaths(paths)
if err != nil {
fatal(err)
@ -38,28 +39,35 @@ func ls(paths []string, all, long bool) {
}
if len(files) == 0 && len(dirs) == 1 {
printDir(client, dirs[0], all, long)
printDir(client, dirs[0], long, all)
} else {
printFiles(files, long)
printFiles(files, long, all)
for _, dir := range dirs {
fmt.Printf("\n%s/:\n", dir)
printDir(client, dir, all, long)
printDir(client, dir, long, all)
}
}
}
func printDir(client *hdfs.Client, dir string, all, long bool) {
func printDir(client *hdfs.Client, dir string, long, all bool) {
files, err := readDir(client, dir, "")
if err != nil {
fatal(err)
}
printFiles(files, long)
if all {
fmt.Println(".")
fmt.Println("..")
}
func printFiles(files []os.FileInfo, long bool) {
printFiles(files, long, all)
}
func printFiles(files []os.FileInfo, long, all bool) {
for _, file := range files {
if all || !strings.HasPrefix(file.Name(), ".") {
fmt.Println(file.Name())
}
}
}

Просмотреть файл

@ -9,8 +9,8 @@ import (
var (
lsOpts = getopt.New()
lsa = lsOpts.Bool('a')
lsl = lsOpts.Bool('l')
lsa = lsOpts.Bool('a')
usage = fmt.Sprintf(`Usage: %s COMMAND [OPTION]... [FILE]...
The flags available are a subset of the POSIX ones, but should behave similarly.
@ -29,7 +29,7 @@ func main() {
switch command {
case "ls":
lsOpts.Parse(os.Args[1:])
ls(lsOpts.Args(), *lsa, *lsl)
ls(lsOpts.Args(), *lsl, *lsa)
case "complete":
var words []string
if len(os.Args) == 3 {