2015-12-15 01:39:29 +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-28 23:30:32 +00:00
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
2016-10-28 01:46:43 +00:00
|
|
|
|
using NuGet.Frameworks;
|
2015-12-15 01:39:29 +00:00
|
|
|
|
|
2015-12-31 01:02:59 +00:00
|
|
|
|
namespace Microsoft.DotNet.Tools.Test.Utilities
|
2015-12-15 01:39:29 +00:00
|
|
|
|
{
|
|
|
|
|
public sealed class PublishCommand : TestCommand
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
private string _framework;
|
|
|
|
|
private string _output;
|
|
|
|
|
private string _runtime;
|
2017-02-14 01:56:25 +00:00
|
|
|
|
private string _profileproj;
|
2016-02-16 23:30:39 +00:00
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public PublishCommand()
|
2015-12-15 01:39:29 +00:00
|
|
|
|
: base("dotnet")
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public PublishCommand WithFramework(string framework)
|
2016-01-11 21:40:47 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
_framework = framework;
|
|
|
|
|
return this;
|
2016-01-11 21:40:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public PublishCommand WithFramework(NuGetFramework framework)
|
2015-12-15 01:39:29 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
return WithFramework(framework.GetShortFolderName());
|
2015-12-15 01:39:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public PublishCommand WithOutput(string output)
|
2015-12-15 01:39:29 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
_output = output;
|
|
|
|
|
return this;
|
2015-12-15 01:39:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public PublishCommand WithRuntime(string runtime)
|
2016-03-15 18:50:14 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
_runtime = runtime;
|
|
|
|
|
return this;
|
2016-03-15 18:50:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-14 01:56:25 +00:00
|
|
|
|
public PublishCommand WithProFileProject(string profileproj)
|
|
|
|
|
{
|
|
|
|
|
_profileproj = profileproj;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public override CommandResult Execute(string args = "")
|
2015-12-15 01:39:29 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
args = $"publish {BuildArgs()} {args}";
|
|
|
|
|
return base.Execute(args);
|
2016-03-17 20:46:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public override CommandResult ExecuteWithCapturedOutput(string args = "")
|
2016-03-17 20:46:46 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
args = $"publish {BuildArgs()} {args}";
|
|
|
|
|
return base.ExecuteWithCapturedOutput(args);
|
2015-12-15 01:39:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string BuildArgs()
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
return string.Join(" ",
|
|
|
|
|
FrameworkOption,
|
|
|
|
|
OutputOption,
|
2017-02-14 01:56:25 +00:00
|
|
|
|
ProfileProjOption,
|
2016-10-28 01:46:43 +00:00
|
|
|
|
RuntimeOption);
|
2015-12-15 01:39:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-09 19:36:16 +00:00
|
|
|
|
private string FrameworkOption => string.IsNullOrEmpty(_framework) ? "" : $"-f {_framework}";
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
|
|
private string OutputOption => string.IsNullOrEmpty(_output) ? "" : $"-o {_output}";
|
|
|
|
|
|
2016-03-09 19:36:16 +00:00
|
|
|
|
private string RuntimeOption => string.IsNullOrEmpty(_runtime) ? "" : $"-r {_runtime}";
|
2017-02-14 01:56:25 +00:00
|
|
|
|
|
|
|
|
|
private string ProfileProjOption => string.IsNullOrEmpty(_profileproj) ? "" : $"--filter {_profileproj}";
|
2015-12-15 01:39:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|