Browse Source

add dashboard option to auto launch (#350)

pull/357/head
Shayne Boyer 6 years ago
committed by GitHub
parent
commit
a2dd987aa3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 33
      src/Microsoft.Tye.Hosting/TyeHost.cs
  2. 6
      src/tye/Program.RunCommand.cs

33
src/Microsoft.Tye.Hosting/TyeHost.cs

@ -4,10 +4,13 @@
using System;
using System.Collections.Generic;
using System.CommandLine.Invocation;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
@ -98,6 +101,11 @@ namespace Microsoft.Tye.Hosting
await _processor.StartAsync(_application);
if (_args.Contains("--dashboard"))
{
OpenDashboard(app.Addresses.First());
}
return app;
}
@ -298,6 +306,31 @@ namespace Microsoft.Tye.Hosting
_processor = null;
}
private void OpenDashboard(string url)
{
try
{
// https://github.com/dotnet/corefx/issues/10361
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
url = url.Replace("&", "^&");
System.Diagnostics.Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true });
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
System.Diagnostics.Process.Start("xdg-open", url);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
System.Diagnostics.Process.Start("open", url);
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error launching dashboard.");
}
}
public async ValueTask DisposeAsync()
{
await StopAsync();

6
src/tye/Program.RunCommand.cs

@ -64,6 +64,12 @@ namespace Microsoft.Tye
Required = false
});
command.AddOption(new Option("--dashboard")
{
Description = "Launch dashboard on run.",
Required = false
});
command.Handler = CommandHandler.Create<IConsole, FileInfo, string[]>(async (console, path, debug) =>
{
// Workaround for https://github.com/dotnet/command-line-api/issues/723#issuecomment-593062654

Loading…
Cancel
Save