Convert Run
This commit is contained in:
parent
4149150acc
commit
071f4dc697
3 changed files with 50 additions and 43 deletions
|
@ -54,6 +54,7 @@ namespace Microsoft.DotNet.Tools.Build
|
|||
DebugHelper.HandleDebugSwitch(ref args);
|
||||
|
||||
BuildCommand cmd;
|
||||
|
||||
try
|
||||
{
|
||||
cmd = FromArgs(args);
|
||||
|
|
|
@ -4,47 +4,42 @@
|
|||
using System;
|
||||
using Microsoft.DotNet.Cli.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Cli;
|
||||
using Parser = Microsoft.DotNet.Cli.Parser;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Run
|
||||
{
|
||||
public partial class RunCommand
|
||||
{
|
||||
public static RunCommand FromArgs(string[] args, string msbuildPath = null)
|
||||
{
|
||||
var parser = Parser.Instance;
|
||||
|
||||
var result = parser.ParseFrom("dotnet run", args);
|
||||
|
||||
Reporter.Output.WriteLine(result.Diagram());
|
||||
|
||||
result.ShowHelpIfRequested();
|
||||
|
||||
return result["dotnet"]["run"].Value<RunCommand>();
|
||||
}
|
||||
|
||||
public static int Run(string[] args)
|
||||
{
|
||||
DebugHelper.HandleDebugSwitch(ref args);
|
||||
|
||||
CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false);
|
||||
app.Name = "dotnet run";
|
||||
app.FullName = LocalizableStrings.AppFullName;
|
||||
app.Description = LocalizableStrings.AppDescription;
|
||||
app.HandleResponseFiles = true;
|
||||
app.AllowArgumentSeparator = true;
|
||||
app.ArgumentSeparatorHelpText = LocalizableStrings.RunCommandAdditionalArgsHelpText;
|
||||
app.HelpOption("-h|--help");
|
||||
|
||||
CommandOption configuration = app.Option(
|
||||
"-c|--configuration", LocalizableStrings.CommandOptionConfigurationDescription,
|
||||
CommandOptionType.SingleValue);
|
||||
CommandOption framework = app.Option(
|
||||
$"-f|--framework <{LocalizableStrings.CommandOptionFramework}>", LocalizableStrings.CommandOptionFrameworkDescription,
|
||||
CommandOptionType.SingleValue);
|
||||
CommandOption project = app.Option(
|
||||
"-p|--project", LocalizableStrings.CommandOptionProjectDescription,
|
||||
CommandOptionType.SingleValue);
|
||||
|
||||
app.OnExecute(() =>
|
||||
RunCommand cmd;
|
||||
|
||||
try
|
||||
{
|
||||
RunCommand runCmd = new RunCommand();
|
||||
cmd = FromArgs(args);
|
||||
}
|
||||
catch (CommandCreationException e)
|
||||
{
|
||||
return e.ExitCode;
|
||||
}
|
||||
|
||||
runCmd.Configuration = configuration.Value();
|
||||
runCmd.Framework = framework.Value();
|
||||
runCmd.Project = project.Value();
|
||||
runCmd.Args = app.RemainingArguments;
|
||||
|
||||
return runCmd.Start();
|
||||
});
|
||||
|
||||
return app.Execute(args);
|
||||
return cmd.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +1,36 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.DotNet.Cli.CommandLine;
|
||||
using Microsoft.DotNet.Tools.Run;
|
||||
using LocalizableStrings = Microsoft.DotNet.Tools.Run.LocalizableStrings;
|
||||
|
||||
namespace Microsoft.DotNet.Cli
|
||||
{
|
||||
internal static class RunCommandParser
|
||||
{
|
||||
public static Command Run() =>
|
||||
Create.Command("run",
|
||||
".NET Run Command",
|
||||
CommonOptions.HelpOption(),
|
||||
Create.Option("-c|--configuration",
|
||||
@"Configuration to use for building the project. Default for most projects is ""Debug"".",
|
||||
Accept.ExactlyOneArgument
|
||||
.WithSuggestionsFrom("DEBUG", "RELEASE")),
|
||||
Create.Option("-f|--framework",
|
||||
"Build and run the app using the specified framework. The framework has to be specified in the project file.",
|
||||
Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile)),
|
||||
Create.Option("-p|--project",
|
||||
"The path to the project file to run (defaults to the current directory if there is only one project).",
|
||||
Accept.ZeroOrOneArgument));
|
||||
Create.Command(
|
||||
"run",
|
||||
".NET Run Command",
|
||||
Accept.ZeroOrMoreArguments
|
||||
.MaterializeAs(o =>
|
||||
{
|
||||
return new RunCommand()
|
||||
{
|
||||
Configuration = o.ValueOrDefault<string>("--configuration"),
|
||||
Framework = o.ValueOrDefault<string>("--framework"),
|
||||
Project = o.ValueOrDefault<string>("--project"),
|
||||
Args = (IReadOnlyList<string>)o.Arguments
|
||||
};
|
||||
}),
|
||||
CommonOptions.HelpOption(),
|
||||
CommonOptions.ConfigurationOption(),
|
||||
CommonOptions.FrameworkOption(),
|
||||
Create.Option(
|
||||
"-p|--project",
|
||||
LocalizableStrings.CommandOptionProjectDescription,
|
||||
Accept.ExactlyOneArgument));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue