dotnet-installer/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PublishCommand.cs

86 lines
2.6 KiB
C#
Raw Normal View History

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.
using Microsoft.DotNet.Cli.Utils;
using NuGet.Frameworks;
using System.Collections.Generic;
2015-12-15 01:39:29 +00:00
namespace Microsoft.DotNet.Tools.Test.Utilities
2015-12-15 01:39:29 +00:00
{
public sealed class PublishCommand : DotnetCommand
2015-12-15 01:39:29 +00:00
{
private string _framework;
private string _output;
private string _runtime;
2017-04-07 19:15:38 +00:00
private List<string> _targetManifests = new List<string>();
private bool? _selfContained;
public PublishCommand WithFramework(string framework)
{
_framework = framework;
return this;
}
public PublishCommand WithFramework(NuGetFramework framework)
2015-12-15 01:39:29 +00:00
{
return WithFramework(framework.GetShortFolderName());
2015-12-15 01:39:29 +00:00
}
public PublishCommand WithOutput(string output)
2015-12-15 01:39:29 +00:00
{
_output = output;
return this;
2015-12-15 01:39:29 +00:00
}
public PublishCommand WithRuntime(string runtime)
{
_runtime = runtime;
return this;
}
public PublishCommand WithTargetManifest(string manifest)
{
_targetManifests.Add( $"--manifest {manifest}");
return this;
}
public PublishCommand WithSelfContained(bool value)
{
_selfContained = value;
return this;
}
public override CommandResult Execute(string args = "")
2015-12-15 01:39:29 +00:00
{
args = $"publish {BuildArgs()} {args}";
return base.Execute(args);
}
public override CommandResult ExecuteWithCapturedOutput(string args = "")
{
args = $"publish {BuildArgs()} {args}";
return base.ExecuteWithCapturedOutput(args);
2015-12-15 01:39:29 +00:00
}
private string BuildArgs()
{
return string.Join(" ",
FrameworkOption,
OutputOption,
2017-04-07 19:15:38 +00:00
TargetOption,
RuntimeOption,
SelfContainedOption);
2015-12-15 01:39:29 +00:00
}
private string FrameworkOption => string.IsNullOrEmpty(_framework) ? "" : $"-f {_framework}";
private string OutputOption => string.IsNullOrEmpty(_output) ? "" : $"-o {_output}";
private string RuntimeOption => string.IsNullOrEmpty(_runtime) ? "" : $"-r {_runtime}";
2017-04-07 19:15:38 +00:00
private string TargetOption => string.Join(" ", _targetManifests);
private string SelfContainedOption => _selfContained.HasValue ? $"--self-contained:{_selfContained.Value}" : "";
2015-12-15 01:39:29 +00:00
}
}