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 @@ -25,11 +25,12 @@ internal static class RestoreCommandParser
}.ForwardAsSingle(o => $"-property:RestoreSources={string.Join("%3B", o)}")
.AllowSingleArgPerToken();

private static IEnumerable<CliOption> FullRestoreOptions() =>
private static IEnumerable<CliOption> FullRestoreOptions() =>
ImplicitRestoreOptions(true, true, true, true).Concat(
new CliOption[] {
[
CommonOptions.VerbosityOption,
CommonOptions.InteractiveMsBuildForwardOption,
CommonOptions.ArtifactsPathOption,
new ForwardedOption<bool>("--use-lock-file")
{
Description = LocalizableStrings.CmdUseLockFileOptionDescription,
Expand All @@ -46,7 +47,8 @@ private static IEnumerable<CliOption> FullRestoreOptions() =>
new ForwardedOption<bool>("--force-evaluate")
{
Description = LocalizableStrings.CmdReevaluateOptionDescription
}.ForwardAs("-property:RestoreForceEvaluate=true") });
}.ForwardAs("-property:RestoreForceEvaluate=true"),
]);

private static readonly CliCommand Command = ConstructCommand();

Expand Down
1 change: 1 addition & 0 deletions src/Cli/dotnet/commands/dotnet-run/RunCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private static CliCommand ConstructCommand()
command.Options.Add(CommonOptions.ArchitectureOption);
command.Options.Add(CommonOptions.OperatingSystemOption);
command.Options.Add(CommonOptions.DisableBuildServersOption);
command.Options.Add(CommonOptions.ArtifactsPathOption);

command.Arguments.Add(ApplicationArguments);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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;
using Microsoft.DotNet.Cli.CommandLineValidation;
using Microsoft.DotNet.Tools.Common;
using Parser = Microsoft.DotNet.Cli.Parser;

namespace Microsoft.DotNet.Tests.ParserTests
{
public class BuildRelatedCommandParserTests
{

/// <summary>
/// These commands all implicitly use MSBuild under the covers and generally should expose
/// the same set of property- and behavior-impacting options.
/// </summary>
private static string[] BuildRelatedCommands = [
"build",
"clean",
"pack",
"publish",
"restore",
"run",
"test"
];

private static string[] OptionsToVerify = [
"--artifacts-path"
];

public static TheoryData<string, string> BuildRelatedCommandsAndOptions()
{
var data = new TheoryData<string, string>();
foreach (var cmd in BuildRelatedCommands)
{
foreach (var opt in OptionsToVerify)
{
data.Add(cmd, opt);
}
}
return data;
}

[MemberData(nameof(BuildRelatedCommandsAndOptions))]
[Theory]
public void Build(string command, string option)
{
var cliCommand = Parser.Instance.RootCommand.Children.OfType<CliCommand>().FirstOrDefault(c => c.Name == command);
if (cliCommand is null)
{
throw new ArgumentException($"Command {command} not found in the dotnet CLI");
}
var cliOption = cliCommand.Children.OfType<CliOption>().FirstOrDefault(o => o.Name == option || o.Aliases.Contains(option));
if (cliOption is null)
{
throw new ArgumentException($"Option {option} not found in the {command} command");
}
}
}
}