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