Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
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
Comment thread
Nigusu-Allehu marked this conversation as resolved.
{
public IReadOnlyList<PackageWithNuGetVersion>? Packages { get; set; }
public IList<string>? Sources { get; set; }
public string? OutputDirectory { get; set; }
public string? ConfigFile { get; set; }
Comment thread
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; }
}
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);
}
Comment thread
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,
Comment thread
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,
Comment thread
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")
Comment thread
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);
}
}
}
Loading