dotnet run doesn't accept '--' arg separator anymore

When moving from System.CommandLine to the DNX arg parser, we regressed in parsing arguments that should be passed to the underlying process.

Fix #2643
This commit is contained in:
Eric Erhardt 2016-04-22 16:01:17 -05:00
parent 705a48940f
commit dd327b52a5
2 changed files with 18 additions and 7 deletions

View file

@ -44,6 +44,7 @@ namespace Microsoft.DotNet.Cli.CommandLine
public Func<string> ShortVersionGetter { get; set; }
public List<CommandLineApplication> Commands { get; private set; }
public bool HandleResponseFiles { get; set; }
public bool AllowArgumentSeparator { get; set; }
public CommandLineApplication Command(string name, Action<CommandLineApplication> configuration,
bool throwOnUnexpectedArg = true)
@ -129,10 +130,18 @@ namespace Microsoft.DotNet.Cli.CommandLine
if (longOption != null)
{
processed = true;
option = command.Options.SingleOrDefault(opt => string.Equals(opt.LongName, longOption[0], StringComparison.Ordinal));
string longOptionName = longOption[0];
option = command.Options.SingleOrDefault(opt => string.Equals(opt.LongName, longOptionName, StringComparison.Ordinal));
if (option == null)
{
if (string.IsNullOrEmpty(longOptionName) && !command._throwOnUnexpectedArg && AllowArgumentSeparator)
{
// a stand-alone "--" is the argument separator, so skip it and
// handle the rest of the args as unexpected args
index++;
}
HandleUnexpectedArg(command, args, index, argTypeName: "option");
break;
}
@ -405,6 +414,11 @@ namespace Microsoft.DotNet.Cli.CommandLine
}
}
if (target.AllowArgumentSeparator)
{
headerBuilder.Append(" [[--] <arg>...]]");
}
headerBuilder.AppendLine();
var nameAndVersion = new StringBuilder();

View file

@ -13,21 +13,18 @@ namespace Microsoft.DotNet.Tools.Run
{
DebugHelper.HandleDebugSwitch(ref args);
CommandLineApplication app = new CommandLineApplication();
CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false);
app.Name = "dotnet run";
app.FullName = ".NET Run Command";
app.Description = "Command used to run .NET apps";
app.HandleResponseFiles = true;
app.AllowArgumentSeparator = true;
app.HelpOption("-h|--help");
CommandOption framework = app.Option("-f|--framework", "Compile a specific framework", CommandOptionType.SingleValue);
CommandOption configuration = app.Option("-c|--configuration", "Configuration under which to build", CommandOptionType.SingleValue);
CommandOption project = app.Option("-p|--project", "The path to the project to run (defaults to the current directory). Can be a path to a project.json or a project directory", CommandOptionType.SingleValue);
// TODO: this is not supporting args which can be switches (i.e. --test)
// TODO: we need to make a change in CommandLine utils or parse args ourselves.
CommandArgument runArgs = app.Argument("args", "Arguments to pass to the executable or script", multipleValues: true);
app.OnExecute(() =>
{
RunCommand runCmd = new RunCommand();
@ -35,7 +32,7 @@ namespace Microsoft.DotNet.Tools.Run
runCmd.Framework = framework.Value();
runCmd.Configuration = configuration.Value();
runCmd.Project = project.Value();
runCmd.Args = runArgs.Values;
runCmd.Args = app.RemainingArguments;
return runCmd.Start();
});