mirror of
https://github.com/rclone/rclone.git
synced 2025-12-11 22:14:05 +01:00
cat: adds --separator option to cat command
When using `rclone cat` to print the contents of several files, the user may want to inject some separator between the files, such as a comma or a newline. This patch adds a `--separator` option to the `cat` command to make that possible. The default value remains an empty string, `""`, maintaining the prior behavior of `rclone cat`. Closes #6968
This commit is contained in:
@@ -529,23 +529,25 @@ func TestCat(t *testing.T) {
|
||||
r.CheckRemoteItems(t, file1, file2)
|
||||
|
||||
for _, test := range []struct {
|
||||
offset int64
|
||||
count int64
|
||||
a string
|
||||
b string
|
||||
offset int64
|
||||
count int64
|
||||
separator string
|
||||
a string
|
||||
b string
|
||||
}{
|
||||
{0, -1, "ABCDEFGHIJ", "012345678"},
|
||||
{0, 5, "ABCDE", "01234"},
|
||||
{-3, -1, "HIJ", "678"},
|
||||
{1, 3, "BCD", "123"},
|
||||
{0, -1, "", "ABCDEFGHIJ", "012345678"},
|
||||
{0, 5, "", "ABCDE", "01234"},
|
||||
{-3, -1, "", "HIJ", "678"},
|
||||
{1, 3, "", "BCD", "123"},
|
||||
{0, -1, "\n", "ABCDEFGHIJ", "012345678"},
|
||||
} {
|
||||
var buf bytes.Buffer
|
||||
err := operations.Cat(ctx, r.Fremote, &buf, test.offset, test.count)
|
||||
err := operations.Cat(ctx, r.Fremote, &buf, test.offset, test.count, []byte(test.separator))
|
||||
require.NoError(t, err)
|
||||
res := buf.String()
|
||||
|
||||
if res != test.a+test.b && res != test.b+test.a {
|
||||
t.Errorf("Incorrect output from Cat(%d,%d): %q", test.offset, test.count, res)
|
||||
if res != test.a+test.separator+test.b+test.separator && res != test.b+test.separator+test.a+test.separator {
|
||||
t.Errorf("Incorrect output from Cat(%d,%d,%s): %q", test.offset, test.count, test.separator, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user