Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Cli/dotnet/CommandLineInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void PrintInfo()
Reporter.Output.WriteLine($"{LocalizableStrings.DotNetSdkInfoLabel}");
Reporter.Output.WriteLine($" Version: {Product.Version}");
Reporter.Output.WriteLine($" Commit: {commitSha}");
Reporter.Output.WriteLine($" Workload version: {WorkloadCommandParser.GetWorkloadsVersion()}");
Reporter.Output.WriteLine($" Workload version: {WorkloadCommandDefinition.GetWorkloadsVersion()}");
Reporter.Output.WriteLine($" MSBuild version: {MSBuildForwardingAppWithoutLogging.MSBuildVersion.ToString()}");
Reporter.Output.WriteLine();
Reporter.Output.WriteLine($"{LocalizableStrings.DotNetRuntimeInfoLabel}");
Expand All @@ -40,7 +40,7 @@ private static void PrintWorkloadsInfo()
{
Reporter.Output.WriteLine();
Reporter.Output.WriteLine($"{LocalizableStrings.DotnetWorkloadInfoLabel}");
WorkloadCommandParser.ShowWorkloadsInfo(showVersion: false);
WorkloadCommandDefinition.ShowWorkloadsInfo(showVersion: false);
}

private static string GetDisplayRid(DotnetVersionFile versionFile)
Expand Down
10 changes: 5 additions & 5 deletions src/Cli/dotnet/Commands/Build/BuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public static CommandBase FromParseResult(ParseResult parseResult, string? msbui
parseResult.ShowHelpOrErrorIfAppropriate();

CommonOptions.ValidateSelfContainedOptions(
parseResult.HasOption(BuildCommandParser.SelfContainedOption),
parseResult.HasOption(BuildCommandParser.NoSelfContainedOption));
parseResult.HasOption(BuildCommandDefinition.SelfContainedOption),
parseResult.HasOption(BuildCommandDefinition.NoSelfContainedOption));

bool noRestore = parseResult.HasOption(BuildCommandParser.NoRestoreOption);
bool noRestore = parseResult.HasOption(BuildCommandDefinition.NoRestoreOption);

