Skip to content

Commit 9a6295f

Browse files
Add comments
1 parent 28cdd7a commit 9a6295f

File tree

62 files changed

+2278
-292
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2278
-292
lines changed

CSharpInteractive.HostApi/DotNetCommands.cs

Lines changed: 444 additions & 63 deletions
Large diffs are not rendered by default.

CSharpInteractive.HostApi/DotNetCommands.tt

Lines changed: 44 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<#@ import namespace="System.Linq" #>
2-
<#@ import namespace="System.Linq" #>
3-
<#@ import namespace="System.Linq" #>
42
<#@ import namespace="System.Collections.Generic" #>
3+
<#@ import namespace="System.IO" #>
4+
<#@ import namespace="System.Xml" #>
55
// ReSharper disable UnusedMember.Global
66
// ReSharper disable InconsistentNaming
77
namespace HostApi;
@@ -17,7 +17,7 @@ using Internal;
1717

1818
string CreateCliRef(string command) =>
1919
$"<br/><a href=\"https://learn.microsoft.com/en-us/dotnet/core/tools/{command}\">.NET CLI command</a><br/>";
20-
20+
2121
var projectArg = new Arg("Project", "", "string", "The project or solution file to operate on. If not specified, the command searches the current directory for one. If more than one solution or project is found, an error is thrown.") { IsProject = true };
2222
var solutionArg = new Arg("Solution", "", "string", "The solution file to use. If this argument is omitted, the command searches the current directory for one. If it finds no solution file or multiple solution files, the command fails.") { IsProject = true };
2323
var propsArg = new Arg("Props", "--property", "IEnumerable<(string name, string value)>", "MSBuild options for setting properties.") { IsCollection = true };
@@ -116,11 +116,11 @@ using Internal;
116116
paraFinish,
117117
CreateCliRef("dotnet-add-package")
118118
],
119-
["add", "$Project", "package", "$PackageName"],
119+
["add", "$Project", "package", "$Package"],
120120
[
121121
sourcesArg,
122122
projectArg,
123-
new Arg("PackageName", "", "string", "The package reference to add."),
123+
new Arg("Package", "", "string", "The package reference to add."),
124124
frameworkArg with { Comments = "Adds a package reference only when targeting a specific framework." },
125125
noRestoreArg,
126126
new Arg("PackageDirectory", "--package-directory", "string", @"The directory where to restore the packages. The default package restore location is %userprofile%\.nuget\packages on Windows and ~/.nuget/packages on macOS and Linux."),
@@ -163,10 +163,10 @@ using Internal;
163163
paraFinish,
164164
CreateCliRef("dotnet-remove-package")
165165
],
166-
["remove", "$Project", "package", "$PackageName"],
166+
["remove", "$Project", "package", "$Package"],
167167
[
168168
projectArg,
169-
new Arg("PackageName", "", "string", "The package reference to add."),
169+
new Arg("Package", "", "string", "The package reference to add."),
170170
diagnosticsArg
171171
]
172172
),
@@ -181,7 +181,7 @@ using Internal;
181181
],
182182
["add", "$Project", "reference", "$References"],
183183
[
184-
new Arg("References", "--source", "IEnumerable<string>", "Project-to-project (P2P) references to add. Specify one or more projects. Glob patterns are supported on Unix/Linux-based systems.") { IsCollection = true },
184+
new Arg("References", "", "IEnumerable<string>", "Project-to-project (P2P) references to add. Specify one or more projects. Glob patterns are supported on Unix/Linux-based systems.") { IsProject = true, IsCollection = true },
185185
projectArg,
186186
frameworkArg with { Comments = "Adds project references only when targeting a specific framework using the TFM format." },
187187
diagnosticsArg
@@ -196,7 +196,7 @@ using Internal;
196196
paraFinish,
197197
CreateCliRef("dotnet-list-reference")
198198
],
199-
["list", "$Project"],
199+
["list", "$Project", "reference"],
200200
[
201201
projectArg,
202202
diagnosticsArg
@@ -213,7 +213,7 @@ using Internal;
213213
],
214214
["remove", "$Project", "reference", "$References"],
215215
[
216-
new Arg("References", "--source", "IEnumerable<string>", "Project-to-project (P2P) references to remove. You can specify one or multiple projects. Glob patterns are supported on Unix/Linux based terminals.") { IsCollection = true },
216+
new Arg("References", "", "IEnumerable<string>", "Project-to-project (P2P) references to remove. You can specify one or multiple projects. Glob patterns are supported on Unix/Linux based terminals.") { IsProject = true, IsCollection = true },
217217
projectArg,
218218
frameworkArg with { Comments = "Removes the reference only when targeting a specific framework using the TFM format." },
219219
diagnosticsArg
@@ -229,15 +229,6 @@ using Internal;
229229
paraStart,
230230
"For executable projects targeting .NET Core 3.0 and later, library dependencies are copied to the output folder. This means that if there isn't any other publish-specific logic (such as Web projects have), the build output should be deployable.",
231231
paraFinish,
232-
exampleStart,
233-
codeStart,
234-
"var configuration = Props.Get(\"configuration\", \"Release\");",
235-
"",
236-
"",
237-
"new DotNetBuild().WithConfiguration(configuration)",
238-
" .Build().EnsureSuccess();",
239-
codeFinish,
240-
exampleFinish,
241232
CreateCliRef("dotnet-build")
242233
],
243234
["build", "$Project"],
@@ -344,15 +335,6 @@ using Internal;
344335
paraStart,
345336
"This command creates a .NET project or other artifacts based on a template. The command calls the template engine to create the artifacts on disk based on the specified template and options.",
346337
paraFinish,
347-
exampleStart,
348-
codeStart,
349-
"new DotNetNew()",
350-
" .WithTemplateName(\"console\")",
351-
" .WithName(\"MyApp\")",
352-
" .WithForce(true)",
353-
" .Run().EnsureSuccess();",
354-
codeFinish,
355-
exampleFinish,
356338
CreateCliRef("dotnet-new")
357339
],
358340
["new", "$TemplateName"],
@@ -498,9 +480,9 @@ using Internal;
498480
paraFinish,
499481
CreateCliRef("dotnet-nuget-delete")
500482
],
501-
["nuget", "delete", "$PackageName", "$PackageVersion"],
483+
["nuget", "delete", "$Package", "$PackageVersion"],
502484
[
503-
new Arg("PackageName", "", "string", "Name/ID of the package to delete.") { IsProject = true },
485+
new Arg("Package", "", "string", "Name/ID of the package to delete.") { IsProject = true },
504486
new Arg("PackageVersion", "", "string", "Version of the package to delete.") { IsProject = true },
505487
new Arg("ForceEnglishOutput", "--force-english-output", "bool?", "Forces the application to run using an invariant, English-based culture."),
506488
new Arg("ApiKey", "--api-key", "string", "The API key for the server."),
@@ -931,12 +913,6 @@ using Internal;
931913
paraStart,
932914
"By default, dotnet pack builds the project first. If you wish to avoid this behavior, pass the --no-build option. This option is often useful in Continuous Integration (CI) build scenarios where you know the code was previously built.",
933915
paraFinish,
934-
exampleStart,
935-
codeStart,
936-
"new DotNetPack()",
937-
" .Build().EnsureSuccess();",
938-
codeFinish,
939-
exampleFinish,
940916
CreateCliRef("dotnet-pack")
941917
],
942918
["pack", "$Project"],
@@ -997,12 +973,6 @@ using Internal;
997973
paraStart,
998974
"This command compiles the application, reads through its dependencies specified in the project file, and publishes the resulting set of files to a directory.",
999975
paraFinish,
1000-
exampleStart,
1001-
codeStart,
1002-
"new DotNetPublish().AddProps((\"PublishDir\", \".publish\"))",
1003-
" .Build().EnsureSuccess();",
1004-
codeFinish,
1005-
exampleFinish,
1006976
CreateCliRef("dotnet-publish")
1007977
],
1008978
["publish", "$Project"],
@@ -1044,12 +1014,6 @@ using Internal;
10441014
paraStart,
10451015
"Sometimes, it might be inconvenient to run the implicit NuGet restore with these commands. For example, some automated systems, such as build systems, need to call dotnet restore explicitly to control when the restore occurs so that they can control network usage. To prevent the implicit NuGet restore, you can use the --no-restore flag with any of these commands.",
10461016
paraFinish,
1047-
exampleStart,
1048-
codeStart,
1049-
"new DotNetRestore()",
1050-
" .Build().EnsureSuccess();",
1051-
codeFinish,
1052-
exampleFinish,
10531017
CreateCliRef("dotnet-restore")
10541018
],
10551019
["restore", "$Project"],
@@ -1088,19 +1052,6 @@ using Internal;
10881052
paraStart,
10891053
"To run the application, the dotnet run command resolves the dependencies of the application that are outside of the shared runtime from the NuGet cache. Because it uses cached dependencies, it's not recommended to use dotnet run to run applications in production. Instead, create a deployment using the dotnet publish command and deploy the published output.",
10901054
paraFinish,
1091-
exampleStart,
1092-
codeStart,
1093-
"new DotNetNew()",
1094-
" .WithTemplateName(\"console\")",
1095-
" .WithName(\"MyApp\")",
1096-
" .WithForce(true)",
1097-
" .Run().EnsureSuccess();",
1098-
"",
1099-
"",
1100-
"new DotNetRun().WithWorkingDirectory(\"MyApp\")",
1101-
" .Build().EnsureSuccess();",
1102-
codeFinish,
1103-
exampleFinish,
11041055
CreateCliRef("dotnet-run")
11051056
],
11061057
["run"],
@@ -1210,19 +1161,6 @@ using Internal;
12101161
paraStart,
12111162
"For multi-targeted projects, tests are run for each targeted framework. The test host and the unit test framework are packaged as NuGet packages and are restored as ordinary dependencies for the project. Starting with the .NET 9 SDK, these tests are run in parallel by default. To disable parallel execution, set the TestTfmsInParallel MSBuild property to false.",
12121163
paraFinish,
1213-
exampleStart,
1214-
codeStart,
1215-
"new DotNetNew()",
1216-
" .WithTemplateName(\"mstest\")",
1217-
" .WithName(\"MyTests\")",
1218-
" .WithForce(true)",
1219-
" .Run().EnsureSuccess();",
1220-
"",
1221-
"",
1222-
"new DotNetTest().WithWorkingDirectory(\"MyTests\")",
1223-
" .Build().EnsureSuccess();",
1224-
codeFinish,
1225-
exampleFinish,
12261164
CreateCliRef("dotnet-test")
12271165
],
12281166
["test", "$Project"],
@@ -1636,6 +1574,33 @@ using Internal;
16361574
/// <#= comment #>
16371575
<#
16381576
}
1577+
1578+
var exampleFile = Path.Combine("..", "CSharpInteractive.Tests", "UsageScenarios", "Comments", $"{command.Name}Scenario.txt");
1579+
if (File.Exists(exampleFile))
1580+
{
1581+
var exampleLines = File.ReadAllLines(exampleFile);
1582+
if (exampleLines.Length > 0)
1583+
{
1584+
#>
1585+
/// <#= exampleStart #>
1586+
///<#= codeStart #>
1587+
<#
1588+
var doc = new XmlDocument();
1589+
foreach (var exampleLine in exampleLines.Select(i => i.TrimEnd()))
1590+
{
1591+
var node = doc.CreateElement("root");
1592+
node.InnerText = exampleLine;
1593+
var line = node.InnerXml;
1594+
#>
1595+
/// <#= line #>
1596+
<#
1597+
}
1598+
#>
1599+
///<#= codeFinish #>
1600+
/// <#= exampleFinish #>
1601+
<#
1602+
}
1603+
}
16391604
#>
16401605
/// </summary>
16411606
/// <param name="Args">Specifies the set of command line arguments to use when starting the tool.</param>
@@ -1743,8 +1708,12 @@ public partial record <#= command.Name #>(
17431708
{
17441709
notEmptyArg = $"{notEmptyArg}.ToArray()";
17451710
}
1711+
else
1712+
{
1713+
notEmptyArg = $"{notEmptyArg}.ToArg()";
1714+
}
17461715
#>
1747-
.AddNotEmptyArgs(<#= notEmptyArg #>.ToArg())
1716+
.AddNotEmptyArgs(<#= notEmptyArg #>)
17481717
<#
17491718
}
17501719
else

CSharpInteractive.HostApi/Internal/DotNet/DotNetCommandLineExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ public static string[] ToArgs(this IEnumerable<string> values, string name, stri
161161
}
162162

163163
var str = string.Join(collectionSeparator, values);
164+
if (string.IsNullOrWhiteSpace(str))
165+
{
166+
return [];
167+
}
168+
164169
return string.IsNullOrWhiteSpace(str) ? [] : [name, str];
165170
}
166171

0 commit comments

Comments
 (0)