Skip to content

Commit 582ce37

Browse files
authored
Merge pull request #7 from MiYanni/OtelCleanup
Otel PR cleanup
2 parents 1d877b7 + 55646d4 commit 582ce37

Some content is hidden

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

47 files changed

+423
-436
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ dotnet_diagnostic.IDE0200.severity = none
280280
dotnet_diagnostic.IDE0240.severity = warning
281281

282282
# Additional rules for template engine source code
283+
284+
# Default severity for analyzer diagnostics with category 'StyleCop.CSharp.SpacingRules'
285+
dotnet_analyzer_diagnostic.category-StyleCop.CSharp.SpacingRules.severity = none
286+
283287
[{src,test}/**{Microsoft.TemplateEngine.*,dotnet-new?*}/**.cs]
284288
# Default analyzed API surface = 'public' (public APIs)
285289
dotnet_code_quality.api_surface = public

src/Cli/Microsoft.DotNet.Cli.Utils/Activities.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55

66
namespace Microsoft.DotNet.Cli.Utils;
77

8-
98
public static class Activities
109
{
11-
public static ActivitySource s_source = new("dotnet-cli", Product.Version);
10+
public static ActivitySource Source { get; } = new("dotnet-cli", Product.Version);
1211

1312
public const string DOTNET_CLI_TRACEPARENT = nameof(DOTNET_CLI_TRACEPARENT);
1413
public const string DOTNET_CLI_TRACESTATE = nameof(DOTNET_CLI_TRACESTATE);
Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
namespace Microsoft.Extensions.EnvironmentAbstractions
4+
namespace Microsoft.Extensions.EnvironmentAbstractions;
5+
6+
public readonly struct FilePath
57
{
6-
public struct FilePath
7-
{
8-
public string Value { get; }
8+
public string Value { get; }
99

10-
/// <summary>
11-
/// Create FilePath to represent an absolute file path. Note it may not exist.
12-
/// </summary>
13-
/// <param name="value">If the value is not rooted. Path.GetFullPath will be called during the constructor.</param>
14-
public FilePath(string value)
10+
/// <summary>
11+
/// Create FilePath to represent an absolute file path. Note: It may not exist.
12+
/// </summary>
13+
/// <param name="value">If the value is not rooted. Path.GetFullPath will be called during the constructor.</param>
14+
public FilePath(string value)
15+
{
16+
if (!Path.IsPathRooted(value))
1517
{
16-
if (!Path.IsPathRooted(value))
17-
{
18-
value = Path.GetFullPath(value);
19-
}
20-
21-
Value = value;
18+
value = Path.GetFullPath(value);
2219
}
2320

24-
public override string ToString()
25-
{
26-
return Value;
27-
}
21+
Value = value;
22+
}
2823

29-
public DirectoryPath GetDirectoryPath()
30-
{
31-
return new DirectoryPath(Path.GetDirectoryName(Value)!);
32-
}
24+
public override string ToString()
25+
{
26+
return Value;
27+
}
28+
29+
public DirectoryPath GetDirectoryPath()
30+
{
31+
return new DirectoryPath(Path.GetDirectoryName(Value)!);
3332
}
3433
}

src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ internal InstantiateCommand(
5151
Arity = new ArgumentArity(0, 999)
5252
};
5353

54-
internal IReadOnlyList<Option> PassByOptions { get; } = new Option[]
55-
{
54+
internal IReadOnlyList<Option> PassByOptions { get; } =
55+
[
5656
SharedOptions.ForceOption,
5757
SharedOptions.NameOption,
5858
SharedOptions.DryRunOption,
5959
SharedOptions.NoUpdateCheckOption
60-
};
60+
];
6161

6262
internal static Task<NewCommandStatus> ExecuteAsync(
6363
NewCommandArgs newCommandArgs,
@@ -74,7 +74,7 @@ internal static async Task<IEnumerable<TemplateGroup>> GetTemplateGroupsAsync(
7474
HostSpecificDataLoader hostSpecificDataLoader,
7575
CancellationToken cancellationToken)
7676
{
77-
using var createTemplateGroupsActivity = Activities.s_source.StartActivity("create-template-groups");
77+
using var createTemplateGroupsActivity = Activities.Source.StartActivity("create-template-groups");
7878
IReadOnlyList<ITemplateInfo> templates = await templatePackageManager.GetTemplatesAsync(cancellationToken).ConfigureAwait(false);
7979
return TemplateGroup.FromTemplateList(CliTemplateInfo.FromTemplateInfo(templates, hostSpecificDataLoader));
8080
}
@@ -85,7 +85,7 @@ internal static HashSet<TemplateCommand> GetTemplateCommand(
8585
TemplatePackageManager templatePackageManager,
8686
TemplateGroup templateGroup)
8787
{
88-
using var getTemplateActivity = Activities.s_source.StartActivity("get-template-command");
88+
using var getTemplateActivity = Activities.Source.StartActivity("get-template-command");
8989
//groups templates in the group by precedence
9090
foreach (IGrouping<int, CliTemplateInfo> templateGrouping in templateGroup.Templates.GroupBy(g => g.Precedence).OrderByDescending(g => g.Key))
9191
{
@@ -116,7 +116,7 @@ internal static HashSet<TemplateCommand> GetTemplateCommand(
116116
templateGroup,
117117
candidates);
118118
}
119-
return new HashSet<TemplateCommand>();
119+
return [];
120120
}
121121

122122
internal static void HandleNoMatchingTemplateGroup(InstantiateCommandArgs instantiateArgs, IEnumerable<TemplateGroup> templateGroups, IReporter reporter)
@@ -206,7 +206,7 @@ private static async Task<NewCommandStatus> ExecuteIntAsync(
206206

207207
return await templateListCoordinator.DisplayCommandDescriptionAsync(instantiateArgs, cancellationToken).ConfigureAwait(false);
208208
}
209-
using var createActivity = Activities.s_source.StartActivity("instantiate-command");
209+
using var createActivity = Activities.Source.StartActivity("instantiate-command");
210210
createActivity?.DisplayName = $"Invoke '{instantiateArgs.ShortName}'";
211211

212212
IEnumerable<TemplateGroup> allTemplateGroups = await GetTemplateGroupsAsync(
@@ -277,7 +277,7 @@ private static async Task<NewCommandStatus> HandleTemplateInstantiationAsync(
277277
{
278278
TemplateCommand templateCommandToRun = candidates.Single();
279279
args.Command.Subcommands.Add(templateCommandToRun);
280-
var templateParseActivity = Activities.s_source.StartActivity("reparse-for-template");
280+
var templateParseActivity = Activities.Source.StartActivity("reparse-for-template");
281281
ParseResult updatedParseResult = args.ParseResult.RootCommandResult.Command.Parse(
282282
args.ParseResult.Tokens.Select(t => t.Value).ToArray(),
283283
args.ParseResult.Configuration);

src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/TemplateCommand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Microsoft.TemplateEngine.Cli.Commands
1717
internal class TemplateCommand : Command
1818
{
1919
private static readonly TimeSpan ConstraintEvaluationTimeout = TimeSpan.FromMilliseconds(1000);
20-
private static readonly string[] _helpAliases = new[] { "-h", "/h", "--help", "-?", "/?" };
20+
private static readonly string[] _helpAliases = ["-h", "/h", "--help", "-?", "/?"];
2121
private readonly TemplatePackageManager _templatePackageManager;
2222
private readonly IEngineEnvironmentSettings _environmentSettings;
2323
private readonly BaseCommand _instantiateCommand;
@@ -146,7 +146,7 @@ internal static async Task<IReadOnlyList<TemplateConstraintResult>> ValidateCons
146146

147147
internal async Task<NewCommandStatus> InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
148148
{
149-
using var templateInvocationActivity = Activities.s_source.StartActivity("invoke-template");
149+
using var templateInvocationActivity = Activities.Source.StartActivity("invoke-template");
150150
TemplateCommandArgs args = new(this, _instantiateCommand, parseResult);
151151
TemplateInvoker invoker = new(_environmentSettings, () => Console.ReadLine() ?? string.Empty);
152152
TemplatePackageCoordinator packageCoordinator = new(_environmentSettings, _templatePackageManager);
@@ -162,7 +162,7 @@ internal async Task<NewCommandStatus> InvokeAsync(ParseResult parseResult, Cance
162162

163163
if (!args.IsForceFlagSpecified)
164164
{
165-
using var constraintResultsActivity = Activities.s_source.StartActivity("validate-constraints");
165+
using var constraintResultsActivity = Activities.Source.StartActivity("validate-constraints");
166166
var constraintResults = await constraintsEvaluation.ConfigureAwait(false);
167167
if (constraintResults.Any())
168168
{
@@ -177,7 +177,7 @@ internal async Task<NewCommandStatus> InvokeAsync(ParseResult parseResult, Cance
177177
Task<(string Id, string Version, string Provider)> builtInPackageCheck = packageCoordinator.ValidateBuiltInPackageAvailabilityAsync(args.Template, cancellationToken);
178178
Task<CheckUpdateResult?> checkForUpdateTask = packageCoordinator.CheckUpdateForTemplate(args, cancellationToken);
179179

180-
Task[] tasksToWait = new Task[] { instantiateTask, builtInPackageCheck, checkForUpdateTask };
180+
Task[] tasksToWait = [instantiateTask, builtInPackageCheck, checkForUpdateTask];
181181

182182
await Task.WhenAll(tasksToWait).ConfigureAwait(false);
183183
Reporter.Output.WriteLine();

src/Cli/Microsoft.TemplateEngine.Cli/TemplateInvoker.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ internal TemplateInvoker(
3737

3838
internal async Task<NewCommandStatus> InvokeTemplateAsync(TemplateCommandArgs templateArgs, CancellationToken cancellationToken)
3939
{
40-
using var invokerActivity = Activities.s_source.StartActivity("invoker-invoking");
40+
using var invokerActivity = Activities.Source.StartActivity("invoker-invoking");
4141
cancellationToken.ThrowIfCancellationRequested();
4242

4343
CliTemplateInfo templateToRun = templateArgs.Template;
@@ -159,7 +159,7 @@ private async Task<NewCommandStatus> CreateTemplateAsync(TemplateCommandArgs tem
159159

160160
try
161161
{
162-
using var templateCreationActivity = Activities.s_source.StartActivity("actual-instantiate-template");
162+
using var templateCreationActivity = Activities.Source.StartActivity("actual-instantiate-template");
163163
instantiateResult = await _templateCreator.InstantiateAsync(
164164
templateArgs.Template,
165165
templateArgs.Name,
@@ -308,7 +308,7 @@ private async Task<NewCommandStatus> CreateTemplateAsync(TemplateCommandArgs tem
308308

309309
private NewCommandStatus HandlePostActions(ITemplateCreationResult creationResult, TemplateCommandArgs args)
310310
{
311-
using var postActionActivity = Activities.s_source.StartActivity("post-actions");
311+
using var postActionActivity = Activities.Source.StartActivity("post-actions");
312312
PostActionExecutionStatus result = _postActionDispatcher.Process(creationResult, args.IsDryRun, args.AllowScripts ?? AllowRunScripts.Prompt);
313313

314314
return result switch

src/Cli/Microsoft.TemplateEngine.Cli/TemplateListCoordinator.cs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ internal TemplateListCoordinator(
2424
IEngineEnvironmentSettings engineEnvironmentSettings,
2525
TemplatePackageManager templatePackageManager,
2626
IHostSpecificDataLoader hostSpecificDataLoader)
27-
2827
{
2928
_engineEnvironmentSettings = engineEnvironmentSettings ?? throw new ArgumentNullException(nameof(engineEnvironmentSettings));
3029
_templatePackageManager = templatePackageManager ?? throw new ArgumentNullException(nameof(templatePackageManager));
3130
_hostSpecificDataLoader = hostSpecificDataLoader ?? throw new ArgumentNullException(nameof(hostSpecificDataLoader));
3231
_defaultLanguage = engineEnvironmentSettings.GetDefaultLanguage();
33-
using var constraintManagerActivity = Activities.s_source.StartActivity("create-constraints");
32+
using var constraintManagerActivity = Activities.Source.StartActivity("create-constraints");
3433
_constraintManager = new TemplateConstraintManager(_engineEnvironmentSettings);
3534
}
3635

@@ -49,7 +48,6 @@ internal async Task<NewCommandStatus> DisplayTemplateGroupListAsync(
4948
ListTemplateResolver resolver = new(_constraintManager, _templatePackageManager, _hostSpecificDataLoader);
5049
TemplateResolutionResult resolutionResult = await resolver.ResolveTemplatesAsync(args, _defaultLanguage, cancellationToken).ConfigureAwait(false);
5150

52-
//IReadOnlyDictionary<string, string?>? appliedParameterMatches = resolutionResult.GetAllMatchedParametersList();
5351
if (resolutionResult.TemplateGroupsWithMatchingTemplateInfoAndParameters.Any())
5452
{
5553
Reporter.Output.WriteLine(LocalizableStrings.TemplatesFoundMatchingInputParameters, GetInputParametersString(args));
@@ -67,10 +65,10 @@ internal async Task<NewCommandStatus> DisplayTemplateGroupListAsync(
6765
}
6866
else
6967
{
70-
//if there is no criteria and filters it means that dotnet new list was run but there is no templates installed.
68+
// If there is no criteria and filters, it means that dotnet new list was run but there are no templates installed.
7169
if (args.ListNameCriteria == null && !args.AppliedFilters.Any())
7270
{
73-
//No templates installed.
71+
// No templates installed.
7472
Reporter.Output.WriteLine(LocalizableStrings.NoTemplatesFound);
7573
Reporter.Output.WriteLine();
7674
// To search for the templates on NuGet.org, run:
@@ -84,7 +82,7 @@ internal async Task<NewCommandStatus> DisplayTemplateGroupListAsync(
8482
return NewCommandStatus.Success;
8583
}
8684

87-
// at least one criteria was specified.
85+
// At least one criteria was specified.
8886
// No templates found matching the following input parameter(s): {0}.
8987
Reporter.Error.WriteLine(
9088
string.Format(
@@ -196,33 +194,30 @@ internal async Task<NewCommandStatus> DisplayCommandDescriptionAsync(
196194
return NewCommandStatus.Success;
197195
}
198196

199-
private static string GetInputParametersString(ListCommandArgs args/*, IReadOnlyDictionary<string, string?>? templateParameters = null*/)
197+
private static string GetInputParametersString(ListCommandArgs args)
200198
{
201199
string separator = ", ";
202200
IEnumerable<string> appliedFilters = args.AppliedFilters
203201
.Select(filter => $"{args.GetFilterToken(filter)}='{args.GetFilterValue(filter)}'");
204202

205-
//IEnumerable<string> appliedTemplateParameters = templateParameters?
206-
// .Select(param => string.IsNullOrWhiteSpace(param.Value) ? param.Key : $"{param.Key}='{param.Value}'") ?? Array.Empty<string>();
207-
208203
StringBuilder inputParameters = new();
209204
string? mainCriteria = args.ListNameCriteria;
210205
if (!string.IsNullOrWhiteSpace(mainCriteria))
211206
{
212207
inputParameters.Append($"'{mainCriteria}'");
213-
if (appliedFilters.Any()/* || appliedTemplateParameters.Any()*/)
208+
if (appliedFilters.Any())
214209
{
215210
inputParameters.Append(separator);
216211
}
217212
}
218-
if (appliedFilters/*.Concat(appliedTemplateParameters)*/.Any())
213+
if (appliedFilters.Any())
219214
{
220-
inputParameters.Append(string.Join(separator, appliedFilters/*.Concat(appliedTemplateParameters)*/));
215+
inputParameters.Append(string.Join(separator, appliedFilters));
221216
}
222217
return inputParameters.ToString();
223218
}
224219

