Skip to content

Commit 0d80e94

Browse files
MiYannibaronfel
authored andcommitted
Cleaned up the remaining changed src files. Avoided ToolPackageDownloader and ToolPackageDownloaderBase since those will be updated in main. Not interested in cleaning up test files.
1 parent eee8d3d commit 0d80e94

File tree

9 files changed

+166
-207
lines changed

9 files changed

+166
-207
lines changed
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/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/MSBuild/MSBuildForwardingApp.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class MSBuildForwardingApp : CommandBase
1616

1717
private static MSBuildArgs ConcatTelemetryLogger(MSBuildArgs msbuildArgs)
1818
{
19-
if (Telemetry.Telemetry.CurrentSessionId != null)
19+
if (Telemetry.Telemetry.s_currentSessionId != null)
2020
{
2121
try
2222
{
@@ -73,7 +73,7 @@ public ProcessStartInfo GetProcessStartInfo()
7373

7474
private void InitializeRequiredEnvironmentVariables()
7575
{
76-
EnvironmentVariable(TelemetrySessionIdEnvironmentVariableName, Telemetry.Telemetry.CurrentSessionId);
76+
EnvironmentVariable(TelemetrySessionIdEnvironmentVariableName, Telemetry.Telemetry.s_currentSessionId);
7777
}
7878

7979
/// <summary>

src/Cli/dotnet/CommonOptionsFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
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-
#nullable disable
5-
64
using System.CommandLine;
5+
using System.CommandLine.Invocation;
76
using System.CommandLine.Parsing;
87
using Microsoft.DotNet.Cli.Extensions;
98
using Microsoft.DotNet.Cli.Utils;
@@ -25,7 +24,7 @@ internal static class CommonOptionsFactory
2524
Arity = ArgumentArity.Zero
2625
};
2726

28-
internal class SetDiagnosticModeAction(Option<bool> diagnosticOption) : System.CommandLine.Invocation.SynchronousCommandLineAction
27+
internal class SetDiagnosticModeAction(Option<bool> diagnosticOption) : SynchronousCommandLineAction
2928
{
3029
public override int Invoke(ParseResult parseResult)
3130
{
@@ -42,6 +41,7 @@ public override int Invoke(ParseResult parseResult)
4241
Reporter.Reset();
4342
}
4443
}
44+
4545
return 0;
4646
}
4747
}

src/Cli/dotnet/Extensions/ParseResultExtensions.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ namespace Microsoft.DotNet.Cli.Extensions;
1515

1616
public static class ParseResultExtensions
1717
{
18-
///<summary>
18+
/// <summary>
1919
/// Finds the command of the parse result and invokes help for that command.
2020
/// If no command is specified, invokes help for the application.
21-
///<summary>
22-
///<remarks>
21+
/// <summary>
22+
/// <remarks>
2323
/// This is accomplished by finding a set of tokens that should be valid and appending a help token
2424
/// to that list, then re-parsing the list of tokens. This is not ideal - either we should have a direct way
2525
/// of invoking help for a ParseResult, or we should eliminate this custom, ad-hoc help invocation by moving
2626
/// more situations that want to show help into Parsing Errors (which trigger help in the default System.CommandLine pipeline)
2727
/// or custom Invocation Middleware, so we can more easily create our version of a HelpResult type.
28-
///</remarks>
28+
/// </remarks>
2929
public static void ShowHelp(this ParseResult parseResult)
3030
{
31-
// take from the start of the list until we hit an option/--/unparsed token
32-
// since commands can have arguments, we must take those as well in order to get accurate help
31+
// Take from the start of the list until we hit an option/--/unparsed token.
32+
// Since commands can have arguments, we must take those as well in order to get accurate help.
3333
var tokenList = parseResult.Tokens.TakeWhile(token => token.Type == TokenType.Argument || token.Type == TokenType.Command || token.Type == TokenType.Directive).Select(t => t.Value).ToList();
3434
tokenList.Add("-h");
3535
Instance.Parse(tokenList).Invoke();
@@ -55,14 +55,17 @@ public static void ShowHelpOrErrorIfAppropriate(this ParseResult parseResult)
5555
}
5656
}
5757

