From 3f5905349d815095133617a4d7f945a4077dc7d7 Mon Sep 17 00:00:00 2001 From: "Matthew Parker [SSW]" <61717342+MattParkerDev@users.noreply.github.com> Date: Sun, 21 Jan 2024 14:47:49 +1000 Subject: [PATCH] add clean folder to cli --- .gitignore | 2 ++ .../Commands/ClearBinObjCommand.cs | 30 +++++++++++++++++++ DotNetSolutionTools.CLI/Program.cs | 1 + 3 files changed, 33 insertions(+) create mode 100644 DotNetSolutionTools.CLI/Commands/ClearBinObjCommand.cs diff --git a/.gitignore b/.gitignore index f5e6c0a..b4e2a7c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ ## ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore +.config/dotnet-tools.json + # User-specific files *.rsuser *.suo diff --git a/DotNetSolutionTools.CLI/Commands/ClearBinObjCommand.cs b/DotNetSolutionTools.CLI/Commands/ClearBinObjCommand.cs new file mode 100644 index 0000000..2dfe643 --- /dev/null +++ b/DotNetSolutionTools.CLI/Commands/ClearBinObjCommand.cs @@ -0,0 +1,30 @@ +using System.ComponentModel; +using DotNetSolutionTools.Core; +using Spectre.Console.Cli; + +namespace DotNetSolutionTools.CLI.Commands; + +public class ClearBinObjCommand : Command +{ + public sealed class Settings : CommandSettings + { + [CommandArgument(1, "")] + 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; + } +} diff --git a/DotNetSolutionTools.CLI/Program.cs b/DotNetSolutionTools.CLI/Program.cs index 1797cb6..94064f8 100644 --- a/DotNetSolutionTools.CLI/Program.cs +++ b/DotNetSolutionTools.CLI/Program.cs @@ -12,6 +12,7 @@ app.Configure(config => config.AddCommand("implicit-usings"); config.AddCommand("format-csproj"); config.AddCommand("warnings-as-errors"); + config.AddCommand("clear-bin-obj"); }); var instance = MSBuildLocator.QueryVisualStudioInstances().OrderByDescending(instance => instance.Version).First();