mycroforge/MicroForge.CLI/Commands/MicroForge.Uninstall.cs
2024-04-21 23:56:27 +02:00

29 lines
970 B
C#

using System.CommandLine;
using MicroForge.CLI.Commands.Interfaces;
namespace MicroForge.CLI.Commands;
public partial class MicroForge
{
public class Uninstall : Command, ISubCommandOf<MicroForge>
{
private static readonly Argument<IEnumerable<string>> PackagesArgument =
new(name: "packages", description: "The names of the packages to uninstall");
public Uninstall() : base("uninstall", "Uninstall packages and update the requirements.txt")
{
AddAlias("u");
AddArgument(PackagesArgument);
this.SetHandler(ExecuteAsync, PackagesArgument);
}
private async Task ExecuteAsync(IEnumerable<string> packages)
{
await Bash.ExecuteAsync(
"source .venv/bin/activate",
$"pip uninstall {string.Join(' ', packages)}",
"pip freeze > requirements.txt"
);
}
}
}