225-
private static string GetPartialMatchReason(TemplateResolutionResult templateResolutionResult, ListCommandArgs args/*, IReadOnlyDictionary<string, string?>? templateParameters = null*/)
220+
private static string GetPartialMatchReason(TemplateResolutionResult templateResolutionResult, ListCommandArgs args)
226221
{
227222
string separator = ", ";
228223

@@ -231,15 +226,10 @@ private static string GetPartialMatchReason(TemplateResolutionResult templateRes
231226
.Where(filter => filter.MismatchCriteria(templateResolutionResult))
232227
.Select(filter => $"{args.GetFilterToken(filter)}='{args.GetFilterValue(filter)}'");
233228

234-
//IEnumerable<string> appliedTemplateParameters = templateParameters?
235-
// .Where(parameter =>
236-
// templateResolutionResult.IsParameterMismatchReason(parameter.Key))
237-
// .Select(param => string.IsNullOrWhiteSpace(param.Value) ? param.Key : $"{param.Key}='{param.Value}'") ?? Array.Empty<string>();
238-
239229
StringBuilder inputParameters = new();
240-
if (appliedFilters/*.Concat(appliedTemplateParameters)*/.Any())
230+
if (appliedFilters.Any())
241231
{
242-
inputParameters.Append(string.Join(separator, appliedFilters/*.Concat(appliedTemplateParameters)*/));
232+
inputParameters.Append(string.Join(separator, appliedFilters));
243233
}
244234
return inputParameters.ToString();
245235
}

src/Cli/dotnet/CliSchema.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,20 @@ internal static class CliSchema
3333
TypeInfoResolver = new DefaultJsonTypeInfoResolver()
3434
};
3535

