Skip to content

Commit

Permalink
Environment.GetCommandLineArgs() includes the executable itself as th…
Browse files Browse the repository at this point in the history
…e first argument, which breaks System.CommandLine on Linux. Workaround is to use Environment.GetCommandLineArgs().Skip(1).ToArray() per dotnet/runtime#36566.
  • Loading branch information
KyleKolander committed Oct 31, 2021
1 parent 18559c6 commit fc533a1
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions src/Summarizer/Summarizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,32 @@ namespace NuGetUtilities.Summarizer
[ExcludeFromCodeCoverage]
public class Summarizer : IHostedService
{
public Summarizer(ILogger<Summarizer> logger
public Summarizer(ILogger<Summarizer> logger
, IHostApplicationLifetime appLifetime
, PackageRetriever packageRetriever
, PackageInstaller packageInstaller
, PackageReader packageReader
, DependencyTreeBuilder dependencyTreeBuilder)
, PackageRetriever packageRetriever
, PackageInstaller packageInstaller
, PackageReader packageReader
, DependencyTreeBuilder dependencyTreeBuilder)
{
Logger = logger;
AppLifetime = appLifetime;
PackageRetriever = packageRetriever;
PackageInstaller = packageInstaller;
PackageReader = packageReader;
Logger = logger;
AppLifetime = appLifetime;
PackageRetriever = packageRetriever;
PackageInstaller = packageInstaller;
PackageReader = packageReader;
DependencyTreeBuilder = dependencyTreeBuilder;
}

private ILogger<Summarizer> Logger { get; }
private IHostApplicationLifetime AppLifetime { get; }
private PackageRetriever PackageRetriever { get; }
public PackageInstaller PackageInstaller { get; }
public PackageReader PackageReader { get; }
private DependencyTreeBuilder DependencyTreeBuilder { get; }
private int ExitCode { get; set; }
private ILogger<Summarizer> Logger { get; }
private IHostApplicationLifetime AppLifetime { get; }
private PackageRetriever PackageRetriever { get; }
public PackageInstaller PackageInstaller { get; }
public PackageReader PackageReader { get; }
private DependencyTreeBuilder DependencyTreeBuilder { get; }
private int ExitCode { get; set; }

public Task StartAsync(CancellationToken cancellationToken)
{
Logger.LogDebug($"Starting with arguments: {string.Join(" ", Environment.GetCommandLineArgs())}");
Logger.LogDebug($"Starting with arguments: {string.Join(" ", Environment.GetCommandLineArgs().Skip(1).ToArray())}");

// "commandLineArgs": "--id MailKit --version 2.15.0 --framework net5.0 --install --transitive --tree --contents --assemblies --powerShell",

Expand Down Expand Up @@ -86,8 +86,8 @@ public Task StopAsync(CancellationToken cancellationToken)
, new Option<bool>("--powerShell", "Flag indicating whether to display the PowerShell commands needed to use the specified NuGet package")
};
rootCommand.Description = "NuGet package summarizer";
rootCommand.Handler = CommandHandler.Create<string, string, string, string, bool, bool, bool, bool, bool, bool>(Run);
await rootCommand.InvokeAsync(Environment.GetCommandLineArgs());
rootCommand.Handler = CommandHandler.Create<string, string, string, string, bool, bool, bool, bool, bool, bool>(Run);
await rootCommand.InvokeAsync(Environment.GetCommandLineArgs().Skip(1).ToArray());
}
catch (Exception e)
{
Expand Down Expand Up @@ -141,27 +141,27 @@ public async Task Run(string id, string version, string framework, string nupkg,
Logger.LogDebug("--contents specified but not --install, which is a prerequisite, so adding --install");
}

var nuGetFramework = NuGetFramework.ParseFolder(framework);
Package package;
var nuGetFramework = NuGetFramework.ParseFolder(framework);
Package package;
PackageIdentity packageIdentity;

if (string.IsNullOrWhiteSpace(nupkg))
{
packageIdentity = new(id, NuGetVersion.Parse(version));
package = await HandleRetrieve(packageIdentity, nuGetFramework);
package = await HandleRetrieve(packageIdentity, nuGetFramework);
}
else
{
package = await PackageInstaller.Install(nupkg, nuGetFramework, CancellationToken.None);
package = await PackageInstaller.Install(nupkg, nuGetFramework, CancellationToken.None);
packageIdentity = package.PackageIdentity;
}

var transitiveDependencies = await HandleTransitiveDependencies(transitive, package, nuGetFramework);
var rootNode = HandleTree(tree, transitive, package, transitiveDependencies);
var installedPackages = await HandleInstall(install, package, transitiveDependencies);
var transitiveDependencies = await HandleTransitiveDependencies(transitive, package, nuGetFramework);
var rootNode = HandleTree(tree, transitive, package, transitiveDependencies);
var installedPackages = await HandleInstall(install, package, transitiveDependencies);
var installedPackageContents = HandleContents(contents, installedPackages);
var assemblyItems = HandleAssemblies(assemblies, installedPackageContents);
var powerShellCommands = HandlePowerShell(powerShell, package, installedPackageContents);
var assemblyItems = HandleAssemblies(assemblies, installedPackageContents);
var powerShellCommands = HandlePowerShell(powerShell, package, installedPackageContents);
}

private async Task<Package> HandleRetrieve(PackageIdentity packageIdentity, NuGetFramework nuGetFramework)
Expand Down

0 comments on commit fc533a1

Please sign in to comment.