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

37 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.CommandLine;
using MycroForge.Core;
using MycroForge.Core.Contract;
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 static readonly Option<bool> YesOption =
new(aliases: ["-y", "--yes"], description: "Dont ask for confirmation of uninstall deletions");
private readonly ProjectContext _context;
public Uninstall(ProjectContext context) : base("uninstall", "Uninstall packages and update the requirements.txt")
{
_context = context;
AddAlias("u");
AddArgument(PackagesArgument);
AddOption(YesOption);
this.SetHandler(ExecuteAsync, PackagesArgument, YesOption);
}
private async Task ExecuteAsync(IEnumerable<string> packages, bool yes)
{
await _context.Bash(
"source .venv/bin/activate",
$"pip uninstall{(yes ? " --yes " : " ")}{string.Join(' ', packages)}",
"pip freeze > requirements.txt"
);
}
}
}