1
0
Fork 0
mirror of https://github.com/Jackett/Jackett synced 2024-12-23 16:27:44 +00:00

Invalid command line options now show errors

This commit is contained in:
KZ 2015-08-05 19:13:51 +01:00
parent ec6f361241
commit b72248ab3d
2 changed files with 40 additions and 13 deletions

View file

@ -33,8 +33,11 @@ namespace Jackett.Console
[Option('k', "Stop", HelpText = "Stop the Jacket Windows service (Must be admin)")]
public bool StopService { get; set; }
[Option('x', "ListenPublic", HelpText = "Listen publicly [true/false]")]
public bool? ListenPublic { get; set; }
[Option('x', "ListenPublic", HelpText = "Listen publicly")]
public bool ListenPublic { get; set; }
[Option('z', "ListenPrivate", HelpText = "Only allow local access")]
public bool ListenPrivate { get; set; }
[Option('h', "Help", HelpText = "Show Help")]
public bool ShowHelp { get; set; }
@ -48,7 +51,10 @@ namespace Jackett.Console
[Option('m', "MigrateSettings", HelpText = "Migrate settings manually (Must be admin on Windows)")]
public bool MigrateSettings { get; set; }
[Option('f', "SSLFix", HelpText = "Linux Libcurl NSS Missing ECC Ciphers workaround (Use if you can't access some trackers) [true/false].")]
[Option('f', "SSLFix", HelpText = "[true/false] Linux Libcurl NSS Missing ECC Ciphers workaround (Use if you can't access some trackers) .")]
public bool? SSLFix { get; set; }
[ParserState]
public IParserState LastParserState { get; set; }
}
}

View file

@ -26,22 +26,43 @@ namespace JackettConsole
var options = new ConsoleOptions();
if (!Parser.Default.ParseArguments(args, options) || options.ShowHelp == true)
{
var text = HelpText.AutoBuild(options, (HelpText current) => HelpText.DefaultParsingErrorsHandler(options, current));
text.Copyright = " ";
text.Heading = "Jackett v" + Engine.ConfigService.GetVersion() + " options:";
Console.WriteLine(text);
Environment.ExitCode = 1;
return;
if (options.LastParserState != null && options.LastParserState.Errors.Count > 0)
{
var help = new HelpText();
var errors = help.RenderParsingErrorsText(options, 2); // indent with two spaces
Console.WriteLine("Jackett v" + Engine.ConfigService.GetVersion());
Console.WriteLine("Switch error: " + errors);
Console.WriteLine("See --help for further details on switches.");
Environment.ExitCode = 1;
return;
}
else
{
var text = HelpText.AutoBuild(options, (HelpText current) => HelpText.DefaultParsingErrorsHandler(options, current));
text.Copyright = " ";
text.Heading = "Jackett v" + Engine.ConfigService.GetVersion() + " options:";
Console.WriteLine(text);
Environment.ExitCode = 1;
return;
}
}
else
{
if (options.ListenPublic && options.ListenPrivate)
{
Console.WriteLine("You can only use listen private OR listen publicly.");
Environment.ExitCode = 1;
return;
}
/* ====== Options ===== */
// SSL Fix
Startup.DoSSLFix = options.SSLFix;
// Use curl
if (options.Client!=null)
if (options.Client != null)
Startup.ClientOverride = options.Client.ToLowerInvariant();
// Logging
@ -126,12 +147,12 @@ namespace JackettConsole
/* ====== Overrides ===== */
// Override listen public
if(options.ListenPublic.HasValue)
if (options.ListenPublic || options.ListenPrivate)
{
if (Engine.Server.Config.AllowExternal != options.ListenPublic)
{
Engine.Logger.Info("Overriding external access to " + options.ListenPublic);
Engine.Server.Config.AllowExternal = options.ListenPublic.Value;
Engine.Server.Config.AllowExternal = options.ListenPublic;
if (System.Environment.OSVersion.Platform != PlatformID.Unix)
{
if (ServerUtil.IsUserAdministrator())
@ -151,7 +172,7 @@ namespace JackettConsole
}
// Override port
if(options.Port != 0)
if (options.Port != 0)
{
if (Engine.Server.Config.Port != options.Port)
{