This commit is contained in:
Matthew Parker
2023-08-29 23:19:28 +10:00
parent 18a4500c7b
commit fe9b8627c5
6 changed files with 93 additions and 23 deletions

View File

@@ -0,0 +1,75 @@
using System.ComponentModel;
using Microsoft.Build.Construction;
using Spectre.Console;
using Spectre.Console.Cli;
namespace SolutionParityChecker.CLI.Commands;
public class CompareCommand : Command<CompareCommand.Settings>
{
public sealed class Settings : CommandSettings
{
[CommandArgument(0, "<SolutionFolderPath>")]
public required string SolutionFolderPath { get; set; }
[CommandArgument(1, "<SolutionFilePath>")]
public required string SolutionFilePath { get; set; }
[CommandOption("-l|--logprojectfiles")]
[Description("true to enable logging of all project files. Default is false.")]
[DefaultValue(false)]
public bool LogAllProjectFileNames { get; set; } = false;
}
public override int Execute(CommandContext context, Settings settings)
{
var folderDirectory = settings.SolutionFolderPath; // Include the trailing slash
var pathToSolutionFile = settings.SolutionFilePath;
Console.WriteLine($"Retrieving C# Projects from {folderDirectory}");
var csprojList = SolutionParityChecker.RetrieveAllCSharpProjectNamesFromFolder(
folderDirectory
);
if (settings.LogAllProjectFileNames)
{
foreach (var project in csprojList)
{
Console.WriteLine(project);
}
}
Console.WriteLine($"Retrieved {csprojList.Length} C# Projects");
Console.WriteLine("==================================================");
Console.WriteLine($"Parsing Solution File: {pathToSolutionFile}");
// Load the solution file
var solutionFile = SolutionParityChecker.ParseSolutionFileFromPath(pathToSolutionFile);
if (solutionFile == null)
{
Console.WriteLine(
"Failed to parse solution file. The file was either not found or malformed."
);
return 1;
}
// Get the list of projects
var projectsMissingFromSolution = SolutionParityChecker.FindProjectsMissingFromSolution(
csprojList,
solutionFile
);
Console.WriteLine("==================================================");
Console.WriteLine(
$"Missing {projectsMissingFromSolution.Count} C# Projects from Solution File"
);
foreach (var project in projectsMissingFromSolution)
{
Console.WriteLine(project);
}
Console.WriteLine("==================================================");
Console.WriteLine("Done!");
return 0;
}
}

View File

@@ -0,0 +1,13 @@
using SolutionParityChecker.CLI.Commands;
using Spectre.Console.Cli;
var app = new CommandApp();
app.Configure(config =>
{
config.SetApplicationName("SolutionParityChecker");
config.ValidateExamples();
config.AddCommand<CompareCommand>("compare");
});
return await app.RunAsync(args);

View File

@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build" Version="17.7.2" />
<PackageReference Include="Spectre.Console" Version="0.47.0" />
<PackageReference Include="Spectre.Console.Cli" Version="0.47.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SolutionParityChecker\SolutionParityChecker.csproj" />
</ItemGroup>
</Project>