58-
///<summary>Splits a .NET format string by the format placeholders (the {N} parts) to get an array of the literal parts, to be used in message-checking</summary>
58+
/// <summary>
59+
/// Splits a .NET format string by the format placeholders (the {N} parts) to get an array of the literal parts, to be used in message-checking.
60+
/// </summary>
5961
static string[] DistinctFormatStringParts(string formatString)
6062
{
6163
return Regex.Split(formatString, @"{[0-9]+}"); // match the literal '{', followed by any of 0-9 one or more times, followed by the literal '}'
6264
}
6365

64-
65-
/// <summary>given a string and a series of parts, ensures that all parts are present in the string in sequential order</summary>
66+
/// <summary>
67+
/// Given a string and a series of parts, ensures that all parts are present in the string in sequential order.
68+
/// </summary>
6669
static bool ErrorContainsAllParts(ReadOnlySpan<char> error, string[] parts)
6770
{
6871
foreach (var part in parts)
@@ -160,13 +163,6 @@ public static bool DiagOptionPrecedesSubcommand(this string[] args, string subCo
160163
return false;
161164
}
162165

163-
private static string? GetSymbolResultValue(ParseResult parseResult, SymbolResult symbolResult) => symbolResult switch
164-
{
165-
CommandResult commandResult => commandResult.Command.Name,
166-
ArgumentResult argResult => argResult.Tokens.FirstOrDefault()?.Value,
167-
_ => parseResult.GetResult(DotnetSubCommand)?.GetValueOrDefault<string>()
168-
};
169-
170166
public static bool BothArchAndOsOptionsSpecified(this ParseResult parseResult) =>
171167
(parseResult.HasOption(CommonOptions.ArchitectureOption) ||
172168
parseResult.HasOption(CommonOptions.LongFormArchitectureOption)) &&
@@ -187,7 +183,7 @@ public static bool BothArchAndOsOptionsSpecified(this ParseResult parseResult) =
187183

188184
public static bool UsingRunCommandShorthandProjectOption(this ParseResult parseResult)
189185
{
190-
if (parseResult.HasOption(RunCommandParser.PropertyOption) && parseResult.GetValue(RunCommandParser.PropertyOption)!.Any())
186+
if (parseResult.HasOption(RunCommandParser.PropertyOption) && (parseResult.GetValue(RunCommandParser.PropertyOption)?.Any() ?? false))
191187
{
192188
var projVals = parseResult.GetRunCommandShorthandProjectValues();
193189
if (projVals?.Any() is true)

src/Cli/dotnet/Parser.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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-
#nullable disable
5-
64
using System.CommandLine;
75
using System.CommandLine.Completions;
86
using System.CommandLine.Invocation;
@@ -105,12 +103,13 @@ public static class Parser
105103
Action = new PrintVersionAction()
106104
};
107105

108-
internal class PrintVersionAction : System.CommandLine.Invocation.SynchronousCommandLineAction
106+
internal class PrintVersionAction : SynchronousCommandLineAction
109107
{
110108
public PrintVersionAction()
111109
{
112110
Terminating = true;
113111
}
112+
114113
public override int Invoke(ParseResult parseResult)
115114
{
116115
CommandLineInfo.PrintVersion();
@@ -124,7 +123,7 @@ public override int Invoke(ParseResult parseResult)
124123
Action = new PrintInfoAction()
125124
};
126125

127-
internal class PrintInfoAction : System.CommandLine.Invocation.SynchronousCommandLineAction
126+
internal class PrintInfoAction : SynchronousCommandLineAction
128127
{
129128
public PrintInfoAction()
130129
{
@@ -220,14 +219,14 @@ private static Command ConfigureCommandLine(RootCommand rootCommand)
220219
return rootCommand;
221220
}
222221

223-
public static Command GetBuiltInCommand(string commandName) =>
222+
public static Command? GetBuiltInCommand(string commandName) =>
224223
Subcommands.FirstOrDefault(c => c.Name.Equals(commandName, StringComparison.OrdinalIgnoreCase));
225224

226225
/// <summary>
227226
/// Implements token-per-line response file handling for the CLI. We use this instead of the built-in S.CL handling
228227
/// to ensure backwards-compatibility with MSBuild.
229228
/// </summary>
230-
public static bool TokenPerLine(string tokenToReplace, out IReadOnlyList<string> replacementTokens, out string errorMessage)
229+
public static bool TokenPerLine(string tokenToReplace, out IReadOnlyList<string>? replacementTokens, out string? errorMessage)
231230
{
232231
var filePath = Path.GetFullPath(tokenToReplace);
233232
if (File.Exists(filePath))
@@ -260,7 +259,7 @@ public static bool TokenPerLine(string tokenToReplace, out IReadOnlyList<string>
260259
ResponseFileTokenReplacer = TokenPerLine
261260
};
262261

263-
internal static int ExceptionHandler(Exception exception, ParseResult parseResult)
262+
internal static int ExceptionHandler(Exception? exception, ParseResult parseResult)
264263
{
265264
if (exception is TargetInvocationException)
266265
{
@@ -280,13 +279,13 @@ internal static int ExceptionHandler(Exception exception, ParseResult parseResul
280279
exception.Message.Red().Bold());
281280
parseResult.ShowHelp();
282281
}
283-
else if (exception.GetType().Name.Equals("WorkloadManifestCompositionException"))
282+
else if (exception is not null && exception.GetType().Name.Equals("WorkloadManifestCompositionException"))
284283
{
285284
Reporter.Error.WriteLine(CommandLoggingContext.IsVerbose ?
286285
exception.ToString().Red().Bold() :
287286
exception.Message.Red().Bold());
288287
}
289-
else
288+
else if (exception is not null)
290289
{
291290
Reporter.Error.Write("Unhandled exception: ".Red().Bold());
292291
Reporter.Error.WriteLine(CommandLoggingContext.IsVerbose ?
@@ -374,7 +373,7 @@ public override void Write(HelpContext context)
374373
}
375374
else if (command.Name.Equals(FormatCommandParser.GetCommand().Name))
376375
{
377-
var arguments = context.ParseResult.GetValue(FormatCommandParser.Arguments);
376+
var arguments = context.ParseResult.GetValue(FormatCommandParser.Arguments) ?? [];
378377
new FormatForwardingApp([.. arguments, .. helpArgs]).Execute();
379378
}
380379
else if (command.Name.Equals(FsiCommandParser.GetCommand().Name))
@@ -401,9 +400,9 @@ public override void Write(HelpContext context)
401400
{
402401
if (command.Name.Equals(ListReferenceCommandParser.GetCommand().Name))
403402
{
404-
Command listCommand = command.Parents.Single() as Command;
403+
Command? listCommand = command.Parents.Single() as Command;
405404

406-
for (int i = 0; i < listCommand.Arguments.Count; i++)
405+
for (int i = 0; i < listCommand?.Arguments.Count; i++)
407406
{
408407
if (listCommand.Arguments[i].Name == CliStrings.SolutionOrProjectArgumentName)
409408
{
@@ -434,6 +433,7 @@ internal PrintCliSchemaAction()
434433
{
435434
Terminating = true;
436435
}
436+
437437
public override int Invoke(ParseResult parseResult)
438438
{
439439
CliSchema.PrintCliSchema(parseResult.CommandResult, parseResult.Configuration.Output, Program.TelemetryClient);

0 commit comments

Comments
 (0)