Skip to content

Commit 6312893

Browse files
Copilottmat
andcommitted
Rename CommandParser to CommandDefinition and method to Create
Per review feedback, transformed all partial CommandParser classes to non-partial CommandDefinition classes: - Removed 'partial' keyword - Renamed classes from *CommandParser to *CommandDefinition - Renamed files to match new class names - Renamed CreateCommandDefinition() method to Create() This provides clearer naming: CommandDefinition for parsing logic, CommandParser for the actions/public API. Co-authored-by: tmat <[email protected]> Remove partial keyword from CommandParser Actions classes Since CommandDefinition classes are no longer partial, the CommandParser Actions classes don't need to be partial either. Removed the 'partial' keyword from all 32 Actions files to reflect this complete separation. Co-authored-by: tmat <[email protected]> Update references to renamed CommandDefinition classes Updated all code references from *CommandParser to *CommandDefinition for accessing static members (options, arguments, etc.). Updated Actions files to call XxxCommandDefinition.Create() instead of CreateCommandDefinition(). The GetCommand() API remains on *CommandParser classes. Co-authored-by: tmat <[email protected]> Remove .Actions suffix from CommandParser files Renamed all 32 *CommandParser.Actions.cs files to *CommandParser.cs to remove the .Actions suffix, making the file names cleaner and more consistent. Co-authored-by: tmat <[email protected]>
1 parent 9690ccc commit 6312893

File tree

128 files changed

+2635
-2635
lines changed

Some content is hidden

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

128 files changed

+2635
-2635
lines changed

src/Cli/dotnet/CommandLineInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static void PrintInfo()
2424
Reporter.Output.WriteLine($"{LocalizableStrings.DotNetSdkInfoLabel}");
2525
Reporter.Output.WriteLine($" Version: {Product.Version}");
2626
Reporter.Output.WriteLine($" Commit: {commitSha}");
27-
Reporter.Output.WriteLine($" Workload version: {WorkloadCommandParser.GetWorkloadsVersion()}");
27+
Reporter.Output.WriteLine($" Workload version: {WorkloadCommandDefinition.GetWorkloadsVersion()}");
2828
Reporter.Output.WriteLine($" MSBuild version: {MSBuildForwardingAppWithoutLogging.MSBuildVersion.ToString()}");
2929
Reporter.Output.WriteLine();
3030
Reporter.Output.WriteLine($"{LocalizableStrings.DotNetRuntimeInfoLabel}");
@@ -40,7 +40,7 @@ private static void PrintWorkloadsInfo()
4040
{
4141
Reporter.Output.WriteLine();
4242
Reporter.Output.WriteLine($"{LocalizableStrings.DotnetWorkloadInfoLabel}");
43-
WorkloadCommandParser.ShowWorkloadsInfo(showVersion: false);
43+
WorkloadCommandDefinition.ShowWorkloadsInfo(showVersion: false);
4444
}
4545

4646
private static string GetDisplayRid(DotnetVersionFile versionFile)

src/Cli/dotnet/Commands/Build/BuildCommand.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ public static CommandBase FromParseResult(ParseResult parseResult, string? msbui
2222
parseResult.ShowHelpOrErrorIfAppropriate();
2323

2424
CommonOptions.ValidateSelfContainedOptions(
25-
parseResult.HasOption(BuildCommandParser.SelfContainedOption),
26-
parseResult.HasOption(BuildCommandParser.NoSelfContainedOption));
25+
parseResult.HasOption(BuildCommandDefinition.SelfContainedOption),
26+
parseResult.HasOption(BuildCommandDefinition.NoSelfContainedOption));
2727

28-
bool noRestore = parseResult.HasOption(BuildCommandParser.NoRestoreOption);
28+
bool noRestore = parseResult.HasOption(BuildCommandDefinition.NoRestoreOption);
2929

