Rename
This commit is contained in:
76
DotNetSolutionTools.CLI/Commands/CompareCommand.cs
Normal file
76
DotNetSolutionTools.CLI/Commands/CompareCommand.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System.ComponentModel;
|
||||
using DotNetSolutionTools.Core;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace DotNetSolutionTools.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 log output of all project files found in folder. 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;
|
||||
}
|
||||
}
|
||||
79
DotNetSolutionTools.CLI/Commands/FormatCsprojCommand.cs
Normal file
79
DotNetSolutionTools.CLI/Commands/FormatCsprojCommand.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using DotNetSolutionTools.Core;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace DotNetSolutionTools.CLI.Commands;
|
||||
|
||||
public class FormatCsprojCommand : Command<FormatCsprojCommand.Settings>
|
||||
{
|
||||
public sealed class Settings : CommandSettings
|
||||
{
|
||||
[CommandOption("--project <CsprojFilePath>")]
|
||||
public string? CsprojFilePath { get; set; }
|
||||
|
||||
[CommandOption("--folder <SolutionFolderPath>")]
|
||||
public string? SolutionFolderPath { get; set; }
|
||||
|
||||
[CommandOption("--sln <SolutionFilePath>")]
|
||||
public string? SolutionFilePath { get; set; }
|
||||
}
|
||||
|
||||
public override int Execute(CommandContext context, Settings settings)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(settings.CsprojFilePath))
|
||||
{
|
||||
var pathToCsprojFile = settings.CsprojFilePath;
|
||||
Console.WriteLine($"Retrieving C# Project from {pathToCsprojFile}");
|
||||
FormatCsproj.FormatCsprojFile(pathToCsprojFile);
|
||||
Console.WriteLine("Done!");
|
||||
return 0;
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(settings.SolutionFilePath))
|
||||
{
|
||||
var test = SolutionParityChecker.ParseSolutionFileFromPath(settings.SolutionFilePath);
|
||||
if (test == null)
|
||||
{
|
||||
Console.WriteLine(
|
||||
"Failed to parse solution file. The file was either not found or malformed."
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
var cSharpProjects = SolutionParityChecker.GetCSharpProjectObjectsFromSolutionFile(
|
||||
test
|
||||
);
|
||||
Console.WriteLine($"Found {cSharpProjects.Count} C# Projects");
|
||||
Console.WriteLine("==================================================");
|
||||
foreach (var project in cSharpProjects)
|
||||
{
|
||||
FormatCsproj.FormatCsprojFile(project.FullPath);
|
||||
}
|
||||
Console.WriteLine("Done!");
|
||||
return 0;
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(settings.SolutionFolderPath))
|
||||
{
|
||||
var folderDirectory = settings.SolutionFolderPath; // Include the trailing slash
|
||||
Console.WriteLine($"Retrieving C# Projects from {folderDirectory}");
|
||||
|
||||
var csprojList = SolutionParityChecker.RetrieveAllCSharpProjectFullPathsFromFolder(
|
||||
folderDirectory
|
||||
);
|
||||
|
||||
Console.WriteLine($"Retrieved {csprojList.Length} C# Projects");
|
||||
Console.WriteLine("==================================================");
|
||||
|
||||
foreach (var project in csprojList)
|
||||
{
|
||||
FormatCsproj.FormatCsprojFile(project);
|
||||
}
|
||||
Console.WriteLine("Done!");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(
|
||||
"No arguments were provided. Please provide a csproj, folder, or solution file."
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
96
DotNetSolutionTools.CLI/Commands/ImplicitUsingsCommand.cs
Normal file
96
DotNetSolutionTools.CLI/Commands/ImplicitUsingsCommand.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System.ComponentModel;
|
||||
using DotNetSolutionTools.Core;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace DotNetSolutionTools.CLI.Commands;
|
||||
|
||||
public class ImplicitUsingsCommand : Command<ImplicitUsingsCommand.Settings>
|
||||
{
|
||||
public sealed class Settings : CommandSettings
|
||||
{
|
||||
[CommandArgument(1, "<SolutionFilePath>")]
|
||||
public required string SolutionFilePath { get; set; }
|
||||
|
||||
[CommandOption("-m|--add-missing")]
|
||||
[Description("Add Implicit Usings=true to projects missing them. Default is false.")]
|
||||
[DefaultValue(false)]
|
||||
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."
|
||||
)]
|
||||
[DefaultValue(false)]
|
||||
public bool EnableDisabled { get; set; } = false;
|
||||
|
||||
[CommandOption("-a|--enable-all")]
|
||||
[Description("Enables Implicit Usings for all projects. Default is false.")]
|
||||
[DefaultValue(false)]
|
||||
public bool EnableAll { get; set; } = false;
|
||||
}
|
||||
|
||||
public override int Execute(CommandContext context, Settings settings)
|
||||
{
|
||||
var pathToSolutionFile = settings.SolutionFilePath;
|
||||
Console.WriteLine($"Retrieving Solution from {pathToSolutionFile}");
|
||||
|
||||
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;
|
||||
}
|
||||
var cSharpProjects = SolutionParityChecker.GetCSharpProjectObjectsFromSolutionFile(
|
||||
solutionFile
|
||||
);
|
||||
Console.WriteLine($"Found {cSharpProjects.Count} C# Projects");
|
||||
Console.WriteLine("==================================================");
|
||||
|
||||
// Get the list of projects
|
||||
var projectsMissingImplicitUsings = ImplicitUsings.FindCSharpProjectsMissingImplicitUsings(
|
||||
cSharpProjects
|
||||
);
|
||||
|
||||
Console.WriteLine(
|
||||
$"{projectsMissingImplicitUsings.Count} C# Projects have missing or disabled implicit usings"
|
||||
);
|
||||
|
||||
foreach (var project in projectsMissingImplicitUsings)
|
||||
{
|
||||
Console.WriteLine(project.DirectoryPath);
|
||||
}
|
||||
|
||||
if (settings.AddMissing)
|
||||
{
|
||||
Console.WriteLine("==================================================");
|
||||
Console.WriteLine("Adding missing implicit usings");
|
||||
ImplicitUsings.AddMissingImplicitUsings(projectsMissingImplicitUsings);
|
||||
var updatedProjects = SolutionParityChecker.GetCSharpProjectObjectsFromSolutionFile(
|
||||
solutionFile
|
||||
);
|
||||
var projectsWithMissing = ImplicitUsings.FindCSharpProjectsMissingImplicitUsings(
|
||||
updatedProjects
|
||||
);
|
||||
Console.WriteLine(
|
||||
$"There are now {projectsWithMissing.Count} C# Projects missing/disabled implicit usings"
|
||||
);
|
||||
}
|
||||
if (settings.EnableDisabled)
|
||||
{
|
||||
Console.WriteLine("==================================================");
|
||||
Console.WriteLine("Enabling disabled implicit usings");
|
||||
ImplicitUsings.EnableDisabledImplicitUsings(projectsMissingImplicitUsings);
|
||||
}
|
||||
if (settings.EnableAll)
|
||||
{
|
||||
Console.WriteLine("==================================================");
|
||||
Console.WriteLine("Enabling all implicit usings");
|
||||
ImplicitUsings.EnableAllImplicitUsings(projectsMissingImplicitUsings);
|
||||
}
|
||||
Console.WriteLine("==================================================");
|
||||
Console.WriteLine("Done!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user