Skip to content

Commit

Permalink
Add paket add/remove command support
Browse files Browse the repository at this point in the history
  • Loading branch information
BlythMeister committed May 28, 2020
1 parent 4327ccc commit 7beb353
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/PaketChain/Runner.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;

Expand Down Expand Up @@ -54,7 +55,7 @@ public static int Start(RunnerArgs runnerArgs, CancellationToken cancellationTok
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine($"Done at {DateTime.UtcNow:u}");
if (!runnerArgs.NoPrompt)
if (!runnerArgs.NoPrompt && !Debugger.IsAttached)
{
Console.WriteLine("Press Enter To Close...");
Console.ReadLine();
Expand Down Expand Up @@ -100,6 +101,44 @@ private static int Run(RunnerArgs runnerArgs, CancellationToken cancellationToke
if (cancellationToken.IsCancellationRequested) return -2;
}

if (!string.IsNullOrWhiteSpace(runnerArgs.AddPackage))
{
if (runnerArgs.AddProjects != null && runnerArgs.AddProjects.Any(x => !string.IsNullOrWhiteSpace(x)))
{
foreach (var addProject in runnerArgs.AddProjects.Where(x => !string.IsNullOrWhiteSpace(x)))
{
ConsoleHelper.RunPaketCommand(rootDir, paketPath, toolType, "add", $"{runnerArgs.AddPackage} --project {addProject} {runnerArgs.AddAdditionalArgs}", cancellationToken);
Console.WriteLine("-----------------------------------------------------");
if (cancellationToken.IsCancellationRequested) return -2;
}
}
else
{
ConsoleHelper.RunPaketCommand(rootDir, paketPath, toolType, "add", $"{runnerArgs.AddPackage} {runnerArgs.AddAdditionalArgs}", cancellationToken);
Console.WriteLine("-----------------------------------------------------");
if (cancellationToken.IsCancellationRequested) return -2;
}
}

if (!string.IsNullOrWhiteSpace(runnerArgs.RemovePackage))
{
if (runnerArgs.RemoveProjects != null && runnerArgs.RemoveProjects.Any(x => !string.IsNullOrWhiteSpace(x)))
{
foreach (var removeProject in runnerArgs.RemoveProjects.Where(x => !string.IsNullOrWhiteSpace(x)))
{
ConsoleHelper.RunPaketCommand(rootDir, paketPath, toolType, "remove", $"{runnerArgs.RemovePackage} --project {removeProject} {runnerArgs.RemoveAdditionalArgs}", cancellationToken);
Console.WriteLine("-----------------------------------------------------");
if (cancellationToken.IsCancellationRequested) return -2;
}
}
else
{
ConsoleHelper.RunPaketCommand(rootDir, paketPath, toolType, "remove", $"{runnerArgs.RemovePackage} {runnerArgs.RemoveAdditionalArgs}", cancellationToken);
Console.WriteLine("-----------------------------------------------------");
if (cancellationToken.IsCancellationRequested) return -2;
}
}

if (runnerArgs.Sort)
{
Sorter.SortReferences(rootDir);
Expand Down
18 changes: 18 additions & 0 deletions src/PaketChain/RunnerArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ internal class RunnerArgs
[Option("-ia|--install-args <ARGS>", "Args to pass to paket install (Note: <ARGS> should be in quotes)", CommandOptionType.SingleValue)]
public string InstallArgs { get; }

[Option("-a|--add <PackageName>", "Run a paket add for package", CommandOptionType.SingleValue)]
public string AddPackage { get; }

[Option("-ap|--add-project <ProjectName>", "Projects to add package to. (Requires -a/--add with package)", CommandOptionType.MultipleValue)]
public string[] AddProjects { get; }

[Option("-aa|--add-args <ARGS>", "Args to pass to paket add (Note: <ARGS> should be in quotes)", CommandOptionType.SingleValue)]
public string AddAdditionalArgs { get; }

[Option("-re|--remove <PackageName>", "Run a paket remove for package", CommandOptionType.SingleValue)]
public string RemovePackage { get; }

[Option("-rep|--remove-project <ProjectName>", "Projects to remove package from. (Requires -re/--remove with package) (Note: can be used multiple times for multiple projects)", CommandOptionType.MultipleValue)]
public string[] RemoveProjects { get; }

[Option("-rea|--remove-args <ARGS>", "Args to pass to paket remove (Note: <ARGS> should be in quotes)", CommandOptionType.SingleValue)]
public string RemoveAdditionalArgs { get; }

[Option("-r|--restore", "Run a paket restore", CommandOptionType.NoValue)]
public bool Restore { get; }

Expand Down

0 comments on commit 7beb353

Please sign in to comment.