3030
return CommandFactory.CreateVirtualOrPhysicalCommand(
3131
BuildCommandParser.GetCommand(),
32-
BuildCommandParser.SlnOrProjectOrFileArgument,
32+
BuildCommandDefinition.SlnOrProjectOrFileArgument,
3333
(msbuildArgs, appFilePath) => new VirtualProjectBuildingCommand(
3434
entryPointFileFullPath: Path.GetFullPath(appFilePath),
3535
msbuildArgs: msbuildArgs
@@ -43,7 +43,7 @@ public static CommandBase FromParseResult(ParseResult parseResult, string? msbui
4343
noRestore: noRestore,
4444
msbuildPath: msbuildPath
4545
),
46-
[CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, BuildCommandParser.TargetOption, BuildCommandParser.VerbosityOption, BuildCommandParser.NoLogoOption],
46+
[CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, BuildCommandDefinition.TargetOption, BuildCommandDefinition.VerbosityOption, BuildCommandDefinition.NoLogoOption],
4747
parseResult,
4848
msbuildPath
4949
);
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.CommandLine;
5+
using Microsoft.DotNet.Cli.CommandLine;
6+
using Microsoft.DotNet.Cli.Commands.Restore;
7+
using Microsoft.DotNet.Cli.Extensions;
8+
9+
namespace Microsoft.DotNet.Cli.Commands.Build;
10+
11+
internal static class BuildCommandDefinition
12+
{
13+
public static readonly string DocsLink = "https://aka.ms/dotnet-build";
14+
15+
public static readonly Argument<string[]> SlnOrProjectOrFileArgument = new(CliStrings.SolutionOrProjectOrFileArgumentName)
16+
{
17+
Description = CliStrings.SolutionOrProjectOrFileArgumentDescription,
18+
Arity = ArgumentArity.ZeroOrMore
19+
};
20+
21+
public static readonly Option<string> OutputOption = new Option<string>("--output", "-o")
22+
{
23+
Description = CliCommandStrings.BuildOutputOptionDescription,
24+
HelpName = CliCommandStrings.OutputOptionName
25+
}.ForwardAsOutputPath("OutputPath");
26+
27+
public static readonly Option<bool> NoIncrementalOption = new Option<bool>("--no-incremental")
28+
{
29+
Description = CliCommandStrings.NoIncrementalOptionDescription,
30+
Arity = ArgumentArity.Zero
31+
}.ForwardAs("--target:Rebuild");
32+
33+
public static readonly Option<bool> NoDependenciesOption = new Option<bool>("--no-dependencies")
34+
{
35+
Description = CliCommandStrings.NoDependenciesOptionDescription,
36+
Arity = ArgumentArity.Zero
37+
}.ForwardAs("--property:BuildProjectReferences=false");
38+
39+
public static readonly Option<bool> NoLogoOption = CommonOptions.NoLogoOption();
40+
41+
public static readonly Option<bool> NoRestoreOption = CommonOptions.NoRestoreOption;
42+
43+
public static readonly Option<bool> SelfContainedOption = CommonOptions.SelfContainedOption;
44+
45+
public static readonly Option<bool> NoSelfContainedOption = CommonOptions.NoSelfContainedOption;
46+
47+
public static readonly Option<string> RuntimeOption = CommonOptions.RuntimeOption(CliCommandStrings.BuildRuntimeOptionDescription);
48+
49+
public static readonly Option<string> FrameworkOption = CommonOptions.FrameworkOption(CliCommandStrings.BuildFrameworkOptionDescription);
50+
51+
public static readonly Option<string?> ConfigurationOption = CommonOptions.ConfigurationOption(CliCommandStrings.BuildConfigurationOptionDescription);
52+
53+
/// <summary>
54+
/// Build actually means 'run the default Target' generally in MSBuild
55+
/// </summary>
56+
public static readonly Option<string[]?> TargetOption = CommonOptions.MSBuildTargetOption();
57+
58+
public static readonly Option<Utils.VerbosityOptions?> VerbosityOption = CommonOptions.VerbosityOption();
59+
60+
public static Command Create()
61+
{
62+
Command command = new("build", CliCommandStrings.BuildAppFullName)
63+
{
64+
DocsLink = DocsLink
65+
};
66+
67+
command.Arguments.Add(SlnOrProjectOrFileArgument);
68+
RestoreCommandParser.AddImplicitRestoreOptions(command, includeRuntimeOption: false, includeNoDependenciesOption: false);
69+
command.Options.Add(FrameworkOption);
70+
command.Options.Add(ConfigurationOption);
71+
command.Options.Add(RuntimeOption);
72+
command.Options.Add(CommonOptions.VersionSuffixOption);
73+
command.Options.Add(NoRestoreOption);
74+
command.Options.Add(CommonOptions.InteractiveMsBuildForwardOption);
75+
command.Options.Add(VerbosityOption);
76+
command.Options.Add(CommonOptions.DebugOption);
77+
command.Options.Add(OutputOption);
78+
command.Options.Add(CommonOptions.ArtifactsPathOption);
79+
command.Options.Add(NoIncrementalOption);
80+
command.Options.Add(NoDependenciesOption);
81+
command.Options.Add(NoLogoOption);
82+
command.Options.Add(SelfContainedOption);
83+
command.Options.Add(NoSelfContainedOption);
84+
command.Options.Add(CommonOptions.ArchitectureOption);
85+
command.Options.Add(CommonOptions.OperatingSystemOption);
86+
command.Options.Add(CommonOptions.DisableBuildServersOption);
87+
command.Options.Add(TargetOption);
88+
command.Options.Add(CommonOptions.GetPropertyOption);
89+
command.Options.Add(CommonOptions.GetItemOption);
90+
command.Options.Add(CommonOptions.GetTargetResultOption);
91+
command.Options.Add(CommonOptions.GetResultOutputFileOption);
92+
93+
return command;
94+
}
95+
}

src/Cli/dotnet/Commands/Build/BuildCommandParser.Actions.cs

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

src/Cli/dotnet/Commands/Build/BuildCommandParser.cs

Lines changed: 7 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2,94 +2,22 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.CommandLine;
5-
using Microsoft.DotNet.Cli.CommandLine;
6-
using Microsoft.DotNet.Cli.Commands.Restore;
75
using Microsoft.DotNet.Cli.Extensions;
86

97
namespace Microsoft.DotNet.Cli.Commands.Build;
108

11-
internal static partial class BuildCommandParser
9+
internal static class BuildCommandParser
1210
{
13-
public static readonly string DocsLink = "https://aka.ms/dotnet-build";
11+
private static readonly Command Command = ConfigureCommand(BuildCommandDefinition.Create());
1412

15-
public static readonly Argument<string[]> SlnOrProjectOrFileArgument = new(CliStrings.SolutionOrProjectOrFileArgumentName)
13+
public static Command GetCommand()
1614
{
17-
Description = CliStrings.SolutionOrProjectOrFileArgumentDescription,
18-
Arity = ArgumentArity.ZeroOrMore
19-
};
20-
21-
public static readonly Option<string> OutputOption = new Option<string>("--output", "-o")
22-
{
23-
Description = CliCommandStrings.BuildOutputOptionDescription,
24-
HelpName = CliCommandStrings.OutputOptionName
25-
}.ForwardAsOutputPath("OutputPath");
26-
27-
public static readonly Option<bool> NoIncrementalOption = new Option<bool>("--no-incremental")
28-
{
29-
Description = CliCommandStrings.NoIncrementalOptionDescription,
30-
Arity = ArgumentArity.Zero
31-
}.ForwardAs("--target:Rebuild");
32-
33-
public static readonly Option<bool> NoDependenciesOption = new Option<bool>("--no-dependencies")
34-
{
35-
Description = CliCommandStrings.NoDependenciesOptionDescription,
36-
Arity = ArgumentArity.Zero
37-
}.ForwardAs("--property:BuildProjectReferences=false");
38-
39-
public static readonly Option<bool> NoLogoOption = CommonOptions.NoLogoOption();
40-
41-
public static readonly Option<bool> NoRestoreOption = CommonOptions.NoRestoreOption;
42-
43-
public static readonly Option<bool> SelfContainedOption = CommonOptions.SelfContainedOption;
44-
45-
public static readonly Option<bool> NoSelfContainedOption = CommonOptions.NoSelfContainedOption;
46-
47-
public static readonly Option<string> RuntimeOption = CommonOptions.RuntimeOption(CliCommandStrings.BuildRuntimeOptionDescription);
48-
49-
public static readonly Option<string> FrameworkOption = CommonOptions.FrameworkOption(CliCommandStrings.BuildFrameworkOptionDescription);
50-
51-
public static readonly Option<string?> ConfigurationOption = CommonOptions.ConfigurationOption(CliCommandStrings.BuildConfigurationOptionDescription);
52-
53-
/// <summary>
54-
/// Build actually means 'run the default Target' generally in MSBuild
55-
/// </summary>
56-
public static readonly Option<string[]?> TargetOption = CommonOptions.MSBuildTargetOption();
57-
58-
public static readonly Option<Utils.VerbosityOptions?> VerbosityOption = CommonOptions.VerbosityOption();
15+
return Command;
16+
}
5917

60-
public static Command CreateCommandDefinition()
18+
private static Command ConfigureCommand(Command command)
6119
{
62-
Command command = new("build", CliCommandStrings.BuildAppFullName)
63-
{
64-
DocsLink = DocsLink
65-
};
66-
67-
command.Arguments.Add(SlnOrProjectOrFileArgument);
68-
RestoreCommandParser.AddImplicitRestoreOptions(command, includeRuntimeOption: false, includeNoDependenciesOption: false);
69-
command.Options.Add(FrameworkOption);
70-
command.Options.Add(ConfigurationOption);
71-
command.Options.Add(RuntimeOption);
72-
command.Options.Add(CommonOptions.VersionSuffixOption);
73-
command.Options.Add(NoRestoreOption);
74-
command.Options.Add(CommonOptions.InteractiveMsBuildForwardOption);
75-
command.Options.Add(VerbosityOption);
76-
command.Options.Add(CommonOptions.DebugOption);
77-
command.Options.Add(OutputOption);
78-
command.Options.Add(CommonOptions.ArtifactsPathOption);
79-
command.Options.Add(NoIncrementalOption);
80-
command.Options.Add(NoDependenciesOption);
81-
command.Options.Add(NoLogoOption);
82-
command.Options.Add(SelfContainedOption);
83-
command.Options.Add(NoSelfContainedOption);
84-
command.Options.Add(CommonOptions.ArchitectureOption);
85-
command.Options.Add(CommonOptions.OperatingSystemOption);
86-
command.Options.Add(CommonOptions.DisableBuildServersOption);
87-
command.Options.Add(TargetOption);
88-
command.Options.Add(CommonOptions.GetPropertyOption);
89-
command.Options.Add(CommonOptions.GetItemOption);
90-
command.Options.Add(CommonOptions.GetTargetResultOption);
91-
command.Options.Add(CommonOptions.GetResultOutputFileOption);
92-
20+
command.SetAction(BuildCommand.Run);
9321
return command;
9422
}
9523
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#nullable disable
5+
6+
using System.CommandLine;
7+
using Microsoft.DotNet.Cli.Commands.BuildServer.Shutdown;
8+
using Microsoft.DotNet.Cli.CommandLine;
9+
using Microsoft.DotNet.Cli.Extensions;
10+
11+
namespace Microsoft.DotNet.Cli.Commands.BuildServer;
12+
13+
internal static class BuildServerCommandDefinition
14+
{
15+
public static readonly string DocsLink = "https://aka.ms/dotnet-build-server";
16+
17+
public static Command Create()
18+
{
19+
var command = new Command("build-server", CliCommandStrings.BuildServerCommandDescription)
20+
{
21+
DocsLink = DocsLink
22+
};
23+
24+
command.Subcommands.Add(BuildServerShutdownCommandParser.GetCommand());
25+
26+
return command;
27+
}
28+
}

src/Cli/dotnet/Commands/BuildServer/BuildServerCommandParser.Actions.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
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;
7-
using Microsoft.DotNet.Cli.Commands.BuildServer.Shutdown;
8-
using Microsoft.DotNet.Cli.CommandLine;
95
using Microsoft.DotNet.Cli.Extensions;
106

117
namespace Microsoft.DotNet.Cli.Commands.BuildServer;
128

13-
internal static partial class BuildServerCommandParser
9+
internal static class BuildServerCommandParser
1410
{
15-
public static readonly string DocsLink = "https://aka.ms/dotnet-build-server";
11+
private static readonly Command Command = ConfigureCommand(BuildServerCommandDefinition.Create());
1612

17-
public static Command CreateCommandDefinition()
13+
public static Command GetCommand()
1814
{
19-
var command = new Command("build-server", CliCommandStrings.BuildServerCommandDescription)
20-
{
21-
DocsLink = DocsLink
22-
};
23-
24-
command.Subcommands.Add(BuildServerShutdownCommandParser.GetCommand());
15+
return Command;
16+
}
2517

18+
private static Command ConfigureCommand(Command command)
19+
{
20+
command.SetAction((parseResult) => parseResult.HandleMissingCommand());
2621
return command;
2722
}
2823
}

src/Cli/dotnet/Commands/Clean/CleanCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static CommandBase FromParseResult(ParseResult result, string? msbuildPat
2222
result.ShowHelpOrErrorIfAppropriate();
2323
return CommandFactory.CreateVirtualOrPhysicalCommand(
2424
CleanCommandParser.GetCommand(),
25-
CleanCommandParser.SlnOrProjectOrFileArgument,
25+
CleanCommandDefinition.SlnOrProjectOrFileArgument,
2626
static (msbuildArgs, appFilePath) => new VirtualProjectBuildingCommand(
2727
entryPointFileFullPath: appFilePath,
2828
msbuildArgs: msbuildArgs)
@@ -33,7 +33,7 @@ public static CommandBase FromParseResult(ParseResult result, string? msbuildPat
3333
NoWriteBuildMarkers = true,
3434
},
3535
static (msbuildArgs, msbuildPath) => new CleanCommand(msbuildArgs, msbuildPath),
36-
[ CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, CleanCommandParser.TargetOption, CleanCommandParser.VerbosityOption, CleanCommandParser.NoLogoOption],
36+
[ CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, CleanCommandDefinition.TargetOption, CleanCommandDefinition.VerbosityOption, CleanCommandDefinition.NoLogoOption],
3737
result,
3838
msbuildPath
3939
);

0 commit comments

Comments
 (0)