Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,16 @@ public Option<IEnumerable<string>> ForwardAsManyArgumentsEachPrefixedByOption(st
/// <summary>
/// Calls the forwarding functions for all options that have declared a forwarding function (via <see cref="ForwardedOptionExtensions"/>'s extension members) in the provided <see cref="ParseResult"/>.
/// </summary>
/// <param name="parseResult"></param>
/// <param name="command">If not provided, uses the <see cref="ParseResult.CommandResult" />'s <see cref="CommandResult.Command"/>.</param>
/// <returns></returns>
public IEnumerable<string> OptionValuesToBeForwarded(Command? command = null) =>
(command ?? parseResult.CommandResult.Command)
.Options
public IEnumerable<string> OptionValuesToBeForwarded(Command? command = null)
=> parseResult.OptionValuesToBeForwarded((command ?? parseResult.CommandResult.Command).Options);

/// <summary>
/// Calls the forwarding functions for all options that have declared a forwarding function (via <see cref="ForwardedOptionExtensions"/>'s extension members) in the provided <see cref="ParseResult"/>.
/// </summary>
/// <param name="command">If not provided, uses the <see cref="ParseResult.CommandResult" />'s <see cref="CommandResult.Command"/>.</param>
public IEnumerable<string> OptionValuesToBeForwarded(IEnumerable<Option> options)
=> options
.Select(o => o.ForwardingFunction)
.SelectMany(f => f is not null ? f(parseResult) : []);

Expand All @@ -191,9 +195,6 @@ public IEnumerable<string> OptionValuesToBeForwarded(Command? command = null) =>
/// invokes its forwarding function (if any) and returns the result. If no option with that name is found, or if the option
/// has no forwarding function, returns an empty enumeration.
/// </summary>
/// <param name="command"></param>
/// <param name="alias"></param>
/// <returns></returns>
public IEnumerable<string> ForwardedOptionValues(Command command, string alias)
{
var func = command.Options?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ internal void GenerateDepsJsonFile(
string? stdOut;
string? stdErr;

var msbuildArgs = MSBuildArgs.AnalyzeMSBuildArguments([..args], CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, BuildCommandParser.TargetOption, BuildCommandParser.VerbosityOption, BuildCommandParser.NoLogoOption);
var msbuildArgs = MSBuildArgs.AnalyzeMSBuildArguments([..args], CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, BuildCommandDefinition.TargetOption, BuildCommandDefinition.VerbosityOption, BuildCommandDefinition.NoLogoOption);
var forwardingAppWithoutLogging = new MSBuildForwardingAppWithoutLogging(msbuildArgs, msBuildExePath);
if (forwardingAppWithoutLogging.ExecuteMSBuildOutOfProc)
{
Expand Down
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 == BuildServerShutdownCommandDefinition.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
Loading
Loading