Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/duplicati/duplicati.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Skovhede <kenneth@hexad.dk>2017-04-04 17:56:34 +0300
committerKenneth Skovhede <kenneth@hexad.dk>2017-04-04 17:57:30 +0300
commit6855824285d1b8aa23e1da2ff74729a5a3c02410 (patch)
tree07c97e42a58d55bdb5f9189cffd1f56dd2879716 /Duplicati/CommandLine/Commands.cs
parent8e9acddab86a2216dd3501c86c49770ee73ec277 (diff)
Rewrote the commandline to support plug-able output
Diffstat (limited to 'Duplicati/CommandLine/Commands.cs')
-rw-r--r--Duplicati/CommandLine/Commands.cs353
1 files changed, 196 insertions, 157 deletions
diff --git a/Duplicati/CommandLine/Commands.cs b/Duplicati/CommandLine/Commands.cs
index 25aa20776..f40152432 100644
--- a/Duplicati/CommandLine/Commands.cs
+++ b/Duplicati/CommandLine/Commands.cs
@@ -18,6 +18,7 @@
using System;
using System.Linq;
using System.Collections.Generic;
+using System.IO;
namespace Duplicati.CommandLine
{
@@ -124,30 +125,30 @@ namespace Duplicati.CommandLine
}
}
- public static int Examples(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
+ public static int Examples(TextWriter outwriter, Action<Duplicati.Library.Main.Controller> setup, List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
{
- Duplicati.CommandLine.Help.PrintUsage("example", options);
+ Duplicati.CommandLine.Help.PrintUsage(outwriter, "example", options);
return 0;
}
- public static int Help(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
+ public static int Help(TextWriter outwriter, Action<Duplicati.Library.Main.Controller> setup, List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
{
if (args.Count < 1)
- Duplicati.CommandLine.Help.PrintUsage("help", options);
+ Duplicati.CommandLine.Help.PrintUsage(outwriter, "help", options);
else
- Duplicati.CommandLine.Help.PrintUsage(args[0], options);
+ Duplicati.CommandLine.Help.PrintUsage(outwriter, args[0], options);
return 0;
}
- public static int Affected(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
+ public static int Affected(TextWriter outwriter, Action<Duplicati.Library.Main.Controller> setup, List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
{
var backend = args[0];
args.RemoveAt(0);
if (args.Count == 0)
{
- Console.WriteLine("You must specify at least a remote filename");
+ outwriter.WriteLine("You must specify at least a remote filename");
return 200;
}
@@ -170,16 +171,17 @@ namespace Duplicati.CommandLine
options["no-encryption"] = "true";
}
- using(var i = new Library.Main.Controller(backend, options, new ConsoleOutput(options)))
+ using(var i = new Library.Main.Controller(backend, options, new ConsoleOutput(outwriter, options)))
{
+ setup(i);
var res = i.ListAffected(args);
if (res.Filesets != null && res.Filesets.Count() != 0)
{
- Console.WriteLine("The following filesets are affected:");
+ outwriter.WriteLine("The following filesets are affected:");
foreach(var e in res.Filesets)
- Console.WriteLine("{0}\t: {1}", e.Version, e.Time);
- Console.WriteLine();
+ outwriter.WriteLine("{0}\t: {1}", e.Version, e.Time);
+ outwriter.WriteLine();
}
if (res.RemoteVolumes != null && res.RemoteVolumes.Count() != 0)
@@ -189,42 +191,43 @@ namespace Duplicati.CommandLine
var filecount = res.Files.Count();
if (filecount == 0 || (filecount > 10 && !Duplicati.Library.Utility.Utility.ParseBoolOption(options, "verbose")))
- Console.WriteLine("A total of {0} file(s) are affected (use --{1} to see filenames)", res.Files.Count(), "verbose");
+ outwriter.WriteLine("A total of {0} file(s) are affected (use --{1} to see filenames)", res.Files.Count(), "verbose");
else
{
- Console.WriteLine("The following files are affected:");
+ outwriter.WriteLine("The following files are affected:");
foreach(var file in res.Files)
- Console.WriteLine(file.Path);
+ outwriter.WriteLine(file.Path);
}
- Console.WriteLine();
+ outwriter.WriteLine();
var logcount = res.LogMessages.Count();
if (logcount == 0 || (logcount > 10 && !Duplicati.Library.Utility.Utility.ParseBoolOption(options, "verbose")))
- Console.WriteLine("Found {0} related log messages (use --{1} to see the data)", res.Files.Count(), "verbose");
+ outwriter.WriteLine("Found {0} related log messages (use --{1} to see the data)", res.Files.Count(), "verbose");
else
{
- Console.WriteLine("The following related log messages were found:");
+ outwriter.WriteLine("The following related log messages were found:");
foreach(var log in res.LogMessages)
if (log.Message.Length > 100 && !Duplicati.Library.Utility.Utility.ParseBoolOption(options, "verbose"))
- Console.WriteLine("{0}: {1}", log.Timestamp, log.Message.Substring(0, 96) + " ...");
+ outwriter.WriteLine("{0}: {1}", log.Timestamp, log.Message.Substring(0, 96) + " ...");
else
- Console.WriteLine("{0}: {1}", log.Timestamp, log.Message);
+ outwriter.WriteLine("{0}: {1}", log.Timestamp, log.Message);
}
- Console.WriteLine();
+ outwriter.WriteLine();
return 0;
}
}
- public static int List(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
+ public static int List(TextWriter outwriter, Action<Duplicati.Library.Main.Controller> setup, List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
{
filter = filter ?? new Duplicati.Library.Utility.FilterExpression();
if (Duplicati.Library.Utility.Utility.ParseBoolOption(options, "list-sets-only"))
filter = new Duplicati.Library.Utility.FilterExpression();
- using(var i = new Library.Main.Controller(args[0], options, new ConsoleOutput(options)))
+ using(var i = new Library.Main.Controller(args[0], options, new ConsoleOutput(outwriter, options)))
{
+ setup(i);
var backend = args[0];
args.RemoveAt(0);
@@ -302,7 +305,7 @@ namespace Duplicati.CommandLine
if (isRequestForFiles && !Library.Utility.Utility.ParseBoolOption(options, "all-versions"))
{
- Console.WriteLine("No files matching, looking in all versions");
+ outwriter.WriteLine("No files matching, looking in all versions");
options["all-versions"] = "true";
options.Remove("time");
options.Remove("version");
@@ -311,47 +314,47 @@ namespace Duplicati.CommandLine
if (res.Filesets.Count() != 0 && (res.Files == null || res.Files.Count() == 0) && compareFilter.Empty)
{
- Console.WriteLine("Listing filesets:");
+ outwriter.WriteLine("Listing filesets:");
foreach(var e in res.Filesets)
{
if (e.FileCount >= 0)
- Console.WriteLine("{0}\t: {1} ({2} files, {3})", e.Version, e.Time, e.FileCount, Library.Utility.Utility.FormatSizeString(e.FileSizes));
+ outwriter.WriteLine("{0}\t: {1} ({2} files, {3})", e.Version, e.Time, e.FileCount, Library.Utility.Utility.FormatSizeString(e.FileSizes));
else
- Console.WriteLine("{0}\t: {1}", e.Version, e.Time);
+ outwriter.WriteLine("{0}\t: {1}", e.Version, e.Time);
}
}
else if (isRequestForFiles)
{
- Console.WriteLine("No files matched expression");
+ outwriter.WriteLine("No files matched expression");
}
else
{
if (res.Filesets.Count() == 0)
{
- Console.WriteLine("No time or version matched a fileset");
+ outwriter.WriteLine("No time or version matched a fileset");
}
else if (res.Files == null || res.Files.Count() == 0)
{
- Console.WriteLine("Found {0} filesets, but no files matched", res.Filesets.Count());
+ outwriter.WriteLine("Found {0} filesets, but no files matched", res.Filesets.Count());
}
else if (res.Filesets.Count() == 1)
{
var f = res.Filesets.First();
- Console.WriteLine("Listing contents {0} ({1}):", f.Version, f.Time);
+ outwriter.WriteLine("Listing contents {0} ({1}):", f.Version, f.Time);
foreach(var e in res.Files)
- Console.WriteLine("{0} {1}", e.Path, e.Path.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()) ? "" : "(" + Library.Utility.Utility.FormatSizeString(e.Sizes.First()) + ")");
+ outwriter.WriteLine("{0} {1}", e.Path, e.Path.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()) ? "" : "(" + Library.Utility.Utility.FormatSizeString(e.Sizes.First()) + ")");
}
else
{
- Console.WriteLine("Listing files and versions:");
+ outwriter.WriteLine("Listing files and versions:");
foreach(var e in res.Files)
{
- Console.WriteLine(e.Path);
+ outwriter.WriteLine(e.Path);
foreach(var nx in res.Filesets.Zip(e.Sizes, (a, b) => new { Index = a.Version, Time = a.Time, Size = b } ))
- Console.WriteLine("{0}\t: {1} {2}", nx.Index, nx.Time, nx.Size < 0 ? " - " : Library.Utility.Utility.FormatSizeString(nx.Size));
+ outwriter.WriteLine("{0}\t: {1} {2}", nx.Index, nx.Time, nx.Size < 0 ? " - " : Library.Utility.Utility.FormatSizeString(nx.Size));
- Console.WriteLine();
+ outwriter.WriteLine();
}
}
@@ -361,34 +364,35 @@ namespace Duplicati.CommandLine
return 0;
}
- public static int Delete(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
+ public static int Delete(TextWriter outwriter, Action<Duplicati.Library.Main.Controller> setup, List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
{
var requiredOptions = new string[] { "keep-time", "keep-versions", "version" };
if (!options.Keys.Where(x => requiredOptions.Contains(x, StringComparer.InvariantCultureIgnoreCase)).Any())
{
- Console.WriteLine(Strings.Program.DeleteCommandNeedsOptions("delete", requiredOptions));
+ outwriter.WriteLine(Strings.Program.DeleteCommandNeedsOptions("delete", requiredOptions));
return 200;
}
- using(var i = new Library.Main.Controller(args[0], options, new ConsoleOutput(options)))
+ using(var i = new Library.Main.Controller(args[0], options, new ConsoleOutput(outwriter, options)))
{
+ setup(i);
args.RemoveAt(0);
var res = i.Delete();
if (res.DeletedSets.Count() == 0)
{
- Console.WriteLine(Strings.Program.NoFilesetsMatching);
+ outwriter.WriteLine(Strings.Program.NoFilesetsMatching);
}
else
{
if (res.Dryrun)
- Console.WriteLine(Strings.Program.WouldDeleteBackups);
+ outwriter.WriteLine(Strings.Program.WouldDeleteBackups);
else
- Console.WriteLine(Strings.Program.DeletedBackups);
+ outwriter.WriteLine(Strings.Program.DeletedBackups);
foreach(var f in res.DeletedSets)
- Console.WriteLine(string.Format("{0}: {1}", f.Item1, f.Item2));
+ outwriter.WriteLine(string.Format("{0}: {1}", f.Item1, f.Item2));
}
}
@@ -396,21 +400,24 @@ namespace Duplicati.CommandLine
}
- public static int Repair(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
+ public static int Repair(TextWriter outwriter, Action<Duplicati.Library.Main.Controller> setup, List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
{
if (args.Count != 1)
- return PrintWrongNumberOfArguments(args, 1);
+ return PrintWrongNumberOfArguments(outwriter, args, 1);
- using(var i = new Duplicati.Library.Main.Controller(args[0], options, new ConsoleOutput(options)))
+ using (var i = new Duplicati.Library.Main.Controller(args[0], options, new ConsoleOutput(outwriter, options)))
+ {
+ setup(i);
i.Repair(filter);
+ }
return 0;
}
- public static int Restore(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
+ public static int Restore(TextWriter outwriter, Action<Duplicati.Library.Main.Controller> setup, List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
{
if (args.Count < 1)
- return PrintWrongNumberOfArguments(args, 1);
+ return PrintWrongNumberOfArguments(outwriter, args, 1);
string backend = args[0];
args.RemoveAt(0);
@@ -428,29 +435,32 @@ namespace Duplicati.CommandLine
if (args[ix].IndexOfAny(new char[] { '*', '?' }) < 0 && !args[ix].StartsWith("[") && args[ix].EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
args[ix] += "*";
- var output = new ConsoleOutput(options);
+ var output = new ConsoleOutput(outwriter, options);
output.MessageEvent(string.Format("Restore started at {0}", DateTime.Now));
- using(var i = new Library.Main.Controller(backend, options, output))
+ using (var i = new Library.Main.Controller(backend, options, output))
+ {
+ setup(i);
if (controlFiles)
{
var res = i.RestoreControlFiles(args.ToArray(), filter);
output.MessageEvent("Restore control files completed:");
- foreach(var s in res.Files)
- Console.WriteLine(s);
+ foreach (var s in res.Files)
+ outwriter.WriteLine(s);
}
else
{
- using(var periodicOutput = new PeriodicOutput(output, TimeSpan.FromSeconds(5)))
+ using (var periodicOutput = new PeriodicOutput(output, TimeSpan.FromSeconds(5)))
{
- output.PhaseChanged += (phase, previousPhase) => {
+ output.PhaseChanged += (phase, previousPhase) =>
+ {
if (phase == Duplicati.Library.Main.OperationPhase.Restore_PreRestoreVerify)
output.MessageEvent("Checking remote backup ...");
else if (phase == Duplicati.Library.Main.OperationPhase.Restore_ScanForExistingFiles)
output.MessageEvent("Checking existing target files ...");
- /*else if (phase == Duplicati.Library.Main.OperationPhase.Restore_DownloadingRemoteFiles)
- output.MessageEvent("Downloading remote files ..."); */
- else if (phase == Duplicati.Library.Main.OperationPhase.Restore_PatchWithLocalBlocks)
+ /*else if (phase == Duplicati.Library.Main.OperationPhase.Restore_DownloadingRemoteFiles)
+ output.MessageEvent("Downloading remote files ..."); */
+ else if (phase == Duplicati.Library.Main.OperationPhase.Restore_PatchWithLocalBlocks)
output.MessageEvent("Updating target files with local data ...");
else if (phase == Duplicati.Library.Main.OperationPhase.Restore_PostRestoreVerify)
{
@@ -463,18 +473,19 @@ namespace Duplicati.CommandLine
else if (phase == Duplicati.Library.Main.OperationPhase.Restore_CreateTargetFolders)
periodicOutput.SetReady();
};
-
- periodicOutput.WriteOutput += (progress, files, size, counting) => {
+
+ periodicOutput.WriteOutput += (progress, files, size, counting) =>
+ {
output.MessageEvent(string.Format(" {0} files need to be restored ({1})", files, Library.Utility.Utility.FormatSizeString(size)));
};
-
+
var res = i.Restore(args.ToArray(), filter);
string restorePath;
options.TryGetValue("restore-path", out restorePath);
-
+
output.MessageEvent(string.Format("Restored {0} ({1}) files to {2}", res.FilesRestored, Library.Utility.Utility.FormatSizeString(res.SizeOfRestoredFiles), string.IsNullOrEmpty(restorePath) ? "original path" : restorePath));
output.MessageEvent(string.Format("Duration of restore: {0:hh\\:mm\\:ss}", res.Duration));
-
+
if (res.FilesRestored > 0 && !Library.Main.Utility.SuppressDonationMessages)
{
output.MessageEvent("***********************************************");
@@ -484,27 +495,28 @@ namespace Duplicati.CommandLine
output.MessageEvent("Bitcoin: 1L74qa1n5SFKwwyHhECTHBJgcf6WT2rJKf");
output.MessageEvent("***********************************************");
}
-
+
if (output.VerboseOutput)
- Library.Utility.Utility.PrintSerializeObject(res, Console.Out);
+ Library.Utility.Utility.PrintSerializeObject(res, outwriter);
if (res.Warnings.Count() > 0)
return 2;
}
}
+ }
return 0;
}
- public static int Backup(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
+ public static int Backup(TextWriter outwriter, Action<Duplicati.Library.Main.Controller> setup, List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
{
if (args.Count < 2)
- return PrintWrongNumberOfArguments(args, 2);
+ return PrintWrongNumberOfArguments(outwriter, args, 2);
var backend = args[0];
args.RemoveAt(0);
var dirs = args.ToArray();
- var output = new ConsoleOutput(options);
+ var output = new ConsoleOutput(outwriter, options);
Library.Interface.IBackupResults result;
@@ -537,14 +549,17 @@ namespace Duplicati.CommandLine
periodicOutput.WriteOutput += (progress, files, size, counting) => {
output.MessageEvent(string.Format(" {0} files need to be examined ({1}){2}", files, Library.Utility.Utility.FormatSizeString(size), counting ? " (still counting)" : ""));
};
-
- using(var i = new Library.Main.Controller(backend, options, output))
+
+ using (var i = new Library.Main.Controller(backend, options, output))
+ {
+ setup(i);
result = i.Backup(dirs, filter);
+ }
}
if (output.VerboseOutput)
{
- Library.Utility.Utility.PrintSerializeObject(result, Console.Out);
+ Library.Utility.Utility.PrintSerializeObject(result, outwriter);
}
else
{
@@ -588,21 +603,24 @@ namespace Duplicati.CommandLine
return 0;
}
- public static int Compact(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
+ public static int Compact(TextWriter outwriter, Action<Duplicati.Library.Main.Controller> setup, List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
{
if (args.Count != 1)
- return PrintWrongNumberOfArguments(args, 1);
-
- using(var i = new Library.Main.Controller(args[0], options, new ConsoleOutput(options)))
+ return PrintWrongNumberOfArguments(outwriter, args, 1);
+
+ using (var i = new Library.Main.Controller(args[0], options, new ConsoleOutput(outwriter, options)))
+ {
+ setup(i);
i.Compact();
+ }
return 0;
}
- public static int Test(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
+ public static int Test(TextWriter outwriter, Action<Duplicati.Library.Main.Controller> setup, List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
{
if (args.Count != 1 && args.Count != 2)
- return PrintWrongNumberOfArguments(args, 1);
+ return PrintWrongNumberOfArguments(outwriter, args, 1);
var tests = 1L;
if (args.Count == 2)
@@ -614,13 +632,16 @@ namespace Duplicati.CommandLine
}
Library.Interface.ITestResults result;
- using(var i = new Library.Main.Controller(args[0], options, new ConsoleOutput(options)))
+ using (var i = new Library.Main.Controller(args[0], options, new ConsoleOutput(outwriter, options)))
+ {
+ setup(i);
result = i.Test(tests);
+ }
var totalFiles = result.Verifications.Count();
if (totalFiles == 0)
{
- Console.WriteLine("No files examined, is the remote destination is empty?");
+ outwriter.WriteLine("No files examined, is the remote destination is empty?");
return 100;
}
else
@@ -628,7 +649,7 @@ namespace Duplicati.CommandLine
var filtered = from n in result.Verifications where n.Value.Count() != 0 select n;
if (filtered.Count() == 0)
{
- Console.WriteLine("Examined {0} files and found no errors", totalFiles);
+ outwriter.WriteLine("Examined {0} files and found no errors", totalFiles);
return 0;
}
else
@@ -639,22 +660,22 @@ namespace Duplicati.CommandLine
{
var changecount = n.Value.Count();
if (changecount == 0)
- Console.WriteLine("{0}: No errors", n.Key);
+ outwriter.WriteLine("{0}: No errors", n.Key);
else
{
- Console.WriteLine("{0}: {1} errors", n.Key, changecount);
+ outwriter.WriteLine("{0}: {1} errors", n.Key, changecount);
foreach(var c in n.Value)
- Console.WriteLine("{0}: {1}", c.Key, c.Value);
- Console.WriteLine();
+ outwriter.WriteLine("{0}: {1}", c.Key, c.Value);
+ outwriter.WriteLine();
}
}
}
else
{
- Console.WriteLine("Examined {0} files and found errors in the following files:", totalFiles);
+ outwriter.WriteLine("Examined {0} files and found errors in the following files:", totalFiles);
foreach(var n in filtered)
- Console.WriteLine(n.Key);
- Console.WriteLine();
+ outwriter.WriteLine(n.Key);
+ outwriter.WriteLine();
}
return 3;
@@ -662,19 +683,19 @@ namespace Duplicati.CommandLine
}
}
- private static int PrintWrongNumberOfArguments(List<string> args, int expected)
+ private static int PrintWrongNumberOfArguments(TextWriter outwriter, List<string> args, int expected)
{
- Console.WriteLine(Strings.Program.WrongNumberOfCommandsError_v2(args.Count, expected, args.Select(n => "\"" + n + "\"").ToArray()));
+ outwriter.WriteLine(Strings.Program.WrongNumberOfCommandsError_v2(args.Count, expected, args.Select(n => "\"" + n + "\"").ToArray()));
return 200;
}
- public static int PrintInvalidCommand(string command, List<string> args)
+ public static int PrintInvalidCommand(TextWriter outwriter, string command, List<string> args)
{
- Console.WriteLine(Strings.Program.InvalidCommandError(command));
+ outwriter.WriteLine(Strings.Program.InvalidCommandError(command));
return 200;
}
- public static int CreateBugReport(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
+ public static int CreateBugReport(TextWriter outwriter, Action<Duplicati.Library.Main.Controller> setup, List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
{
// Support for not adding the --auth-username if possible
string dbpath = null;
@@ -686,7 +707,7 @@ namespace Duplicati.CommandLine
if (dbpath == null)
{
- Console.WriteLine("No local database found, please add --{0}", "dbpath");
+ outwriter.WriteLine("No local database found, please add --{0}", "dbpath");
return 100;
}
else
@@ -698,24 +719,27 @@ namespace Duplicati.CommandLine
args = new List<string>(new string[] { "file://unused", "report" });
else if (args.Count == 1)
args.Add("report");
-
- using(var i = new Library.Main.Controller(args[0], options, new ConsoleOutput(options)))
+
+ using (var i = new Library.Main.Controller(args[0], options, new ConsoleOutput(outwriter, options)))
+ {
+ setup(i);
i.CreateLogDatabase(args[1]);
+ }
- Console.WriteLine("Completed!");
- Console.WriteLine();
- Console.WriteLine("Please examine the log table of the database to see that no filenames are accidentially left over.");
- Console.WriteLine("If you are concerned that your filenames may contain sensitive information,");
- Console.WriteLine(" do not attach the database to an issue!!!");
- Console.WriteLine();
+ outwriter.WriteLine("Completed!");
+ outwriter.WriteLine();
+ outwriter.WriteLine("Please examine the log table of the database to see that no filenames are accidentially left over.");
+ outwriter.WriteLine("If you are concerned that your filenames may contain sensitive information,");
+ outwriter.WriteLine(" do not attach the database to an issue!!!");
+ outwriter.WriteLine();
return 0;
}
- public static int ListChanges(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
+ public static int ListChanges(TextWriter outwriter, Action<Duplicati.Library.Main.Controller> setup, List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
{
if (args.Count < 1)
- return PrintWrongNumberOfArguments(args, 1);
+ return PrintWrongNumberOfArguments(outwriter, args, 1);
// Support for not adding the --auth-username if possible
string dbpath;
@@ -737,22 +761,25 @@ namespace Duplicati.CommandLine
}
Library.Interface.IListChangesResults result;
- using(var i = new Library.Main.Controller(args[0], options, new ConsoleOutput(options)))
+ using (var i = new Library.Main.Controller(args[0], options, new ConsoleOutput(outwriter, options)))
+ {
+ setup(i);
if (args.Count == 2)
result = i.ListChanges(null, args[1], null, filter);
- else
+ else
result = i.ListChanges(args.Count > 1 ? args[1] : null, args.Count > 2 ? args[2] : null, null, filter);
+ }
- Console.WriteLine("Listing changes");
- Console.WriteLine(" {0}: {1}", result.BaseVersionIndex, result.BaseVersionTimestamp);
- Console.WriteLine(" {0}: {1}", result.CompareVersionIndex, result.CompareVersionTimestamp);
- Console.WriteLine();
+ outwriter.WriteLine("Listing changes");
+ outwriter.WriteLine(" {0}: {1}", result.BaseVersionIndex, result.BaseVersionTimestamp);
+ outwriter.WriteLine(" {0}: {1}", result.CompareVersionIndex, result.CompareVersionTimestamp);
+ outwriter.WriteLine();
- Console.WriteLine("Size of backup {0}: {1}", result.BaseVersionIndex, Library.Utility.Utility.FormatSizeString(result.PreviousSize));
+ outwriter.WriteLine("Size of backup {0}: {1}", result.BaseVersionIndex, Library.Utility.Utility.FormatSizeString(result.PreviousSize));
if (result.ChangeDetails != null)
{
- Console.WriteLine();
+ outwriter.WriteLine();
var added = result.ChangeDetails.Where(x => x.Item1 == Library.Interface.ListChangesChangeType.Added);
var deleted = result.ChangeDetails.Where(x => x.Item1 == Library.Interface.ListChangesChangeType.Deleted);
@@ -761,104 +788,108 @@ namespace Duplicati.CommandLine
var count = added.Count();
if (count > 0)
{
- Console.WriteLine(" {0} added entries:", count);
+ outwriter.WriteLine(" {0} added entries:", count);
foreach(var n in added)
- Console.WriteLine(" + {0}", n.Item3);
- Console.WriteLine();
+ outwriter.WriteLine(" + {0}", n.Item3);
+ outwriter.WriteLine();
}
count = modified.Count();
if (count > 0)
{
- Console.WriteLine(" {0} modified entries:", count);
+ outwriter.WriteLine(" {0} modified entries:", count);
foreach(var n in modified)
- Console.WriteLine(" ~ {0}", n.Item3);
- Console.WriteLine();
+ outwriter.WriteLine(" ~ {0}", n.Item3);
+ outwriter.WriteLine();
}
count = deleted.Count();
if (count > 0)
{
- Console.WriteLine("{0} deleted entries:", count);
+ outwriter.WriteLine("{0} deleted entries:", count);
foreach(var n in deleted)
- Console.WriteLine(" - {0}", n.Item3);
- Console.WriteLine();
+ outwriter.WriteLine(" - {0}", n.Item3);
+ outwriter.WriteLine();
}
- Console.WriteLine();
+ outwriter.WriteLine();
}
else
{
if (result.AddedFolders > 0)
- Console.WriteLine(" Added folders: {0}", result.AddedFolders);
+ outwriter.WriteLine(" Added folders: {0}", result.AddedFolders);
if (result.AddedSymlinks > 0)
- Console.WriteLine(" Added symlinks: {0}", result.AddedSymlinks);
+ outwriter.WriteLine(" Added symlinks: {0}", result.AddedSymlinks);
if (result.AddedFiles > 0)
- Console.WriteLine(" Added files: {0}", result.AddedFiles);
+ outwriter.WriteLine(" Added files: {0}", result.AddedFiles);
if (result.DeletedFolders > 0)
- Console.WriteLine(" Deleted folders: {0}", result.DeletedFolders);
+ outwriter.WriteLine(" Deleted folders: {0}", result.DeletedFolders);
if (result.DeletedSymlinks > 0)
- Console.WriteLine(" Deleted symlinks: {0}", result.DeletedSymlinks);
+ outwriter.WriteLine(" Deleted symlinks: {0}", result.DeletedSymlinks);
if (result.DeletedFiles > 0)
- Console.WriteLine(" Deleted files: {0}", result.DeletedFiles);
+ outwriter.WriteLine(" Deleted files: {0}", result.DeletedFiles);
if (result.ModifiedFolders > 0)
- Console.WriteLine(" Modified folders: {0}", result.ModifiedFolders);
+ outwriter.WriteLine(" Modified folders: {0}", result.ModifiedFolders);
if (result.ModifiedSymlinks > 0)
- Console.WriteLine(" Modified symlinka: {0}", result.ModifiedSymlinks);
+ outwriter.WriteLine(" Modified symlinka: {0}", result.ModifiedSymlinks);
if (result.ModifiedFiles > 0)
- Console.WriteLine(" Modified files: {0}", result.ModifiedFiles);
+ outwriter.WriteLine(" Modified files: {0}", result.ModifiedFiles);
if (result.AddedFolders + result.AddedSymlinks + result.AddedFolders +
result.ModifiedFolders + result.ModifiedSymlinks + result.ModifiedFiles +
result.DeletedFolders + result.DeletedSymlinks + result.DeletedFiles == 0)
- Console.WriteLine(" No changes found");
+ outwriter.WriteLine(" No changes found");
}
- Console.WriteLine("Size of backup {0}: {1}", result.CompareVersionIndex, Library.Utility.Utility.FormatSizeString(result.CurrentSize));
+ outwriter.WriteLine("Size of backup {0}: {1}", result.CompareVersionIndex, Library.Utility.Utility.FormatSizeString(result.CurrentSize));
return 0;
}
- public static int TestFilters(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
+ public static int TestFilters(TextWriter outwriter, Action<Duplicati.Library.Main.Controller> setup, List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
{
if (args == null || args.Count < 1)
{
- Console.WriteLine("No source paths given");
+ outwriter.WriteLine("No source paths given");
return 200;
}
options["verbose"] = "true";
- using(var i = new Library.Main.Controller("dummy://", options, new ConsoleOutput(options)))
+ using(var i = new Library.Main.Controller("dummy://", options, new ConsoleOutput(outwriter, options)))
{
+ setup(i);
var result = i.TestFilter(args.ToArray(), filter);
- Console.WriteLine("Matched {0} files ({1})", result.FileCount, Duplicati.Library.Utility.Utility.FormatSizeString(result.FileSize));
+ outwriter.WriteLine("Matched {0} files ({1})", result.FileCount, Duplicati.Library.Utility.Utility.FormatSizeString(result.FileSize));
}
return 0;
}
- public static int SystemInfo(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
+ public static int SystemInfo(TextWriter outwriter, Action<Duplicati.Library.Main.Controller> setup, List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
{
if (args != null && args.Count != 0)
{
- Console.WriteLine("Command takes no arguments");
+ outwriter.WriteLine("Command takes no arguments");
return 200;
}
- using(var i = new Library.Main.Controller("dummy://", options, new ConsoleOutput(options)))
- foreach(var line in i.SystemInfo().Lines)
- Console.WriteLine(line);
+ using (var i = new Library.Main.Controller("dummy://", options, new ConsoleOutput(outwriter, options)))
+ {
+ setup(i);
+ foreach (var line in i.SystemInfo().Lines)
+ outwriter.WriteLine(line);
+ }
- Console.WriteLine("Know locales: {0}", string.Join(", ", Library.Localization.LocalizationService.AllLocales));
- Console.WriteLine("Translated locales: {0}", string.Join(", ", Library.Localization.LocalizationService.SupportedCultures));
+ outwriter.WriteLine("Know locales: {0}", string.Join(", ", Library.Localization.LocalizationService.AllLocales));
+ outwriter.WriteLine("Translated locales: {0}", string.Join(", ", Library.Localization.LocalizationService.SupportedCultures));
return 0;
}
- public static int PurgeFiles(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
+ public static int PurgeFiles(TextWriter outwriter, Action<Duplicati.Library.Main.Controller> setup, List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
{
if (args.Count < 1)
- return PrintWrongNumberOfArguments(args, 1);
+ return PrintWrongNumberOfArguments(outwriter, args, 1);
var backend = args[0];
var paths = args.Skip(1).ToArray();
@@ -869,35 +900,40 @@ namespace Duplicati.CommandLine
filter = new Library.Utility.FilterExpression(paths);
else
{
- Console.WriteLine("You cannot combine filters and paths on the commandline");
+ outwriter.WriteLine("You cannot combine filters and paths on the commandline");
return 200;
}
}
else if (filter == null || filter.Empty)
{
- Console.WriteLine("You must provide either filename filters, or a list of paths to remove");
+ outwriter.WriteLine("You must provide either filename filters, or a list of paths to remove");
return 200;
}
- using (var i = new Library.Main.Controller(args[0], options, new ConsoleOutput(options)))
+ using (var i = new Library.Main.Controller(args[0], options, new ConsoleOutput(outwriter, options)))
+ {
+ setup(i);
i.PurgeFiles(filter);
+ }
return 0;
}
- public static int ListBrokenFiles(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
+ public static int ListBrokenFiles(TextWriter outwriter, Action<Duplicati.Library.Main.Controller> setup, List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
{
if (args.Count != 1)
- return PrintWrongNumberOfArguments(args, 1);
+ return PrintWrongNumberOfArguments(outwriter, args, 1);
- var con = new ConsoleOutput(options);
+ var con = new ConsoleOutput(outwriter, options);
var previd = -1L;
var outputcount = 0L;
var verbose = Duplicati.Library.Utility.Utility.ParseBoolOption(options, "verbose");
using (var i = new Library.Main.Controller(args[0], options, con))
- i.ListBrokenFiles(filter, (id, time, count, path, size) =>
+ {
+ setup(i);
+ i.ListBrokenFiles(filter, (id, time, count, path, size) =>
{
if (previd != id)
{
@@ -917,35 +953,38 @@ namespace Duplicati.CommandLine
return true;
});
+ }
return 0;
}
- public static int PurgeBrokenFiles(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
+ public static int PurgeBrokenFiles(TextWriter outwriter, Action<Duplicati.Library.Main.Controller> setup, List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
{
if (args.Count != 1)
- return PrintWrongNumberOfArguments(args, 1);
+ return PrintWrongNumberOfArguments(outwriter, args, 1);
- using (var i = new Library.Main.Controller(args[0], options, new ConsoleOutput(options)))
+ using (var i = new Library.Main.Controller(args[0], options, new ConsoleOutput(outwriter, options)))
{
+ setup(i);
var res = i.PurgeBrokenFiles(filter);
}
return 0;
}
- public static int SendMail(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
+ public static int SendMail(TextWriter outwriter, Action<Duplicati.Library.Main.Controller> setup, List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
{
if (args != null && args.Count != 0)
{
- Console.WriteLine("Command takes no arguments");
+ outwriter.WriteLine("Command takes no arguments");
return 200;
}
- using (var i = new Library.Main.Controller("dummy://", options, new ConsoleOutput(options)))
+ using (var i = new Library.Main.Controller("dummy://", options, new ConsoleOutput(outwriter, options)))
{
+ setup(i);
foreach (var l in i.SendMail().Lines)
- Console.WriteLine(l);
+ outwriter.WriteLine(l);
}
return 0;