Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 19 additions & 36 deletions src/NuGetMirror/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using NuGetMirror;
using McMaster.Extensions.CommandLineUtils;
using NuGet.Common;
using NuGet.Protocol;
Expand All @@ -14,35 +13,35 @@ public static class Program
{
public static int Main(string[] args)
{
var logLevel = LogLevel.Information;
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

if (CmdUtils.IsDebugModeEnabled())
{
logLevel = LogLevel.Debug;
}
var logLevel = CmdUtils.IsDebugModeEnabled()
? LogLevel.Debug
: LogLevel.Information;

var log = new ConsoleLogger(logLevel);

var task = MainCore(args, log);
return task.Result;
return MainCore(args, log).GetAwaiter().GetResult();
}

public static Task<int> MainCore(string[] args, ILogger log)
public static async Task<int> MainCore(string[] args, ILogger log)
{
return MainCore(args, httpSource: null, log: log);
return await MainCore(args, httpSource: null, log: log);
}

public static Task<int> MainCore(string[] args, HttpSource? httpSource, ILogger log)
public static async Task<int> MainCore(string[] args, HttpSource? httpSource, ILogger log)
{
CmdUtils.LaunchDebuggerIfSet(ref args, log);

var app = new CommandLineApplication()
var app = new CommandLineApplication
{
Name = "NuGetMirror",
FullName = "nuget mirror"
};

app.HelpOption(Constants.HelpOption);
app.VersionOption("--version", (new NuGetVersion(CmdUtils.GetAssemblyVersion())).ToNormalizedString());
app.VersionOption("--version",
new NuGetVersion(CmdUtils.GetAssemblyVersion()).ToNormalizedString());
app.Description = "Mirror a nuget v3 feed.";

Configure();
Expand All @@ -56,44 +55,28 @@ public static Task<int> MainCore(string[] args, HttpSource? httpSource, ILogger
return 1;
});

var exitCode = 1;

try
{
exitCode = app.Execute(args);
return await Task.FromResult(app.Execute(args));
}
Comment on lines 58 to 61

Copilot AI Mar 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MainCore is marked async but only awaits Task.FromResult(app.Execute(args)), which is a synchronous operation. This adds an unnecessary async state machine/await without providing actual asynchrony; consider either (a) making this method non-async again and returning Task.FromResult(app.Execute(args)), or (b) switching to a truly async execution path if the CLI library supports it.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

catch (CommandParsingException ex)
{
ex.Command.ShowHelp();
ex.Command?.ShowHelp();
return 1;
}
catch (Exception ex)
{
ExceptionUtils.LogException(ex, log);
return 1;
}

return Task.FromResult(exitCode);
}

private static void Configure()
{
#if NET6_0 || NET8_0
// Set connection limit
if (!RuntimeEnvironmentHelper.IsMono)
{
ServicePointManager.DefaultConnectionLimit = 64;
}
else
{
// Keep mono limited to a single download to avoid issues.
ServicePointManager.DefaultConnectionLimit = 1;
}

// Limit SSL
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
#endif
// Настройки для .NET 8/9/10

var userAgent = new UserAgentStringBuilder("NuGetMirror");
UserAgent.SetUserAgentString(userAgent);
}
}
}
}