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
{
2017-03-14 14:07:51 -07:00
public sealed class PublishCommand : DotnetCommand
2015-12-14 17:39:29 -08:00
{
2016-10-27 18:46:43 -07:00
private string _framework ;
private string _output ;
private string _runtime ;
2017-04-07 14:15:38 -05:00
private List < string > _targetManifests = new List < string > ( ) ;
2017-04-03 18:09:50 -05:00
private bool? _selfContained ;
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-04-14 16:08:32 -05:00
public PublishCommand WithTargetManifest ( string manifest )
2017-02-13 17:56:25 -08:00
{
2017-04-14 16:08:32 -05:00
_targetManifests . Add ( $"--manifest {manifest}" ) ;
2017-02-13 17:56:25 -08:00
return this ;
}
2017-04-03 18:09:50 -05:00
public PublishCommand WithSelfContained ( bool value )
{
_selfContained = value ;
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-04-07 14:15:38 -05:00
TargetOption ,
2017-04-03 18:09:50 -05:00
RuntimeOption ,
SelfContainedOption ) ;
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-04-07 14:15:38 -05:00
private string TargetOption = > string . Join ( " " , _targetManifests ) ;
2017-04-03 18:09:50 -05:00
private string SelfContainedOption = > _selfContained . HasValue ? $"--self-contained:{_selfContained.Value}" : "" ;
2015-12-14 17:39:29 -08:00
}
}