2015-12-30 17:02:59 -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.
using Microsoft.DotNet.Cli.Utils ;
namespace Microsoft.DotNet.Tools.Test.Utilities
{
2017-03-14 14:07:51 -07:00
public sealed class PackCommand : DotnetCommand
2015-12-30 17:02:59 -08:00
{
private string _projectPath ;
private string _outputDirectory ;
2016-02-23 19:07:27 -08:00
private string _buildBasePath ;
2015-12-30 17:02:59 -08:00
private string _tempOutputDirectory ;
private string _configuration ;
private string _versionSuffix ;
2016-06-05 11:52:41 -07:00
private bool _serviceable ;
2015-12-30 17:02:59 -08:00
2023-11-10 17:07:05 -08:00
private string OutputOption = > _outputDirectory = = string . Empty ?
2015-12-30 17:02:59 -08:00
"" :
2016-01-22 14:05:02 -08:00
$"-o \" { _outputDirectory } \ "" ;
2023-11-10 17:07:05 -08:00
private string BuildBasePathOption = > _buildBasePath = = string . Empty ?
2016-02-23 19:07:27 -08:00
"" :
$"-b \" { _buildBasePath } \ "" ;
2015-12-30 17:02:59 -08:00
2023-11-10 17:07:05 -08:00
private string TempOutputOption = > _tempOutputDirectory = = string . Empty ?
2015-12-30 17:02:59 -08:00
"" :
$"-t {_tempOutputDirectory}" ;
2023-11-10 17:07:05 -08:00
private string ConfigurationOption = > _configuration = = string . Empty ?
2015-12-30 17:02:59 -08:00
"" :
$"-c {_configuration}" ;
2023-11-10 17:07:05 -08:00
private string VersionSuffixOption = > _versionSuffix = = string . Empty ?
2015-12-30 17:02:59 -08:00
"" :
$"--version-suffix {_versionSuffix}" ;
2023-11-10 17:07:05 -08:00
private string ServiceableOption = > _serviceable ?
2016-06-05 11:52:41 -07:00
$"--serviceable" :
"" ;
2016-06-03 15:46:16 -07:00
2016-10-27 18:46:43 -07:00
public PackCommand WithConfiguration ( string configuration )
{
_configuration = configuration ;
return this ;
}
2015-12-30 17:02:59 -08:00
public PackCommand (
2016-10-27 18:46:43 -07:00
string projectPath = "" ,
2016-02-23 19:07:27 -08:00
string output = "" ,
string buildBasePath = "" ,
2015-12-30 17:02:59 -08:00
string tempOutput = "" ,
string configuration = "" ,
2016-06-03 15:46:16 -07:00
string versionSuffix = "" ,
2016-06-05 11:52:41 -07:00
bool serviceable = false )
2015-12-30 17:02:59 -08:00
{
_projectPath = projectPath ;
_outputDirectory = output ;
2016-02-23 19:07:27 -08:00
_buildBasePath = buildBasePath ;
2015-12-30 17:02:59 -08:00
_tempOutputDirectory = tempOutput ;
_configuration = configuration ;
_versionSuffix = versionSuffix ;
2016-06-03 15:46:16 -07:00
_serviceable = serviceable ;
2015-12-30 17:02:59 -08:00
}
public override CommandResult Execute ( string args = "" )
{
args = $"pack {BuildArgs()} {args}" ;
return base . Execute ( args ) ;
}
2016-12-09 16:10:16 -08:00
public override CommandResult ExecuteWithCapturedOutput ( string args = "" )
{
args = $"pack {BuildArgs()} {args}" ;
return base . ExecuteWithCapturedOutput ( args ) ;
}
2023-11-10 17:08:10 -08:00
private string BuildArgs ( ) = > $"{_projectPath} {OutputOption} {BuildBasePathOption} {TempOutputOption} {ConfigurationOption} {VersionSuffixOption} {ServiceableOption}" ;
2015-12-30 17:02:59 -08:00
}
}