Skip to content

Commit 4d184a2

Browse files
Use DotNet command template
1 parent 5546828 commit 4d184a2

File tree

4 files changed

+112
-95
lines changed

4 files changed

+112
-95
lines changed

Build/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225

226226
if (!string.IsNullOrWhiteSpace(apiKey) && packageVersion.Release != "dev" && packageVersion.Release != "dev")
227227
{
228-
var push = new DotNetNuGetPush().WithApiKey(apiKey).WithSources(defaultNuGetSource);
228+
var push = new DotNetNuGetPush().WithApiKey(apiKey).WithSource(defaultNuGetSource);
229229
foreach (var package in packages.Where(i => i.Publish))
230230
{
231231
push.WithPackage(package.Package)

CSharpInteractive.HostApi/DotNetNuGetPush.cs

Lines changed: 0 additions & 94 deletions
This file was deleted.

CSharpInteractive.HostApi/SimpleDotNetCommands.cs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,97 @@ public IStartInfo GetStartInfo(IHost host)
14321432
public override string ToString() => "".GetShortName(ShortName, "new", "update");
14331433
}
14341434

1435+
/// <summary>
1436+
/// Pushes a package to the server and publishes it. The dotnet nuget push command pushes a package to the server and publishes it. The push command uses server and credential details found in the system's NuGet config file or chain of config files. NuGet's default configuration is obtained by loading %AppData%\NuGet\NuGet.config (Windows) or $HOME/.nuget/NuGet/NuGet.Config (Linux/macOS), then loading any nuget.config or .nuget\nuget.config starting from the root of drive and ending in the current directory.
1437+
/// </summary>
1438+
/// <param name="Args">Specifies the set of command line arguments to use when starting the tool.</param>
1439+
/// <param name="Vars">Specifies the set of environment variables that apply to this process and its child processes.</param>
1440+
/// <param name="ExecutablePath">Overrides the tool executable path.</param>
1441+
/// <param name="WorkingDirectory">Specifies the working directory for the tool to be started.</param>
1442+
/// <param name="Package">Specifies the file path to the package to be pushed.</param>
1443+
/// <param name="DisableBuffering">Disables buffering when pushing to an HTTP(S) server to reduce memory usage.</param>
1444+
/// <param name="ForceEnglishOutput">Forces the application to run using an invariant, English-based culture.</param>
1445+
/// <param name="ApiKey">The API key for the server.</param>
1446+
/// <param name="NoSymbols">Doesn't push symbols (even if present).</param>
1447+
/// <param name="NoServiceEndpoint">Doesn't append "api/v2/package" to the source URL.</param>
1448+
/// <param name="Source">Specifies the server URL. NuGet identifies a UNC or local folder source and simply copies the file there instead of pushing it using HTTP.</param>
1449+
/// <param name="SkipDuplicate">When pushing multiple packages to an HTTP(S) server, treats any 409 Conflict response as a warning so that other pushes can continue.</param>
1450+
/// <param name="SymbolApiKey">The API key for the symbol server.</param>
1451+
/// <param name="SymbolSource">Specifies the symbol server URL.</param>
1452+
/// <param name="Timeout">Specifies the timeout for pushing to a server in seconds. Defaults to 300 seconds (5 minutes). Specifying 0 applies the default value.</param>
1453+
/// <param name="Verbosity">Sets the verbosity level of the command. Allowed values are <see cref="DotNetVerbosity.Quiet"/>, <see cref="DotNetVerbosity.Minimal"/>, <see cref="DotNetVerbosity.Normal"/>, <see cref="DotNetVerbosity.Detailed"/>, and <see cref="DotNetVerbosity.Diagnostic"/>. The default is <see cref="DotNetVerbosity.Minimal"/>. For more information, see <see cref="DotNetVerbosity"/>.</param>
1454+
/// <param name="Diagnostics">Enables diagnostic output.</param>
1455+
/// <param name="ShortName">Specifies a short name for this operation.</param>
1456+
[Target]
1457+
public partial record DotNetNuGetPush(
1458+
IEnumerable<string> Args,
1459+
IEnumerable<(string name, string value)> Vars,
1460+
string Package = "",
1461+
bool? DisableBuffering = default,
1462+
bool? ForceEnglishOutput = default,
1463+
string ApiKey = "",
1464+
bool? NoSymbols = default,
1465+
bool? NoServiceEndpoint = default,
1466+
string Source = "",
1467+
bool? SkipDuplicate = default,
1468+
string SymbolApiKey = "",
1469+
string SymbolSource = "",
1470+
int? Timeout = default,
1471+
DotNetVerbosity? Verbosity = default,
1472+
string ExecutablePath = "",
1473+
string WorkingDirectory = "",
1474+
bool? Diagnostics = default,
1475+
string ShortName = "")
1476+
{
1477+
/// <summary>
1478+
/// Create a new instance of the command.
1479+
/// </summary>
1480+
/// <param name="args">Specifies the set of command line arguments to use when starting the tool.</param>
1481+
public DotNetNuGetPush(params string[] args)
1482+
: this(args, [])
1483+
{
1484+
}
1485+
1486+
/// <summary>
1487+
/// Create a new instance of the command.
1488+
/// </summary>
1489+
public DotNetNuGetPush()
1490+
: this([], [])
1491+
{
1492+
}
1493+
1494+
/// <inheritdoc/>
1495+
public IStartInfo GetStartInfo(IHost host)
1496+
{
1497+
if (host == null) throw new ArgumentNullException(nameof(host));
1498+
return host.CreateCommandLine(ExecutablePath)
1499+
.WithShortName(ToString())
1500+
.WithWorkingDirectory(WorkingDirectory)
1501+
.WithVars(Vars.ToArray())
1502+
.AddArgs("nuget")
1503+
.AddArgs("push")
1504+
.AddNotEmptyArgs(Package)
1505+
.AddArgs(ApiKey.ToArgs("--api-key"))
1506+
.AddArgs(Source.ToArgs("--source"))
1507+
.AddArgs(SymbolApiKey.ToArgs("--symbol-api-key"))
1508+
.AddArgs(SymbolSource.ToArgs("--symbol-source"))
1509+
.AddArgs(Timeout.ToArgs("--timeout"))
1510+
.AddArgs(Verbosity.ToArgs("--verbosity"))
1511+
.AddBooleanArgs(
1512+
("--disable-buffering", DisableBuffering),
1513+
("--force-english-output", ForceEnglishOutput),
1514+
("--no-symbols", NoSymbols),
1515+
("--no-service-endpoint", NoServiceEndpoint),
1516+
("--skip-duplicate", SkipDuplicate),
1517+
("--diagnostics", Diagnostics)
1518+
)
1519+
.AddArgs(Args.ToArray());
1520+
}
1521+
1522+
/// <inheritdoc/>
1523+
public override string ToString() => "".GetShortName(ShortName, "nuget", "push", Package);
1524+
}
1525+
14351526
/// <summary>
14361527
/// Runs source code without any explicit compile or launch commands.
14371528
/// <example>

CSharpInteractive.HostApi/SimpleDotNetCommands.tt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,26 @@ namespace HostApi;
335335
],
336336
false, false
337337
),
338+
(
339+
"DotNetNuGetPush",
340+
["Pushes a package to the server and publishes it. The dotnet nuget push command pushes a package to the server and publishes it. The push command uses server and credential details found in the system's NuGet config file or chain of config files. NuGet's default configuration is obtained by loading %AppData%\\NuGet\\NuGet.config (Windows) or $HOME/.nuget/NuGet/NuGet.Config (Linux/macOS), then loading any nuget.config or .nuget\\nuget.config starting from the root of drive and ending in the current directory."],
341+
["nuget", "push", "$Package"],
342+
[
343+
("Package", "", "string", true, "Specifies the file path to the package to be pushed."),
344+
("DisableBuffering", "--disable-buffering", "bool?", false, "Disables buffering when pushing to an HTTP(S) server to reduce memory usage."),
345+
("ForceEnglishOutput", "--force-english-output", "bool?", false, "Forces the application to run using an invariant, English-based culture."),
346+
("ApiKey", "--api-key", "string", false, "The API key for the server."),
347+
("NoSymbols", "--no-symbols", "bool?", false, "Doesn't push symbols (even if present)."),
348+
("NoServiceEndpoint", "--no-service-endpoint", "bool?", false, "Doesn't append \"api/v2/package\" to the source URL."),
349+
("Source", "--source", "string", false, "Specifies the server URL. NuGet identifies a UNC or local folder source and simply copies the file there instead of pushing it using HTTP."),
350+
("SkipDuplicate", "--skip-duplicate", "bool?", false, "When pushing multiple packages to an HTTP(S) server, treats any 409 Conflict response as a warning so that other pushes can continue."),
351+
("SymbolApiKey", "--symbol-api-key", "string", false, "The API key for the symbol server."),
352+
("SymbolSource", "--symbol-source", "string", false, "Specifies the symbol server URL."),
353+
("Timeout", "--timeout", "int?", false, "Specifies the timeout for pushing to a server in seconds. Defaults to 300 seconds (5 minutes). Specifying 0 applies the default value."),
354+
("#Verbosity", "", "", false, ""),
355+
],
356+
false, false
357+
),
338358
(
339359
"DotNetRun",
340360
[

0 commit comments

Comments
 (0)