Fix dotnet run double dash passing arguments

When run “dotnet run -- foo”, foo should be the argument passed to the
subject app. After replacing the original parser, dotnet-run did not
utilize the “unparsedtoken” of the parsed result.

To append unparsedtoken to RunCommand’s argument is not straight
forward. RunCommand has an “immutable constructor”, which is a good
thing, so I made update RunCommand’s argument following the immutable
pattern -- create a new object with the original field but only change
the arguments. I also made these filed private set.
This commit is contained in:
William Li 2017-04-12 16:03:45 -07:00
commit 83f3a3ec86
7 changed files with 115 additions and 21 deletions

View file

@ -13,11 +13,11 @@ namespace Microsoft.DotNet.Tools.Run
{
public partial class RunCommand
{
public string Configuration { get; set; }
public string Framework { get; set; }
public bool NoBuild { get; set; }
public string Project { get; set; }
public IReadOnlyCollection<string> Args { get; set; }
public string Configuration { get; private set; }
public string Framework { get; private set; }
public bool NoBuild { get; private set; }
public string Project { get; private set; }
public IReadOnlyCollection<string> Args { get; private set; }
private List<string> _args;
private bool ShouldBuild => !NoBuild;
@ -38,6 +38,34 @@ namespace Microsoft.DotNet.Tools.Run
.ExitCode;
}
public RunCommand(string configuration,
string framework,
bool noBuild,
string project,
IReadOnlyCollection<string> args)
{
Configuration = configuration;
Framework = framework;
NoBuild = noBuild;
Project = project;
Args = args;
}
public RunCommand MakeNewWithReplaced(string configuration = null,
string framework = null,
bool? noBuild = null,
string project = null,
IReadOnlyCollection<string> args = null)
{
return new RunCommand(
configuration ?? this.Configuration,
framework ?? this.Framework,
noBuild ?? this.NoBuild,
project ?? this.Project,
args ?? this.Args
);
}
private void EnsureProjectIsBuilt()
{
List<string> buildArgs = new List<string>();