-
Notifications
You must be signed in to change notification settings - Fork 753
[Feature]Add package download command
#6804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Nigusu-Allehu
merged 15 commits into
dev-feature-package-download
from
dev-nyenework-packagedownload
Oct 28, 2025
Merged
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f29e88b
start
Nigusu-Allehu b4d4d4a
More tests
Nigusu-Allehu 8266c93
Add parsing tests
Nigusu-Allehu acd8708
Cleanup
Nigusu-Allehu 8d14247
oops
Nigusu-Allehu 6345503
cleanup
Nigusu-Allehu ca34b33
move func tests
Nigusu-Allehu 8472caf
Simplify
Nigusu-Allehu 3f79933
undo
Nigusu-Allehu aac5448
unlisted
Nigusu-Allehu b075e4c
more test
Nigusu-Allehu 149339e
more test
Nigusu-Allehu 203f7fa
more test
Nigusu-Allehu 0b9925d
fix
Nigusu-Allehu 14332c6
different ids
Nigusu-Allehu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Download/PackageDownloadArgs.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
|
||
| #nullable enable | ||
|
|
||
| using System.Collections.Generic; | ||
| using NuGet.Common; | ||
|
|
||
| namespace NuGet.CommandLine.XPlat.Commands.Package.PackageDownload; | ||
|
|
||
| internal record PackageDownloadArgs | ||
| { | ||
| public IReadOnlyList<PackageWithNuGetVersion>? Packages { get; set; } | ||
| public IList<string>? Sources { get; set; } | ||
| public string? OutputDirectory { get; set; } | ||
| public string? ConfigFile { get; set; } | ||
|
Nigusu-Allehu marked this conversation as resolved.
|
||
| public bool IncludePrerelease { get; set; } | ||
| public bool AllowInsecureConnections { get; set; } | ||
| public bool Interactive { get; set; } | ||
| public LogLevel LogLevel { get; set; } | ||
| } | ||
97 changes: 97 additions & 0 deletions
97
src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Package/Download/PackageDownloadCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.CommandLine; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace NuGet.CommandLine.XPlat.Commands.Package.PackageDownload | ||
| { | ||
| internal class PackageDownloadCommand | ||
| { | ||
| internal static void Register(Command packageCommand, Option<bool> interactiveOption) | ||
| { | ||
| Register(packageCommand, interactiveOption, PackageDownloadRunner.RunAsync); | ||
| } | ||
|
Nigusu-Allehu marked this conversation as resolved.
|
||
|
|
||
| public static void Register(Command packageCommand, Option<bool> interactiveOption, Func<PackageDownloadArgs, CancellationToken, Task<int>> action) | ||
| { | ||
| var downloadCommand = new DocumentedCommand( | ||
| "download", | ||
| Strings.PackageDownloadCommand_descritpion, | ||
|
Nigusu-Allehu marked this conversation as resolved.
Outdated
|
||
| "https://aka.ms/dotnet/package/download"); | ||
|
|
||
| // Arguments | ||
| var packagesArguments = new Argument<IReadOnlyList<PackageWithNuGetVersion>>("packages") | ||
| { | ||
| Description = Strings.PackageUpdate_PackageArgumentDescription, | ||
| Arity = ArgumentArity.OneOrMore, | ||
| CustomParser = PackageWithNuGetVersion.Parse | ||
| }; | ||
|
|
||
| // Options | ||
| var allowInsecureConnections = new Option<bool>("--allow-insecure-connections") | ||
| { | ||
| Description = Strings.PackageDownloadCommand_AllowInsecureConnectionsDescritption, | ||
|
Nigusu-Allehu marked this conversation as resolved.
Outdated
|
||
| Arity = ArgumentArity.Zero | ||
| }; | ||
|
|
||
| var configFile = new Option<string>("--configfile") | ||
| { | ||
| Description = Strings.Option_ConfigFile, | ||
| Arity = ArgumentArity.ExactlyOne | ||
| }; | ||
|
|
||
| var outputDirectory = new Option<string>("--output", "-o") | ||
|
Nigusu-Allehu marked this conversation as resolved.
|
||
| { | ||
| Description = Strings.PackageDownloadCommand_OutputDirectoryDescription, | ||
| Arity = ArgumentArity.ExactlyOne | ||
| }; | ||
|
|
||
| var prerelease = new Option<bool>("--prerelease") | ||
| { | ||
| Description = Strings.Prerelease_Description, | ||
| Arity = ArgumentArity.Zero | ||
| }; | ||
|
|
||
| var sources = new Option<List<string>>("--source", "-s") | ||
| { | ||
| Description = Strings.PackageDownloadCommand_SourcesDescription, | ||
| Arity = ArgumentArity.OneOrMore | ||
| }; | ||
|
|
||
| var verbosity = CommonOptions.GetVerbosityOption(); | ||
|
|
||
| downloadCommand.Arguments.Add(packagesArguments); | ||
| downloadCommand.Options.Add(allowInsecureConnections); | ||
| downloadCommand.Options.Add(configFile); | ||
| downloadCommand.Options.Add(interactiveOption); | ||
| downloadCommand.Options.Add(outputDirectory); | ||
| downloadCommand.Options.Add(prerelease); | ||
| downloadCommand.Options.Add(sources); | ||
| downloadCommand.Options.Add(verbosity); | ||
|
|
||
| downloadCommand.SetAction(async (parserResult, cancellationToken) => | ||
| { | ||
| IReadOnlyList<PackageWithNuGetVersion> packages = parserResult.GetValue(packagesArguments) ?? []; | ||
| var args = new PackageDownloadArgs() | ||
| { | ||
| Packages = packages, | ||
| Sources = parserResult.GetValue(sources), | ||
| OutputDirectory = parserResult.GetValue(outputDirectory), | ||
| IncludePrerelease = parserResult.GetValue(prerelease), | ||
| AllowInsecureConnections = parserResult.GetValue(allowInsecureConnections), | ||
| Interactive = parserResult.GetValue(interactiveOption), | ||
| ConfigFile = parserResult.GetValue(configFile), | ||
| LogLevel = (parserResult.GetValue(verbosity) ?? VerbosityEnum.normal).ToLogLevel() | ||
| }; | ||
|
|
||
| return await action(args, cancellationToken); | ||
| }); | ||
|
|
||
| packageCommand.Subcommands.Add(downloadCommand); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.