From baad3e2c9598e31a802e5a5e3000e8b60b3fbce5 Mon Sep 17 00:00:00 2001 From: verhoek <30193551+verhoek@users.noreply.github.com> Date: Thu, 7 Feb 2019 21:41:58 +0100 Subject: [PATCH] Simplify show help. --- Duplicati/Server/Program.cs | 58 +++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/Duplicati/Server/Program.cs b/Duplicati/Server/Program.cs index e6044b53f..d5277ba4e 100644 --- a/Duplicati/Server/Program.cs +++ b/Duplicati/Server/Program.cs @@ -209,39 +209,26 @@ namespace Duplicati.Server Library.Utility.SystemContextSettings.StartSession(); - // Check if a parameters-file was provided. Skip if help was already specified - if (!commandlineOptions.ContainsKey("help")) - { - // try and parse all parameter file aliases - foreach (string parameterOption in new[] { "parameters-file", "parameters-file", "parameterfile" }) - { - if (commandlineOptions.ContainsKey(parameterOption) && !string.IsNullOrEmpty(commandlineOptions[parameterOption])) - { - string filename = commandlineOptions[parameterOption]; - commandlineOptions.Remove(parameterOption); - if (!ReadOptionsFromFile(filename, ref filter, args, commandlineOptions)) - return 100; - break; - } - } - } - //If the commandline issues --help, just stop here if (commandlineOptions.ContainsKey("help")) { - if (writeConsole) - { - Console.WriteLine(Strings.Program.HelpDisplayDialog); - - foreach(Library.Interface.ICommandLineArgument arg in SupportedCommands) - Console.WriteLine(Strings.Program.HelpDisplayFormat(arg.Name, arg.LongDescription)); - - return 0; - } - - throw new Exception("Server invoked with --help"); + return ShowHelp(writeConsole); } + // try and parse all parameter file aliases + foreach (string parameterOption in new[] { "parameters-file", "parameters-file", "parameterfile" }) + { + if (commandlineOptions.ContainsKey(parameterOption) && !string.IsNullOrEmpty(commandlineOptions[parameterOption])) + { + string filename = commandlineOptions[parameterOption]; + commandlineOptions.Remove(parameterOption); + if (!ReadOptionsFromFile(filename, ref filter, args, commandlineOptions)) + return 100; + break; + } + } + + #if DEBUG //Log various information in the logfile if (!commandlineOptions.ContainsKey("log-file")) @@ -494,6 +481,21 @@ namespace Duplicati.Server return 0; } + private static int ShowHelp(bool writeConsole) + { + if (writeConsole) + { + Console.WriteLine(Strings.Program.HelpDisplayDialog); + + foreach (Library.Interface.ICommandLineArgument arg in SupportedCommands) + Console.WriteLine(Strings.Program.HelpDisplayFormat(arg.Name, arg.LongDescription)); + + return 0; + } + + throw new Exception("Server invoked with --help"); + } + public static Database.Connection GetDatabaseConnection(Dictionary commandlineOptions) { var dbPassword = Environment.GetEnvironmentVariable(DB_KEY_ENV_NAME);