create helper classes

This commit is contained in:
Matthew Parker [SSW]
2024-01-21 14:59:19 +10:00
parent 3f5905349d
commit 22af01dc48
16 changed files with 225 additions and 215 deletions

View File

@@ -1,5 +1,4 @@
using System.ComponentModel;
using DotNetSolutionTools.Core;
using DotNetSolutionTools.Core;
using Spectre.Console.Cli;
namespace DotNetSolutionTools.CLI.Commands;

View File

@@ -1,5 +1,6 @@
using System.ComponentModel;
using DotNetSolutionTools.Core;
using DotNetSolutionTools.Core.Common;
using Spectre.Console.Cli;
namespace DotNetSolutionTools.CLI.Commands;
@@ -15,9 +16,7 @@ public class CompareCommand : Command<CompareCommand.Settings>
public required string SolutionFilePath { get; set; }
[CommandOption("-l|--logprojectfiles")]
[Description(
"true to enable log output of all project files found in folder. Default is false."
)]
[Description("true to enable log output of all project files found in folder. Default is false.")]
[DefaultValue(false)]
public bool LogAllProjectFileNames { get; set; } = false;
}
@@ -28,9 +27,7 @@ public class CompareCommand : Command<CompareCommand.Settings>
var pathToSolutionFile = settings.SolutionFilePath;
Console.WriteLine($"Retrieving C# Projects from {folderDirectory}");
var csprojList = SolutionProjectParity.RetrieveAllCSharpProjectNamesFromFolder(
folderDirectory
);
var csprojList = CsprojHelper.RetrieveAllCSharpProjectFullPathsFromFolder(folderDirectory);
if (settings.LogAllProjectFileNames)
{
@@ -45,12 +42,10 @@ public class CompareCommand : Command<CompareCommand.Settings>
Console.WriteLine($"Parsing Solution File: {pathToSolutionFile}");
// Load the solution file
var solutionFile = SolutionProjectParity.ParseSolutionFileFromPath(pathToSolutionFile);
var solutionFile = SlnHelper.ParseSolutionFileFromPath(pathToSolutionFile);
if (solutionFile == null)
{
Console.WriteLine(
"Failed to parse solution file. The file was either not found or malformed."
);
Console.WriteLine("Failed to parse solution file. The file was either not found or malformed.");
return 1;
}
@@ -61,9 +56,7 @@ public class CompareCommand : Command<CompareCommand.Settings>
);
Console.WriteLine("==================================================");
Console.WriteLine(
$"Missing {projectsMissingFromSolution.Count} C# Projects from Solution File"
);
Console.WriteLine($"Missing {projectsMissingFromSolution.Count} C# Projects from Solution File");
foreach (var project in projectsMissingFromSolution)
{

View File

@@ -1,4 +1,5 @@
using DotNetSolutionTools.Core;
using DotNetSolutionTools.Core.Common;
using Spectre.Console.Cli;
namespace DotNetSolutionTools.CLI.Commands;
@@ -29,17 +30,13 @@ public class FormatCsprojCommand : Command<FormatCsprojCommand.Settings>
}
else if (!string.IsNullOrWhiteSpace(settings.SolutionFilePath))
{
var test = SolutionProjectParity.ParseSolutionFileFromPath(settings.SolutionFilePath);
var test = SlnHelper.ParseSolutionFileFromPath(settings.SolutionFilePath);
if (test == null)
{
Console.WriteLine(
"Failed to parse solution file. The file was either not found or malformed."
);
Console.WriteLine("Failed to parse solution file. The file was either not found or malformed.");
return 1;
}
var cSharpProjects = SolutionProjectParity.GetCSharpProjectObjectsFromSolutionFile(
test
);
var cSharpProjects = SlnHelper.GetCSharpProjectObjectsFromSolutionFile(test);
Console.WriteLine($"Found {cSharpProjects.Count} C# Projects");
Console.WriteLine("==================================================");
foreach (var project in cSharpProjects)
@@ -54,9 +51,7 @@ public class FormatCsprojCommand : Command<FormatCsprojCommand.Settings>
var folderDirectory = settings.SolutionFolderPath; // Include the trailing slash
Console.WriteLine($"Retrieving C# Projects from {folderDirectory}");
var csprojList = SolutionProjectParity.RetrieveAllCSharpProjectFullPathsFromFolder(
folderDirectory
);
var csprojList = CsprojHelper.RetrieveAllCSharpProjectFullPathsFromFolder(folderDirectory);
Console.WriteLine($"Retrieved {csprojList.Length} C# Projects");
Console.WriteLine("==================================================");
@@ -70,9 +65,7 @@ public class FormatCsprojCommand : Command<FormatCsprojCommand.Settings>
}
else
{
Console.WriteLine(
"No arguments were provided. Please provide a csproj, folder, or solution file."
);
Console.WriteLine("No arguments were provided. Please provide a csproj, folder, or solution file.");
return 1;
}
}

View File

