Command line args. Superceade pull #102 from sdesbure:master

This commit is contained in:
KZ
2015-07-24 00:07:36 +01:00
parent 8891c04b84
commit 84c2b0c8b9
9 changed files with 194 additions and 43 deletions

View File

@@ -1,5 +1,9 @@
using Jackett;
using CommandLine;
using CommandLine.Text;
using Jackett;
using Jackett.Console;
using Jackett.Indexers;
using Jackett.Utils;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -18,44 +22,132 @@ namespace JackettConsole
{
try
{
foreach (var arg in args)
var options = new ConsoleOptions();
if (!Parser.Default.ParseArguments(args, options) || options.ShowHelp == true)
{
switch (arg.ToLowerInvariant())
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
{
/* ====== Actions ===== */
// Install service
if (options.Install)
{
case "/i": // Install
Engine.ServiceConfig.Install();
return;
case "/r": // Reserve port/url & install
Engine.Server.ReserveUrls(doInstall: true);
return;
case "/c": // Change port
Engine.Server.ReserveUrls(doInstall: false);
return;
case "/u": // Uninstall
Engine.Server.ReserveUrls(doInstall: false);
Engine.ServiceConfig.Uninstall();
return;
case "/l": // Logging
Startup.LogRequests = true;
break;
case "/t": // Tracing
Startup.TracingEnabled = true;
break;
case "/curlsafe": // Curl safe mode
Startup.CurlSafe = true;
break;
case "/start": // Start Service
if (!Engine.ServiceConfig.ServiceRunning())
Engine.ServiceConfig.Install();
return;
}
// Uninstall service
if (options.Uninstall)
{
Engine.Server.ReserveUrls(doInstall: false);
Engine.ServiceConfig.Uninstall();
return;
}
// Reserve urls
if (options.ReserveUrls)
{
Engine.Server.ReserveUrls(doInstall: true);
return;
}
// Start Service
if (options.StartService)
{
if (!Engine.ServiceConfig.ServiceRunning())
{
Engine.ServiceConfig.Start();
}
return;
}
// Stop Service
if (options.StopService)
{
if (Engine.ServiceConfig.ServiceRunning())
{
Engine.ServiceConfig.Stop();
}
return;
}
// Show Version
if (options.ShowVersion)
{
Console.WriteLine("Jackett v" + Engine.ConfigService.GetVersion());
return;
}
/* ====== Options ===== */
// Logging
if (options.Logging)
{
Startup.LogRequests = true;
}
// Tracing
if (options.Tracing)
{
Startup.TracingEnabled = true;
}
// Use curl
if (options.UseCurlExec)
{
Startup.CurlSafe = true;
}
// Override listen public
if(options.ListenPublic.HasValue)
{
if(Engine.Server.Config.AllowExternal != options.ListenPublic)
{
Engine.Server.Config.AllowExternal = options.ListenPublic.Value;
if (System.Environment.OSVersion.Platform != PlatformID.Unix)
{
Engine.ServiceConfig.Start();
if (ServerUtil.IsUserAdministrator())
{
Engine.Server.ReserveUrls(doInstall: true);
}
else
{
Engine.Logger.Error("Unable to switch to public listening without admin rights.");
Environment.ExitCode = 1;
return;
}
}
return;
case "/stop": // Stop Service
if (Engine.ServiceConfig.ServiceRunning())
}
}
// Override port
if(options.Port != 0)
{
if (Engine.Server.Config.Port != options.Port)
{
Engine.Server.Config.Port = options.Port;
if (System.Environment.OSVersion.Platform != PlatformID.Unix)
{
Engine.ServiceConfig.Stop();
if (ServerUtil.IsUserAdministrator())
{
Engine.Server.ReserveUrls(doInstall: true);
}
else
{
Engine.Logger.Error("Unable to switch ports when not running as administrator");
Environment.ExitCode = 1;
return;
}
}
return;
}
}
}