From b72248ab3d2b8704b73ca6232911c72e52ec019f Mon Sep 17 00:00:00 2001 From: KZ Date: Wed, 5 Aug 2015 19:13:51 +0100 Subject: [PATCH] Invalid command line options now show errors --- src/Jackett.Console/ConsoleOptions.cs | 12 ++++++-- src/Jackett.Console/Program.cs | 41 ++++++++++++++++++++------- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/Jackett.Console/ConsoleOptions.cs b/src/Jackett.Console/ConsoleOptions.cs index cefa8d94f..8ad9bd000 100644 --- a/src/Jackett.Console/ConsoleOptions.cs +++ b/src/Jackett.Console/ConsoleOptions.cs @@ -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; } } } diff --git a/src/Jackett.Console/Program.cs b/src/Jackett.Console/Program.cs index 90c49c6b5..f83d4ed14 100644 --- a/src/Jackett.Console/Program.cs +++ b/src/Jackett.Console/Program.cs @@ -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) {