mycroforge/MycroForge.CLI/Commands/MycroForge.Install.cs
mdnapo 02a82589ae - Refactored init & features
- Extended documentation
2024-07-14 22:27:32 +02:00

42 lines
1.3 KiB
C#

using System.CommandLine;
using MycroForge.Core;
using MycroForge.Core.Contract;
namespace MycroForge.CLI.Commands;
public partial class MycroForge
{
public class Install : Command, ISubCommandOf<MycroForge>
{
private static readonly Argument<IEnumerable<string>> PackagesArgument =
new(name: "packages", description: "The names of the packages to install");
private readonly ProjectContext _context;
public Install(ProjectContext context) :
base("install", "Install packages and update the requirements.txt")
{
_context = context;
AddAlias("i");
AddArgument(PackagesArgument);
this.SetHandler(ExecuteAsync, PackagesArgument);
}
private async Task ExecuteAsync(IEnumerable<string> packages)
{
var packs = packages.ToArray();
if (packs.Length == 0)
{
Console.WriteLine("m4g install requires at least one package.");
return;
}
await _context.Bash(
"source .venv/bin/activate",
$"pip install {string.Join(' ', packs)}",
"pip freeze > requirements.txt"
);
}
}
}