From 3ac9732a26edbeaa63cb4b9df35e4d54e7623904 Mon Sep 17 00:00:00 2001 From: jienfak Date: Tue, 5 May 2020 11:04:29 +0500 Subject: [PATCH] ls: Simplified. No "-d" flag. Use "-r 0" when with args and "-r 1" when without. --- ls/ls.go | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/ls/ls.go b/ls/ls.go index 950ebf9..3fa0f2c 100644 --- a/ls/ls.go +++ b/ls/ls.go @@ -6,11 +6,6 @@ import( "strings" ) -var( - dirFlag bool - foldLvl int -) - func IsDir(p string) (bool, error) { finfo, e := os.Stat(p) if e != nil { @@ -51,22 +46,20 @@ func ls(p string, fold int) error { pp := strings.TrimRight(p, "/") - if !isDir || dirFlag || fold<1 { - fmt.Println(pp); - }else{ + if isDir && fold>0 { l, e := ReadDir(pp) if e!=nil { return e } for _, f := range l { s := pp+"/"+f.Name() - if b, _:=IsDir(s) ; b { - fmt.Println(s) - } - if 00 { + fmt.Println(f.Name()) + e := ls(f.Name(), foldLvl) + if e!=nil { + status = 1 + fmt.Fprintf(os.Stderr, "%s: %s.\n", arg0, e) + } + } else { + fmt.Println(f.Name()) } } }