add clean folder to cli

This commit is contained in:
Matthew Parker [SSW]
2024-01-21 14:47:49 +10:00
parent a9f9aa1834
commit 3f5905349d
3 changed files with 33 additions and 0 deletions

2
.gitignore vendored
View File

@@ -3,6 +3,8 @@
## ##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
.config/dotnet-tools.json
# User-specific files # User-specific files
*.rsuser *.rsuser
*.suo *.suo

View File

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

View File

@@ -12,6 +12,7 @@ app.Configure(config =>
config.AddCommand<ImplicitUsingsCommand>("implicit-usings"); config.AddCommand<ImplicitUsingsCommand>("implicit-usings");
config.AddCommand<FormatCsprojCommand>("format-csproj"); config.AddCommand<FormatCsprojCommand>("format-csproj");
config.AddCommand<TreatWarningsAsErrorsCommand>("warnings-as-errors"); config.AddCommand<TreatWarningsAsErrorsCommand>("warnings-as-errors");
config.AddCommand<ClearBinObjCommand>("clear-bin-obj");
}); });
var instance = MSBuildLocator.QueryVisualStudioInstances().OrderByDescending(instance => instance.Version).First(); var instance = MSBuildLocator.QueryVisualStudioInstances().OrderByDescending(instance => instance.Version).First();