lsf: add --absolute flag to add a leading / onto path names

This commit is contained in:
Nick Craig-Wood
2018-06-03 10:42:34 +01:00
parent 5302e5f9b1
commit 3ef938ebde
3 changed files with 33 additions and 5 deletions
+14 -5
View File
@@ -1372,6 +1372,7 @@ func CopyFile(fdst fs.Fs, fsrc fs.Fs, dstFileName string, srcFileName string) (e
type ListFormat struct {
separator string
dirSlash bool
absolute bool
output []func() string
entry fs.DirEntry
csv *csv.Writer
@@ -1388,6 +1389,11 @@ func (l *ListFormat) SetDirSlash(dirSlash bool) {
l.dirSlash = dirSlash
}
// SetAbsolute prints a leading slash in front of path names
func (l *ListFormat) SetAbsolute(absolute bool) {
l.absolute = absolute
}
// SetCSV defines if the output should be csv
//
// Note that you should call SetSeparator before this if you want a
@@ -1423,12 +1429,15 @@ func (l *ListFormat) AddSize() {
// AddPath adds path to file to output
func (l *ListFormat) AddPath() {
l.AppendOutput(func() string {
_, isDir := l.entry.(fs.Directory)
if isDir && l.dirSlash {
return l.entry.Remote() + "/"
remote := l.entry.Remote()
if l.absolute && !strings.HasPrefix(remote, "/") {
remote = "/" + remote
}
return l.entry.Remote()
_, isDir := l.entry.(fs.Directory)
if isDir && l.dirSlash {
remote += "/"
}
return remote
})
}