Simplify show help.

This commit is contained in:
verhoek
2019-02-25 11:35:43 +01:00
parent 9e498a2548
commit baad3e2c95
+30 -28
View File
@@ -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<string, string> commandlineOptions)
{
var dbPassword = Environment.GetEnvironmentVariable(DB_KEY_ENV_NAME);