@@ -1,5 +1,6 @@
using System.ComponentModel;
using DotNetSolutionTools.Core;
using DotNetSolutionTools.Core.Common;
using Spectre.Console.Cli;
namespace DotNetSolutionTools.CLI.Commands;
@@ -17,9 +18,7 @@ public class ImplicitUsingsCommand : Command<ImplicitUsingsCommand.Settings>
public bool AddMissing { get; set; } = false;
[CommandOption("-d|--enable-disabled")]
[Description(
"Sets Implicit Usings to true for any projects with it disabled. Default is false."
)]
[Description("Sets Implicit Usings to true for any projects with it disabled. Default is false.")]
[DefaultValue(false)]
public bool EnableDisabled { get; set; } = false;
@@ -34,24 +33,18 @@ public class ImplicitUsingsCommand : Command<ImplicitUsingsCommand.Settings>
var pathToSolutionFile = settings.SolutionFilePath;
Console.WriteLine($"Retrieving Solution from {pathToSolutionFile}");
var solutionFile = SolutionProjectParity.ParseSolutionFileFromPath(pathToSolutionFile);
var solutionFile = SlnHelper.ParseSolutionFileFromPath(pathToSolutionFile);
if (solutionFile == null)
{
Console.WriteLine(
"Failed to parse solution file. The file was either not found or malformed."
);
Console.WriteLine("Failed to parse solution file. The file was either not found or malformed.");
return 1;
}
var cSharpProjects = SolutionProjectParity.GetCSharpProjectObjectsFromSolutionFile(
solutionFile
);
var cSharpProjects = SlnHelper.GetCSharpProjectObjectsFromSolutionFile(solutionFile);
Console.WriteLine($"Found {cSharpProjects.Count} C# Projects");
Console.WriteLine("==================================================");
// Get the list of projects
var projectsMissingImplicitUsings = ImplicitUsings.FindCSharpProjectsMissingImplicitUsings(
cSharpProjects
);
var projectsMissingImplicitUsings = ImplicitUsings.FindCSharpProjectsMissingImplicitUsings(cSharpProjects);
Console.WriteLine(
$"{projectsMissingImplicitUsings.Count} C# Projects have missing or disabled implicit usings"
@@ -67,12 +60,8 @@ public class ImplicitUsingsCommand : Command<ImplicitUsingsCommand.Settings>
Console.WriteLine("==================================================");
Console.WriteLine("Adding missing implicit usings");
ImplicitUsings.AddMissingImplicitUsings(projectsMissingImplicitUsings);
var updatedProjects = SolutionProjectParity.GetCSharpProjectObjectsFromSolutionFile(
solutionFile
);
var projectsWithMissing = ImplicitUsings.FindCSharpProjectsMissingImplicitUsings(
updatedProjects
);
var updatedProjects = SlnHelper.GetCSharpProjectObjectsFromSolutionFile(solutionFile);
var projectsWithMissing = ImplicitUsings.FindCSharpProjectsMissingImplicitUsings(updatedProjects);
Console.WriteLine(
$"There are now {projectsWithMissing.Count} C# Projects missing/disabled implicit usings"
);

View File

@@ -1,5 +1,6 @@
using System.ComponentModel;
using DotNetSolutionTools.Core;
using DotNetSolutionTools.Core.Common;
using Spectre.Console.Cli;
namespace DotNetSolutionTools.CLI.Commands;
@@ -21,13 +22,13 @@ public class TreatWarningsAsErrorsCommand : Command<TreatWarningsAsErrorsCommand
var pathToSolutionFile = settings.SolutionFilePath;
Console.WriteLine($"Retrieving Solution from {pathToSolutionFile}");
var solutionFile = SolutionProjectParity.ParseSolutionFileFromPath(pathToSolutionFile);
var solutionFile = SlnHelper.ParseSolutionFileFromPath(pathToSolutionFile);
if (solutionFile == null)
{
Console.WriteLine("Failed to parse solution file. The file was either not found or malformed.");
return 1;
}
var cSharpProjects = SolutionProjectParity.GetCSharpProjectObjectsFromSolutionFile(solutionFile);
var cSharpProjects = SlnHelper.GetCSharpProjectObjectsFromSolutionFile(solutionFile);
Console.WriteLine($"Found {cSharpProjects.Count} C# Projects");
Console.WriteLine("==================================================");
@@ -45,7 +46,7 @@ public class TreatWarningsAsErrorsCommand : Command<TreatWarningsAsErrorsCommand
Console.WriteLine("==================================================");
Console.WriteLine("Adding missing Warnings As Errors");
WarningsAsErrors.AddMissingTreatWarningsAsErrors(projectsMissingTreatWarningsAsErrors);
var updatedProjects = SolutionProjectParity.GetCSharpProjectObjectsFromSolutionFile(solutionFile);
var updatedProjects = SlnHelper.GetCSharpProjectObjectsFromSolutionFile(solutionFile);
var projectsWithMissing = WarningsAsErrors.FindCSharpProjectsMissingTreatWarningsAsErrors(updatedProjects);
Console.WriteLine(
$"There are now {projectsWithMissing.Count} C# Projects missing Treat Warnings As Errors"

View File

@@ -0,0 +1,29 @@
using DotNetSolutionTools.Core;
using Spectre.Console.Cli;
namespace DotNetSolutionTools.CLI.Commands;
public class UpdateProjectToNet80Command : Command<UpdateProjectToNet80Command.Settings>
{
public sealed class Settings : CommandSettings
{
[CommandArgument(1, "<CsprojFilePath>")]
public required string CsprojFilePath { get; set; }
}
public override int Execute(CommandContext context, Settings settings)
{
// validate a real folder path was passed in
if (!Directory.Exists(settings.CsprojFilePath))
{
Console.WriteLine("Invalid folder path");
return 1;
}
Console.WriteLine("Deleting bin, obj, and node_modules folders");
CleanFolder.DeleteBinObjAndNodeModulesFoldersInFolder(settings.CsprojFilePath);
Console.WriteLine("==================================================");
Console.WriteLine("Done!");
return 0;
}
}