Merge pull request #374 from NextTurn/cli

Improve CLI behaviors with empty arguments
pull/397/head
Oleg Nenashev 2020-02-05 12:40:43 -05:00 committed by GitHub
commit b49216fcb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 252 additions and 248 deletions

View File

@ -486,24 +486,35 @@ namespace winsw
/// <summary>
/// Runs the wrapper.
/// </summary>
/// <param name="_args">Arguments. If empty, WinSW will behave in the service mode. Otherwise - CLI mode</param>
/// <param name="_args">Arguments.</param>
/// <param name="descriptor">Service descriptor. If null, it will be initialized within the method.
/// In such case configs will be loaded from the XML Configuration File.</param>
/// <exception cref="Exception">Any unhandled exception</exception>
public static void Run(string[] _args, ServiceDescriptor? descriptor = null)
{
bool isCLIMode = _args.Length > 0;
bool inCliMode = Console.OpenStandardInput() != Stream.Null;
// If descriptor is not specified, initialize the new one (and load configs from there)
descriptor ??= new ServiceDescriptor();
// Configure the wrapper-internal logging.
// STDIN and STDOUT of the child process will be handled independently.
InitLoggers(descriptor, isCLIMode);
InitLoggers(descriptor, inCliMode);
if (isCLIMode) // CLI mode, in-service mode otherwise
if (!inCliMode)
{
Log.Debug("Starting ServiceWrapper in the CLI mode");
Log.Debug("Starting WinSW in the service mode");
Run(new WrapperService(descriptor));
return;
}
Log.Debug("Starting WinSW in the CLI mode");
if (_args.Length == 0)
{
printHelp();
return;
}
// Get service info for the future use
Win32Services svc = new WmiRoot().GetCollection<Win32Services>();
@ -774,13 +785,6 @@ namespace winsw
printAvailableCommandsInfo();
throw new Exception("Unknown command: " + args[0]);
}
else
{
Log.Info("Starting ServiceWrapper in the service mode");
}
Run(new WrapperService(descriptor));
}
private static void InitLoggers(ServiceDescriptor d, bool enableCLILogging)
{