private static string GetVersion(CommandOption versionOption) { if (versionOption.HasValue()) { return versionOption.Value(); } Console.Write("Please enter version to be inserted into project.json: "); return Console.ReadLine(); }
private static bool CheckArg(CommandOption argument) { if (!argument.HasValue()) { Reporter.Error.WriteLine($"Missing required argument: {argument.LongName.Red().Bold()}"); return false; } return true; }
private static string GetFilePath(CommandOption filePathOption) { if (filePathOption.HasValue()) { return filePathOption.Value(); } Console.WriteLine("No project.json file path is provided. Assuming it is present in current directory."); return "project.json"; }
public static int ResolveProtocol(CommandOption clientProtocolCommand, int pluginProtocol) { int resolvedProtocol; if (clientProtocolCommand.HasValue()) { resolvedProtocol = ResolveProtocol(clientProtocolCommand.Value(), pluginProtocol); } else { // Client protocol wasn't provided, use the plugin's protocol. resolvedProtocol = pluginProtocol; } return resolvedProtocol; }
private static bool MonitorHostProcess(CommandOption host, ILogger logger) { if (!host.HasValue()) { logger.LogError($"Option \"{host.LongName}\" is missing."); return false; } int hostPID; if (int.TryParse(host.Value(), out hostPID)) { var hostProcess = Process.GetProcessById(hostPID); hostProcess.EnableRaisingEvents = true; hostProcess.Exited += (s, e) => { Process.GetCurrentProcess().Kill(); }; logger.LogDebug($"Server will exit when process {hostPID} exits."); return true; } else { logger.LogError($"Option \"{host.LongName}\" is not a valid Int32 value."); return false; } }
private static int CheckPort(CommandOption port, ILogger logger) { if (!port.HasValue()) { logger.LogError($"Option \"{port.LongName}\" is missing."); } int result; if (int.TryParse(port.Value(), out result)) { return result; } else { logger.LogError($"Option \"{port.LongName}\" is not a valid Int32 value."); return -1; } }