Skip to content

Commit b0369ba

Browse files
committed
Subcommands 1
1 parent 0b19cbe commit b0369ba

File tree

109 files changed

+558
-762
lines changed

Some content is hidden

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

109 files changed

+558
-762
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static Command Create()
6565
DocumentedCommand command = new("build", DocsLink, CliCommandStrings.BuildAppFullName);
6666

6767
command.Arguments.Add(SlnOrProjectOrFileArgument);
68-
RestoreCommandParser.AddImplicitRestoreOptions(command, includeRuntimeOption: false, includeNoDependenciesOption: false);
68+
RestoreCommandDefinition.AddImplicitRestoreOptions(command, includeRuntimeOption: false, includeNoDependenciesOption: false);
6969
command.Options.Add(FrameworkOption);
7070
command.Options.Add(ConfigurationOption);
7171
command.Options.Add(RuntimeOption);

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

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

44
using System.CommandLine;
5-
using Microsoft.DotNet.Cli.Extensions;
65

76
namespace Microsoft.DotNet.Cli.Commands.Build;
87

98
internal static class BuildCommandParser
109
{
11-
private static readonly Command Command = ConfigureCommand(BuildCommandDefinition.Create());
10+
private static readonly Command Command = SetAction(BuildCommandDefinition.Create());
1211

1312
public static Command GetCommand()
1413
{
1514
return Command;
1615
}
1716

18-
private static Command ConfigureCommand(Command command)
17+
private static Command SetAction(Command command)
1918
{
2019
command.SetAction(BuildCommand.Run);
2120
return command;

src/Cli/dotnet/Commands/BuildServer/BuildServerCommandDefinition.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
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 Microsoft.DotNet.Cli.Commands.BuildServer.Shutdown;
8-
using Microsoft.DotNet.Cli.Extensions;
96

107
namespace Microsoft.DotNet.Cli.Commands.BuildServer;
118

129
internal static class BuildServerCommandDefinition
1310
{
11+
public const string Name = "build-server";
1412
public static readonly string DocsLink = "https://aka.ms/dotnet-build-server";
1513

1614
public static Command Create()
1715
{
18-
var command = new DocumentedCommand("build-server", DocsLink, CliCommandStrings.BuildServerCommandDescription);
16+
var command = new DocumentedCommand(Name, DocsLink, CliCommandStrings.BuildServerCommandDescription);
1917

20-
command.Subcommands.Add(BuildServerShutdownCommandParser.GetCommand());
18+
command.Subcommands.Add(BuildServerShutdownCommandDefinition.Create());
2119

2220
return command;
2321
}

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

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

44
using System.CommandLine;
5+
using Microsoft.DotNet.Cli.Commands.BuildServer.Shutdown;
56
using Microsoft.DotNet.Cli.Extensions;
67

78
namespace Microsoft.DotNet.Cli.Commands.BuildServer;
89

910
internal static class BuildServerCommandParser
1011
{
11-
private static readonly Command Command = ConfigureCommand(BuildServerCommandDefinition.Create());
12+
private static readonly Command Command = SetAction(BuildServerCommandDefinition.Create());
1213

1314
public static Command GetCommand()
1415
{
1516
return Command;
1617
}
1718

18-
private static Command ConfigureCommand(Command command)
19+
private static Command SetAction(Command command)
1920
{
2021
command.SetAction((parseResult) => parseResult.HandleMissingCommand());
22+
command.Subcommands.Single(c => c.Name == BuildServerCommandDefinition.Name).SetAction((parseResult) => new BuildServerShutdownCommand(parseResult).Execute());
2123
return command;
2224
}
2325
}

src/Cli/dotnet/Commands/BuildServer/Shutdown/BuildServerShutdownCommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public BuildServerShutdownCommand(
2525
IReporter reporter = null)
2626
: base(result)
2727
{
28-
bool msbuild = result.GetValue(BuildServerShutdownCommandParser.MSBuildOption);
29-
bool vbcscompiler = result.GetValue(BuildServerShutdownCommandParser.VbcsOption);
30-
bool razor = result.GetValue(BuildServerShutdownCommandParser.RazorOption);
28+
bool msbuild = result.GetValue(BuildServerShutdownCommandDefinition.MSBuildOption);
29+
bool vbcscompiler = result.GetValue(BuildServerShutdownCommandDefinition.VbcsOption);
30+
bool razor = result.GetValue(BuildServerShutdownCommandDefinition.RazorOption);
3131
bool all = !msbuild && !vbcscompiler && !razor;
3232

3333
_enumerationFlags = ServerEnumerationFlags.None;

src/Cli/dotnet/Commands/BuildServer/Shutdown/BuildServerShutdownCommandParser.cs renamed to src/Cli/dotnet/Commands/BuildServer/Shutdown/BuildServerShutdownCommandDefinition.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Microsoft.DotNet.Cli.Commands.BuildServer.Shutdown;
99

10-
internal static class BuildServerShutdownCommandParser
10+
internal static class BuildServerShutdownCommandDefinition
1111
{
1212
public static readonly Option<bool> MSBuildOption = new("--msbuild")
1313
{
@@ -27,23 +27,14 @@ internal static class BuildServerShutdownCommandParser
2727
Arity = ArgumentArity.Zero
2828
};
2929

30-
private static readonly Command Command = ConstructCommand();
31-
32-
public static Command GetCommand()
33-
{
34-
return Command;
35-
}
36-
37-
private static Command ConstructCommand()
30+
public static Command Create()
3831
{
3932
Command command = new("shutdown", CliCommandStrings.BuildServerShutdownCommandDescription);
4033

4134
command.Options.Add(MSBuildOption);
4235
command.Options.Add(VbcsOption);
4336
command.Options.Add(RazorOption);
4437

45-
command.SetAction((parseResult) => new BuildServerShutdownCommand(parseResult).Execute());
46-
4738
return command;
4839
}
4940
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static Command Create()
5656
command.Options.Add(CommonOptions.GetItemOption);
5757
command.Options.Add(CommonOptions.GetTargetResultOption);
5858
command.Options.Add(CommonOptions.GetResultOutputFileOption);
59-
command.Subcommands.Add(CleanFileBasedAppArtifactsCommandParser.Command);
59+
command.Subcommands.Add(CleanFileBasedAppArtifactsCommandDefinition.Create());
6060

6161
return command;
6262
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,25 @@
33

44
using System.CommandLine;
55
using Microsoft.DotNet.Cli.Commands.Clean.FileBasedAppArtifacts;
6-
using Microsoft.DotNet.Cli.Extensions;
76

87
namespace Microsoft.DotNet.Cli.Commands.Clean;
98

109
internal static class CleanCommandParser
1110
{
12-
13-
private static readonly Command Command = ConfigureCommand(CleanCommandDefinition.Create());
11+
private static readonly Command Command = SetAction(CleanCommandDefinition.Create());
1412

1513
public static Command GetCommand()
1614
{
1715
return Command;
1816
}
1917

20-
private static Command ConfigureCommand(Command command)
18+
private static Command SetAction(Command command)
2119
{
2220
command.SetAction(CleanCommand.Run);
21+
22+
command.Subcommands.Single(c => c.Name == CleanFileBasedAppArtifactsCommandDefinition.Name)
23+
.SetAction(parseResult => new CleanFileBasedAppArtifactsCommand(parseResult).Execute());
24+
2325
return command;
2426
}
2527
}

src/Cli/dotnet/Commands/Clean/FileBasedAppArtifacts/CleanFileBasedAppArtifactsCommand.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal sealed class CleanFileBasedAppArtifactsCommand(ParseResult parseResult)
1414
{
1515
public override int Execute()
1616
{
17-
bool dryRun = _parseResult.GetValue(CleanFileBasedAppArtifactsCommandParser.DryRunOption);
17+
bool dryRun = _parseResult.GetValue(CleanFileBasedAppArtifactsCommandDefinition.DryRunOption);
1818

1919
using var metadataFileStream = OpenMetadataFile();
2020

@@ -70,7 +70,7 @@ private IEnumerable<DirectoryInfo> GetFoldersToRemove()
7070

7171
Reporter.Output.WriteLine(CliCommandStrings.CleanFileBasedAppArtifactsScanning, directory.FullName);
7272

73-
var days = _parseResult.GetValue(CleanFileBasedAppArtifactsCommandParser.DaysOption);
73+
var days = _parseResult.GetValue(CleanFileBasedAppArtifactsCommandDefinition.DaysOption);
7474
var cutoff = DateTime.UtcNow.AddDays(-days);
7575

7676
foreach (var subdir in directory.GetDirectories())
@@ -89,7 +89,7 @@ private static FileInfo GetMetadataFile()
8989

9090
private FileStream? OpenMetadataFile()
9191
{
92-
if (!_parseResult.GetValue(CleanFileBasedAppArtifactsCommandParser.AutomaticOption))
92+
if (!_parseResult.GetValue(CleanFileBasedAppArtifactsCommandDefinition.AutomaticOption))
9393
{
9494
return null;
9595
}
@@ -127,8 +127,8 @@ public static void StartAutomaticCleanupIfNeeded()
127127
Arguments = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(
128128
[
129129
CleanCommandParser.GetCommand().Name,
130-
CleanFileBasedAppArtifactsCommandParser.Command.Name,
131-
CleanFileBasedAppArtifactsCommandParser.AutomaticOption.Name,
130+
CleanFileBasedAppArtifactsCommandDefinition.Name,
131+
CleanFileBasedAppArtifactsCommandDefinition.AutomaticOption.Name,
132132
]),
133133
UseShellExecute = false,
134134
RedirectStandardInput = true,
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
namespace Microsoft.DotNet.Cli.Commands.Clean.FileBasedAppArtifacts;
77

8-
internal sealed class CleanFileBasedAppArtifactsCommandParser
8+
internal sealed class CleanFileBasedAppArtifactsCommandDefinition
99
{
10+
public const string Name = "file-based-apps";
11+
1012
public static readonly Option<bool> DryRunOption = new("--dry-run")
1113
{
1214
Description = CliCommandStrings.CleanFileBasedAppArtifactsDryRun,
@@ -28,11 +30,8 @@ internal sealed class CleanFileBasedAppArtifactsCommandParser
2830
Hidden = true,
2931
};
3032

31-
public static Command Command => field ??= ConstructCommand();
32-
33-
private static Command ConstructCommand()
34-
{
35-
Command command = new("file-based-apps", CliCommandStrings.CleanFileBasedAppArtifactsCommandDescription)
33+
public static Command Create()
34+
=> new(Name, CliCommandStrings.CleanFileBasedAppArtifactsCommandDescription)
3635
{
3736
Hidden = true,
3837
Options =
@@ -42,8 +41,4 @@ private static Command ConstructCommand()
4241
AutomaticOption,
4342
},
4443
};
45-
46-
command.SetAction((parseResult) => new CleanFileBasedAppArtifactsCommand(parseResult).Execute());
47-
return command;
48-
}
4944
}

0 commit comments

Comments
 (0)