forked from TrueCloudLab/rclone
operations: turn ListFormatted into a Format method on ListFormat
This commit is contained in:
parent
db4c206e0e
commit
2a32e2d838
3 changed files with 18 additions and 18 deletions
|
@ -166,7 +166,7 @@ func Lsf(fsrc fs.Fs, out io.Writer) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Fprintln(out, operations.ListFormatted(&entry, &list))
|
fmt.Fprintln(out, list.Format(entry))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
|
@ -1445,11 +1445,11 @@ func (l *ListFormat) AppendOutput(functionToAppend func() string) {
|
||||||
l.output = append(l.output, functionToAppend)
|
l.output = append(l.output, functionToAppend)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListFormatted prints information about specific file in specific format
|
// Format prints information about the DirEntry in the format defined
|
||||||
func ListFormatted(entry *fs.DirEntry, list *ListFormat) string {
|
func (l *ListFormat) Format(entry fs.DirEntry) string {
|
||||||
list.entry = *entry
|
l.entry = entry
|
||||||
var out string
|
var out string
|
||||||
for _, fun := range list.output {
|
for _, fun := range l.output {
|
||||||
out += fun()
|
out += fun()
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
|
|
|
@ -694,43 +694,43 @@ func TestListFormat(t *testing.T) {
|
||||||
var list operations.ListFormat
|
var list operations.ListFormat
|
||||||
list.AddPath()
|
list.AddPath()
|
||||||
list.SetDirSlash(false)
|
list.SetDirSlash(false)
|
||||||
assert.Equal(t, "subdir", operations.ListFormatted(&items[1], &list))
|
assert.Equal(t, "subdir", list.Format(items[1]))
|
||||||
|
|
||||||
list.SetDirSlash(true)
|
list.SetDirSlash(true)
|
||||||
assert.Equal(t, "subdir/", operations.ListFormatted(&items[1], &list))
|
assert.Equal(t, "subdir/", list.Format(items[1]))
|
||||||
|
|
||||||
list.SetOutput(nil)
|
list.SetOutput(nil)
|
||||||
assert.Equal(t, "", operations.ListFormatted(&items[1], &list))
|
assert.Equal(t, "", list.Format(items[1]))
|
||||||
|
|
||||||
list.AppendOutput(func() string { return "a" })
|
list.AppendOutput(func() string { return "a" })
|
||||||
list.AppendOutput(func() string { return "b" })
|
list.AppendOutput(func() string { return "b" })
|
||||||
assert.Equal(t, "ab", operations.ListFormatted(&items[1], &list))
|
assert.Equal(t, "ab", list.Format(items[1]))
|
||||||
list.SetSeparator(":::")
|
list.SetSeparator(":::")
|
||||||
assert.Equal(t, "a:::b", operations.ListFormatted(&items[1], &list))
|
assert.Equal(t, "a:::b", list.Format(items[1]))
|
||||||
|
|
||||||
list.SetOutput(nil)
|
list.SetOutput(nil)
|
||||||
list.AddModTime()
|
list.AddModTime()
|
||||||
assert.Equal(t, items[0].ModTime().Local().Format("2006-01-02 15:04:05"), operations.ListFormatted(&items[0], &list))
|
assert.Equal(t, items[0].ModTime().Local().Format("2006-01-02 15:04:05"), list.Format(items[0]))
|
||||||
|
|
||||||
list.SetOutput(nil)
|
list.SetOutput(nil)
|
||||||
list.AddID()
|
list.AddID()
|
||||||
_ = operations.ListFormatted(&items[0], &list) // Can't really check anything - at least it didn't panic!
|
_ = list.Format(items[0]) // Can't really check anything - at least it didn't panic!
|
||||||
|
|
||||||
list.SetOutput(nil)
|
list.SetOutput(nil)
|
||||||
list.AddMimeType()
|
list.AddMimeType()
|
||||||
assert.Contains(t, operations.ListFormatted(&items[0], &list), "/")
|
assert.Contains(t, list.Format(items[0]), "/")
|
||||||
assert.Equal(t, "inode/directory", operations.ListFormatted(&items[1], &list))
|
assert.Equal(t, "inode/directory", list.Format(items[1]))
|
||||||
|
|
||||||
list.SetOutput(nil)
|
list.SetOutput(nil)
|
||||||
list.AddSize()
|
list.AddSize()
|
||||||
assert.Equal(t, "1", operations.ListFormatted(&items[0], &list))
|
assert.Equal(t, "1", list.Format(items[0]))
|
||||||
|
|
||||||
list.AddPath()
|
list.AddPath()
|
||||||
list.AddModTime()
|
list.AddModTime()
|
||||||
list.SetDirSlash(true)
|
list.SetDirSlash(true)
|
||||||
list.SetSeparator("__SEP__")
|
list.SetSeparator("__SEP__")
|
||||||
assert.Equal(t, "1__SEP__a__SEP__"+items[0].ModTime().Local().Format("2006-01-02 15:04:05"), operations.ListFormatted(&items[0], &list))
|
assert.Equal(t, "1__SEP__a__SEP__"+items[0].ModTime().Local().Format("2006-01-02 15:04:05"), list.Format(items[0]))
|
||||||
assert.Equal(t, fmt.Sprintf("%d", items[1].Size())+"__SEP__subdir/__SEP__"+items[1].ModTime().Local().Format("2006-01-02 15:04:05"), operations.ListFormatted(&items[1], &list))
|
assert.Equal(t, fmt.Sprintf("%d", items[1].Size())+"__SEP__subdir/__SEP__"+items[1].ModTime().Local().Format("2006-01-02 15:04:05"), list.Format(items[1]))
|
||||||
|
|
||||||
for _, test := range []struct {
|
for _, test := range []struct {
|
||||||
ht hash.Type
|
ht hash.Type
|
||||||
|
@ -742,7 +742,7 @@ func TestListFormat(t *testing.T) {
|
||||||
} {
|
} {
|
||||||
list.SetOutput(nil)
|
list.SetOutput(nil)
|
||||||
list.AddHash(test.ht)
|
list.AddHash(test.ht)
|
||||||
got := operations.ListFormatted(&items[0], &list)
|
got := list.Format(items[0])
|
||||||
if got != "UNSUPPORTED" && got != "" {
|
if got != "UNSUPPORTED" && got != "" {
|
||||||
assert.Equal(t, test.want, got)
|
assert.Equal(t, test.want, got)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue