using Microsoft.Extensions.CommandLineUtils for blazor-cli
This commit is contained in:
parent
fb6427a46a
commit
dd807a6d70
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Microsoft.AspNetCore.Blazor.Cli.Commands
|
||||
{
|
||||
class ServeCommand
|
||||
{
|
||||
public static void Command(CommandLineApplication command)
|
||||
{
|
||||
var remainingArgs = command.RemainingArguments.ToArray();
|
||||
|
||||
Server.Program.BuildWebHost(remainingArgs).Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore" Version="$(AspNetCorePackageVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="$(AspNetCorePackageVersion)" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
using Microsoft.AspNetCore.Hosting;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
using Microsoft.AspNetCore.Blazor.Cli.Commands;
|
||||
|
||||
namespace Microsoft.AspNetCore.Blazor.Cli
|
||||
{
|
||||
|
|
@ -11,22 +13,22 @@ namespace Microsoft.AspNetCore.Blazor.Cli
|
|||
{
|
||||
static int Main(string[] args)
|
||||
{
|
||||
if (args.Length == 0)
|
||||
var app = new CommandLineApplication
|
||||
{
|
||||
Console.WriteLine("Usage: dotnet blazor <command>");
|
||||
return 1;
|
||||
Name = "blazor-cli"
|
||||
};
|
||||
app.HelpOption("-?|-h|--help");
|
||||
|
||||
app.Command("serve", ServeCommand.Command);
|
||||
|
||||
if (args.Length > 0)
|
||||
{
|
||||
return app.Execute(args);
|
||||
}
|
||||
|
||||
var command = args[0];
|
||||
var remainingArgs = args.Skip(1).ToArray();
|
||||
|
||||
switch (command.ToLowerInvariant())
|
||||
else
|
||||
{
|
||||
case "serve":
|
||||
Server.Program.BuildWebHost(remainingArgs).Run();
|
||||
return 0;
|
||||
default:
|
||||
throw new InvalidOperationException($"Unknown command: {command}");
|
||||
app.ShowHelp();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue