mirror of https://github.com/winsw/winsw
Improve CLI behaviors with empty arguments
parent
48d4722b58
commit
e8e1ee2300
|
@ -479,24 +479,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.Info("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>();
|
||||
|
@ -767,13 +778,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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue