2015-12-31 01:02:59 +00:00
|
|
|
|
// 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.
|
|
|
|
|
|
2016-04-23 04:40:39 +00:00
|
|
|
|
using System.Linq;
|
2016-04-05 00:51:36 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2016-04-23 04:40:39 +00:00
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
2015-12-31 01:02:59 +00:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Tools.Test.Utilities
|
|
|
|
|
{
|
|
|
|
|
public sealed class RunCommand : TestCommand
|
|
|
|
|
{
|
|
|
|
|
private string _projectPath;
|
|
|
|
|
private string _framework;
|
|
|
|
|
private string _configuration;
|
|
|
|
|
private bool _preserveTemporary;
|
|
|
|
|
private string _appArgs;
|
|
|
|
|
|
2016-04-25 20:53:02 +00:00
|
|
|
|
private string ProjectPathOption => string.IsNullOrEmpty(_projectPath) ? "" : $"-p \"{_projectPath}\"";
|
2015-12-31 01:02:59 +00:00
|
|
|
|
|
2016-04-25 20:53:02 +00:00
|
|
|
|
private string FrameworkOption => string.IsNullOrEmpty(_framework) ? "" : $"-f {_framework}";
|
2015-12-31 01:02:59 +00:00
|
|
|
|
|
2016-04-25 20:53:02 +00:00
|
|
|
|
private string ConfigurationOption => string.IsNullOrEmpty(_configuration) ? "" : $"-c {_configuration}";
|
2015-12-31 01:02:59 +00:00
|
|
|
|
|
2016-04-25 20:53:02 +00:00
|
|
|
|
private string AppArgsArgument => _appArgs;
|
2015-12-31 01:02:59 +00:00
|
|
|
|
|
|
|
|
|
public RunCommand(
|
|
|
|
|
string projectPath,
|
2016-04-05 00:51:36 +00:00
|
|
|
|
string framework = "",
|
|
|
|
|
string configuration = "",
|
|
|
|
|
string appArgs = "")
|
2015-12-31 01:02:59 +00:00
|
|
|
|
: base("dotnet")
|
|
|
|
|
{
|
|
|
|
|
_projectPath = projectPath;
|
|
|
|
|
_framework = framework;
|
|
|
|
|
_configuration = configuration;
|
|
|
|
|
_appArgs = appArgs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override CommandResult Execute(string args = "")
|
|
|
|
|
{
|
|
|
|
|
args = $"run {BuildArgs()} {args}";
|
|
|
|
|
return base.Execute(args);
|
|
|
|
|
}
|
2016-04-05 00:51:36 +00:00
|
|
|
|
|
2016-03-31 16:00:25 +00:00
|
|
|
|
public override CommandResult ExecuteWithCapturedOutput(string args = "")
|
|
|
|
|
{
|
|
|
|
|
args = $"run {BuildArgs()} {args}";
|
|
|
|
|
return base.ExecuteWithCapturedOutput(args);
|
|
|
|
|
}
|
2015-12-31 01:02:59 +00:00
|
|
|
|
|
2016-04-05 00:51:36 +00:00
|
|
|
|
public override Task<CommandResult> ExecuteAsync(string args = "")
|
|
|
|
|
{
|
|
|
|
|
args = $"run {BuildArgs()} {args}";
|
|
|
|
|
return base.ExecuteAsync(args);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-23 04:40:39 +00:00
|
|
|
|
private string BuildArgs()
|
|
|
|
|
{
|
|
|
|
|
return string.Join(" ",
|
|
|
|
|
new[]
|
|
|
|
|
{
|
|
|
|
|
ProjectPathOption,
|
|
|
|
|
FrameworkOption,
|
|
|
|
|
ConfigurationOption,
|
|
|
|
|
AppArgsArgument,
|
|
|
|
|
}
|
|
|
|
|
.Where(s => !string.IsNullOrEmpty(s)));
|
|
|
|
|
}
|
2015-12-31 01:02:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|