36-
public record ArgumentDetails(string? description, int order, bool hidden, string? helpName, string valueType, bool hasDefaultValue, object? defaultValue, ArityDetails arity);
37-
public record ArityDetails(int minimum, int? maximum);
36+
public record ArgumentDetails(
37+
string? description,
38+
int order,
39+
bool hidden,
40+
string? helpName,
41+
string valueType,
42+
bool hasDefaultValue,
43+
object? defaultValue,
44+
ArityDetails arity);
45+
46+
public record ArityDetails(
47+
int minimum,
48+
int? maximum);
49+
3850
public record OptionDetails(
3951
string? description,
4052
bool hidden,
@@ -45,15 +57,16 @@ public record OptionDetails(
4557
object? defaultValue,
4658
ArityDetails arity,
4759
bool required,
48-
bool recursive
49-
);
60+
bool recursive);
61+
5062
public record CommandDetails(
5163
string? description,
5264
bool hidden,
5365
string[]? aliases,
5466
Dictionary<string, ArgumentDetails>? arguments,
5567
Dictionary<string, OptionDetails>? options,
5668
Dictionary<string, CommandDetails>? subcommands);
69+
5770
public record RootCommandDetails(
5871
string name,
5972
string version,
@@ -65,7 +78,6 @@ public record RootCommandDetails(
6578
Dictionary<string, CommandDetails>? subcommands
6679
) : CommandDetails(description, hidden, aliases, arguments, options, subcommands);
6780

68-
6981
public static void PrintCliSchema(CommandResult commandResult, TextWriter outputWriter, ITelemetry? telemetryClient)
7082
{
7183
var command = commandResult.Command;

src/Cli/dotnet/CommandDirectoryContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static void PerformActionWithBasePath(string basePath, Action action)
3535
$"Calls to {nameof(CommandDirectoryContext)}.{nameof(PerformActionWithBasePath)} cannot be nested.");
3636
}
3737
_basePath = basePath;
38-
Telemetry.Telemetry.CurrentSessionId = null;
38+
Telemetry.Telemetry.s_currentSessionId = null;
3939
try
4040
{
4141
action();

src/Cli/dotnet/Commands/CliCommandStrings.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2522,4 +2522,7 @@ Proceed?</value>
25222522
<value>Tool package download needs confirmation. Run in interactive mode or use the "--yes" command-line option to confirm.</value>
25232523
<comment>{Locked="--yes"}</comment>
25242524
</data>
2525-
</root>
2525+
<data name="ToolInstallPackageIdMissing" xml:space="preserve">
2526+
<value>A package ID was not specified for tool installation.</value>
2527+
</data>
2528+
</root>

0 commit comments

Comments
 (0)