mycroforge/MycroForge.CLI/Commands/MycroForge.Uninstall.cs

32 lines
1.0 KiB
C#

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