util: Improve tree printing function
This makes it behave more like the core GNU tree util.
This commit is contained in:
@@ -29,8 +29,15 @@ import (
|
|||||||
// FsTree returns a string representation of the file system tree similar to the
|
// FsTree returns a string representation of the file system tree similar to the
|
||||||
// well-known `tree` command.
|
// well-known `tree` command.
|
||||||
func FsTree(fs afero.Fs, name string) (string, error) {
|
func FsTree(fs afero.Fs, name string) (string, error) {
|
||||||
str := ".\n" // top level dir
|
clean := path.Clean(name)
|
||||||
s, err := stringify(fs, path.Clean(name), []bool{})
|
str := clean + "/\n" // named dir
|
||||||
|
if name == "" {
|
||||||
|
str = ".\n" // relative dir
|
||||||
|
}
|
||||||
|
if name == "/" {
|
||||||
|
str = "/\n" // root dir
|
||||||
|
}
|
||||||
|
s, err := stringify(fs, clean, []bool{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.
|
/
|
||||||
├── 1
|
├── 1
|
||||||
├── 2
|
├── 2
|
||||||
├── 3
|
├── 3
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.
|
/
|
||||||
└── simple1/
|
└── simple1/
|
||||||
├── 1
|
├── 1
|
||||||
├── 2
|
├── 2
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.
|
/
|
||||||
└── dest/
|
└── dest/
|
||||||
└── simple1/
|
└── simple1/
|
||||||
├── 1
|
├── 1
|
||||||
|
|||||||
Reference in New Issue
Block a user