return CommandFactory.CreateVirtualOrPhysicalCommand(
BuildCommandParser.GetCommand(),
BuildCommandParser.SlnOrProjectOrFileArgument,
BuildCommandDefinition.SlnOrProjectOrFileArgument,
(msbuildArgs, appFilePath) => new VirtualProjectBuildingCommand(
entryPointFileFullPath: Path.GetFullPath(appFilePath),
msbuildArgs: msbuildArgs
Expand All @@ -43,7 +43,7 @@ public static CommandBase FromParseResult(ParseResult parseResult, string? msbui
noRestore: noRestore,
msbuildPath: msbuildPath
),
[CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, BuildCommandParser.TargetOption, BuildCommandParser.VerbosityOption, BuildCommandParser.NoLogoOption],
[CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, BuildCommandDefinition.TargetOption, BuildCommandDefinition.VerbosityOption, BuildCommandDefinition.NoLogoOption],
parseResult,
msbuildPath
);
Expand Down
95 changes: 95 additions & 0 deletions src/Cli/dotnet/Commands/Build/BuildCommandDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Commands.Restore;
using Microsoft.DotNet.Cli.Extensions;

namespace Microsoft.DotNet.Cli.Commands.Build;

internal static class BuildCommandDefinition
{
public static readonly string DocsLink = "https://aka.ms/dotnet-build";

public static readonly Argument<string[]> SlnOrProjectOrFileArgument = new(CliStrings.SolutionOrProjectOrFileArgumentName)
{
Description = CliStrings.SolutionOrProjectOrFileArgumentDescription,
Arity = ArgumentArity.ZeroOrMore
};

public static readonly Option<string> OutputOption = new Option<string>("--output", "-o")
{
Description = CliCommandStrings.BuildOutputOptionDescription,
HelpName = CliCommandStrings.OutputOptionName
}.ForwardAsOutputPath("OutputPath");

public static readonly Option<bool> NoIncrementalOption = new Option<bool>("--no-incremental")
{
Description = CliCommandStrings.NoIncrementalOptionDescription,
Arity = ArgumentArity.Zero
}.ForwardAs("--target:Rebuild");

public static readonly Option<bool> NoDependenciesOption = new Option<bool>("--no-dependencies")
{
Description = CliCommandStrings.NoDependenciesOptionDescription,
Arity = ArgumentArity.Zero
}.ForwardAs("--property:BuildProjectReferences=false");

public static readonly Option<bool> NoLogoOption = CommonOptions.NoLogoOption();

public static readonly Option<bool> NoRestoreOption = CommonOptions.NoRestoreOption;

public static readonly Option<bool> SelfContainedOption = CommonOptions.SelfContainedOption;

public static readonly Option<bool> NoSelfContainedOption = CommonOptions.NoSelfContainedOption;

public static readonly Option<string> RuntimeOption = CommonOptions.RuntimeOption(CliCommandStrings.BuildRuntimeOptionDescription);

public static readonly Option<string> FrameworkOption = CommonOptions.FrameworkOption(CliCommandStrings.BuildFrameworkOptionDescription);

public static readonly Option<string?> ConfigurationOption = CommonOptions.ConfigurationOption(CliCommandStrings.BuildConfigurationOptionDescription);

/// <summary>
/// Build actually means 'run the default Target' generally in MSBuild
/// </summary>
public static readonly Option<string[]?> TargetOption = CommonOptions.MSBuildTargetOption();

public static readonly Option<Utils.VerbosityOptions?> VerbosityOption = CommonOptions.VerbosityOption();

public static Command Create()
{
Command command = new("build", CliCommandStrings.BuildAppFullName)
{
DocsLink = DocsLink
};

command.Arguments.Add(SlnOrProjectOrFileArgument);
RestoreCommandDefinition.AddImplicitRestoreOptions(command, includeRuntimeOption: false, includeNoDependenciesOption: false);
command.Options.Add(FrameworkOption);
command.Options.Add(ConfigurationOption);
command.Options.Add(RuntimeOption);
command.Options.Add(CommonOptions.VersionSuffixOption);
command.Options.Add(NoRestoreOption);
command.Options.Add(CommonOptions.InteractiveMsBuildForwardOption);
command.Options.Add(VerbosityOption);
command.Options.Add(CommonOptions.DebugOption);
command.Options.Add(OutputOption);
command.Options.Add(CommonOptions.ArtifactsPathOption);
command.Options.Add(NoIncrementalOption);
command.Options.Add(NoDependenciesOption);
command.Options.Add(NoLogoOption);
command.Options.Add(SelfContainedOption);
command.Options.Add(NoSelfContainedOption);
command.Options.Add(CommonOptions.ArchitectureOption);
command.Options.Add(CommonOptions.OperatingSystemOption);
command.Options.Add(CommonOptions.DisableBuildServersOption);
command.Options.Add(TargetOption);
command.Options.Add(CommonOptions.GetPropertyOption);
command.Options.Add(CommonOptions.GetItemOption);
command.Options.Add(CommonOptions.GetTargetResultOption);
command.Options.Add(CommonOptions.GetResultOutputFileOption);

return command;
}
}
86 changes: 2 additions & 84 deletions src/Cli/dotnet/Commands/Build/BuildCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,103 +2,21 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Commands.Restore;
using Microsoft.DotNet.Cli.Extensions;

namespace Microsoft.DotNet.Cli.Commands.Build;

internal static class BuildCommandParser
{
public static readonly string DocsLink = "https://aka.ms/dotnet-build";

public static readonly Argument<string[]> SlnOrProjectOrFileArgument = new(CliStrings.SolutionOrProjectOrFileArgumentName)
{
Description = CliStrings.SolutionOrProjectOrFileArgumentDescription,
Arity = ArgumentArity.ZeroOrMore
};

public static readonly Option<string> OutputOption = new Option<string>("--output", "-o")
{
Description = CliCommandStrings.BuildOutputOptionDescription,
HelpName = CliCommandStrings.OutputOptionName
}.ForwardAsOutputPath("OutputPath");

public static readonly Option<bool> NoIncrementalOption = new Option<bool>("--no-incremental")
{
Description = CliCommandStrings.NoIncrementalOptionDescription,
Arity = ArgumentArity.Zero
}.ForwardAs("--target:Rebuild");

public static readonly Option<bool> NoDependenciesOption = new Option<bool>("--no-dependencies")
{
Description = CliCommandStrings.NoDependenciesOptionDescription,
Arity = ArgumentArity.Zero
}.ForwardAs("--property:BuildProjectReferences=false");

public static readonly Option<bool> NoLogoOption = CommonOptions.NoLogoOption();

public static readonly Option<bool> NoRestoreOption = CommonOptions.NoRestoreOption;

public static readonly Option<bool> SelfContainedOption = CommonOptions.SelfContainedOption;

public static readonly Option<bool> NoSelfContainedOption = CommonOptions.NoSelfContainedOption;

public static readonly Option<string> RuntimeOption = CommonOptions.RuntimeOption(CliCommandStrings.BuildRuntimeOptionDescription);

public static readonly Option<string> FrameworkOption = CommonOptions.FrameworkOption(CliCommandStrings.BuildFrameworkOptionDescription);

public static readonly Option<string?> ConfigurationOption = CommonOptions.ConfigurationOption(CliCommandStrings.BuildConfigurationOptionDescription);

/// <summary>
/// Build actually means 'run the default Target' generally in MSBuild
/// </summary>
public static readonly Option<string[]?> TargetOption = CommonOptions.MSBuildTargetOption();

public static readonly Option<Utils.VerbosityOptions?> VerbosityOption = CommonOptions.VerbosityOption();

private static readonly Command Command = ConstructCommand();
private static readonly Command Command = SetAction(BuildCommandDefinition.Create());

public static Command GetCommand()
{
return Command;
}

private static Command ConstructCommand()
private static Command SetAction(Command command)
{
Command command = new("build", CliCommandStrings.BuildAppFullName)
{
DocsLink = DocsLink
};

command.Arguments.Add(SlnOrProjectOrFileArgument);
RestoreCommandParser.AddImplicitRestoreOptions(command, includeRuntimeOption: false, includeNoDependenciesOption: false);
command.Options.Add(FrameworkOption);
command.Options.Add(ConfigurationOption);
command.Options.Add(RuntimeOption);
command.Options.Add(CommonOptions.VersionSuffixOption);
command.Options.Add(NoRestoreOption);
command.Options.Add(CommonOptions.InteractiveMsBuildForwardOption);
command.Options.Add(VerbosityOption);
command.Options.Add(CommonOptions.DebugOption);
command.Options.Add(OutputOption);
command.Options.Add(CommonOptions.ArtifactsPathOption);
command.Options.Add(NoIncrementalOption);
command.Options.Add(NoDependenciesOption);
command.Options.Add(NoLogoOption);
command.Options.Add(SelfContainedOption);
command.Options.Add(NoSelfContainedOption);
command.Options.Add(CommonOptions.ArchitectureOption);
command.Options.Add(CommonOptions.OperatingSystemOption);
command.Options.Add(CommonOptions.DisableBuildServersOption);
command.Options.Add(TargetOption);
command.Options.Add(CommonOptions.GetPropertyOption);
command.Options.Add(CommonOptions.GetItemOption);
command.Options.Add(CommonOptions.GetTargetResultOption);
command.Options.Add(CommonOptions.GetResultOutputFileOption);

command.SetAction(BuildCommand.Run);

return command;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using Microsoft.DotNet.Cli.Commands.BuildServer.Shutdown;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Extensions;

namespace Microsoft.DotNet.Cli.Commands.BuildServer;

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

public static Command Create()
{
var command = new Command(Name, CliCommandStrings.BuildServerCommandDescription)
{
DocsLink = DocsLink
};

command.Subcommands.Add(BuildServerShutdownCommandDefinition.Create());

return command;
}
}
18 changes: 3 additions & 15 deletions src/Cli/dotnet/Commands/BuildServer/BuildServerCommandParser.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable

using System.CommandLine;
using Microsoft.DotNet.Cli.Commands.BuildServer.Shutdown;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Extensions;

namespace Microsoft.DotNet.Cli.Commands.BuildServer;

internal static class BuildServerCommandParser
{
public static readonly string DocsLink = "https://aka.ms/dotnet-build-server";

private static readonly Command Command = ConstructCommand();
private static readonly Command Command = SetAction(BuildServerCommandDefinition.Create());

public static Command GetCommand()
{
return Command;
}

private static Command ConstructCommand()
private static Command SetAction(Command command)
{
var command = new Command("build-server", CliCommandStrings.BuildServerCommandDescription)
{
DocsLink = DocsLink
};

command.Subcommands.Add(BuildServerShutdownCommandParser.GetCommand());

command.SetAction((parseResult) => parseResult.HandleMissingCommand());

command.Subcommands.Single(c => c.Name == BuildServerCommandDefinition.Name).SetAction((parseResult) => new BuildServerShutdownCommand(parseResult).Execute());
return command;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public BuildServerShutdownCommand(
IReporter reporter = null)
: base(result)
{
bool msbuild = result.GetValue(BuildServerShutdownCommandParser.MSBuildOption);
bool vbcscompiler = result.GetValue(BuildServerShutdownCommandParser.VbcsOption);
bool razor = result.GetValue(BuildServerShutdownCommandParser.RazorOption);
bool msbuild = result.GetValue(BuildServerShutdownCommandDefinition.MSBuildOption);
bool vbcscompiler = result.GetValue(BuildServerShutdownCommandDefinition.VbcsOption);
bool razor = result.GetValue(BuildServerShutdownCommandDefinition.RazorOption);
bool all = !msbuild && !vbcscompiler && !razor;

_enumerationFlags = ServerEnumerationFlags.None;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

internal static class BuildServerShutdownCommandParser
internal static class BuildServerShutdownCommandDefinition
{
public static readonly Option<bool> MSBuildOption = new("--msbuild")
{
Expand All @@ -27,23 +27,14 @@ internal static class BuildServerShutdownCommandParser
Arity = ArgumentArity.Zero
};

private static readonly Command Command = ConstructCommand();

public static Command GetCommand()
{
return Command;
}

private static Command ConstructCommand()
public static Command Create()
{
Command command = new("shutdown", CliCommandStrings.BuildServerShutdownCommandDescription);

command.Options.Add(MSBuildOption);
command.Options.Add(VbcsOption);
command.Options.Add(RazorOption);

command.SetAction((parseResult) => new BuildServerShutdownCommand(parseResult).Execute());

return command;
}
}
4 changes: 2 additions & 2 deletions src/Cli/dotnet/Commands/Clean/CleanCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static CommandBase FromParseResult(ParseResult result, string? msbuildPat
result.ShowHelpOrErrorIfAppropriate();
return CommandFactory.CreateVirtualOrPhysicalCommand(
CleanCommandParser.GetCommand(),
CleanCommandParser.SlnOrProjectOrFileArgument,
CleanCommandDefinition.SlnOrProjectOrFileArgument,
static (msbuildArgs, appFilePath) => new VirtualProjectBuildingCommand(
entryPointFileFullPath: appFilePath,
msbuildArgs: msbuildArgs)
Expand All @@ -33,7 +33,7 @@ public static CommandBase FromParseResult(ParseResult result, string? msbuildPat
NoWriteBuildMarkers = true,
},
static (msbuildArgs, msbuildPath) => new CleanCommand(msbuildArgs, msbuildPath),
[ CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, CleanCommandParser.TargetOption, CleanCommandParser.VerbosityOption, CleanCommandParser.NoLogoOption],
[ CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, CleanCommandDefinition.TargetOption, CleanCommandDefinition.VerbosityOption, CleanCommandDefinition.NoLogoOption],
result,
msbuildPath
);
Expand Down
Loading
Loading