121 lines
3.8 KiB
C#
121 lines
3.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using TeaBox.Core.Helpers;
|
|
|
|
|
|
namespace TeaBox.Build.Code
|
|
{
|
|
/// <summary>
|
|
/// Command to switch packages from a sln file to git cloned repositories
|
|
/// </summary>
|
|
public class SwitchToSourceCommand : ProcessTask
|
|
{
|
|
public enum GitFolderStructure
|
|
{
|
|
Flat,
|
|
Nested
|
|
}
|
|
|
|
/// <summary>
|
|
/// Solution to switch from
|
|
/// </summary>
|
|
public string Solution { get; set; }
|
|
|
|
/// <summary>
|
|
/// Package name to switch
|
|
/// </summary>
|
|
public string[] Packages { get; set; }
|
|
|
|
/// <summary>
|
|
/// Location of the cloned project references
|
|
/// </summary>
|
|
public string ClonePath { get; set; }
|
|
|
|
/// <summary>
|
|
/// Switch all packages to source
|
|
/// </summary>
|
|
public bool? SwitchAllPackages { get; set; }
|
|
|
|
/// <summary>
|
|
/// Switch package only even if another package has a dependency on it
|
|
/// </summary>
|
|
public bool? DoNotSearchDependentPackages { get; set; }
|
|
|
|
/// <summary>
|
|
/// Do not checkout the tag that match the version of the NuGet package after cloning a repository
|
|
/// </summary>
|
|
public bool? NoCheckout { get; set; }
|
|
|
|
/// <summary>
|
|
/// Switch package and dependencies only
|
|
/// </summary>
|
|
public bool? RequiredProjectsOnly { get; set; }
|
|
|
|
/// <summary>
|
|
/// Add projects to the solution even if there are no dependencies
|
|
/// </summary>
|
|
public bool? SkipDependencyCheck { get; set; }
|
|
|
|
/// <summary>
|
|
/// folder structure of the git cloned projects
|
|
/// </summary>
|
|
public GitFolderStructure FolderStructure { get; set; }
|
|
|
|
/// <inheritdoc />
|
|
protected override string CommandName => LocatorService.LocateApplicationFromScripts("SwitchToSource.CLI.exe");
|
|
|
|
protected override string GetArguments()
|
|
{
|
|
var builder = new SwitchToSourceArguments();
|
|
builder.Set("--solution", Solution);
|
|
if (Packages.Any())
|
|
{
|
|
builder.Set("--package", Packages);
|
|
}
|
|
builder.Set("--all-packages", SwitchAllPackages);
|
|
builder.Set("--clone-path", ClonePath);
|
|
if (DoNotSearchDependentPackages.HasValue && DoNotSearchDependentPackages.Value)
|
|
{
|
|
builder.Set("--do-not-search-dependent-packages");
|
|
}
|
|
if (NoCheckout.HasValue && NoCheckout.Value)
|
|
{
|
|
builder.Set("--no-checkout");
|
|
}
|
|
if (RequiredProjectsOnly.HasValue && RequiredProjectsOnly.Value)
|
|
{
|
|
builder.Set("--required-projects-only");
|
|
}
|
|
|
|
if (SkipDependencyCheck.HasValue && SkipDependencyCheck.Value)
|
|
{
|
|
builder.Set("--skip-dependency-check");
|
|
}
|
|
builder.Set("--folder-structure", FolderStructure);
|
|
return "SwitchToSource " + builder;
|
|
}
|
|
|
|
public class SwitchToSourceArguments : TeaBox.Code.CommandArguments
|
|
{
|
|
public SwitchToSourceArguments()
|
|
{
|
|
ArgumentFormatString = "{0} {1}";
|
|
ArgumentWithNullValueFormatString = "{0}";
|
|
ArrayValuesSeparator = ",";
|
|
Separator = " ";
|
|
}
|
|
|
|
protected override string FormatArgument(KeyValuePair<string, string> argument)
|
|
{
|
|
// Flags are only represented by the argument name, no value are specified.
|
|
if (bool.TryParse(argument.Value, out var argumentValue) && argumentValue)
|
|
{
|
|
return argument.Key;
|
|
}
|
|
|
|
return base.FormatArgument(argument);
|
|
}
|
|
}
|
|
}
|
|
}
|