Skip to content
Open
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 @@ -42,5 +42,11 @@ public T AddCompletions(Func<CompletionContext, IEnumerable<CompletionItem>> com
option.CompletionSources.Add(completionSource);
return option;
}

public T Recursive(bool isRecursive = true)
{
option.Recursive = isRecursive;
return option;
}
}
}
13 changes: 6 additions & 7 deletions src/Cli/Microsoft.DotNet.Cli.Utils/MSBuildArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ private MSBuildArgs(
string[]? getItem,
string[]? getTargetResult,
string[]? getResultOutputFile,
VerbosityOptions? verbosity,
Verbosity? verbosity,
bool noLogo,
string[]? otherMSBuildArgs
)
string[]? otherMSBuildArgs)
{
GlobalProperties = properties;
RestoreGlobalProperties = restoreProperties;
Expand Down Expand Up @@ -74,7 +73,7 @@ private MSBuildArgs(
/// </summary>
public string[]? GetResultOutputFile { get; }

public VerbosityOptions? Verbosity { get; }
public Verbosity? Verbosity { get; }

/// <summary>
/// Whether or not the MSBuild product header text should be emitted at the start of this build
Expand Down Expand Up @@ -116,7 +115,7 @@ public static MSBuildArgs AnalyzeMSBuildArguments(IEnumerable<string> forwardedA
var getItem = TryGetValue<string[]?>("--getItem");
var getTargetResult = TryGetValue<string[]?>("--getTargetResult");
var getResultOutputFile = TryGetValue<string[]?>("--getResultOutputFile");
var verbosity = TryGetValue<VerbosityOptions?>("--verbosity");
var verbosity = TryGetValue<Verbosity?>("--verbosity");
var nologo = TryGetValue<bool?>("--no-logo") ?? true; // Default to nologo if not specified
var otherMSBuildArgs = parseResult.UnmatchedTokens.ToArray();
return new MSBuildArgs(
Expand Down Expand Up @@ -150,7 +149,7 @@ public static MSBuildArgs FromOtherArgs(params ReadOnlySpan<string> args)
{
return new MSBuildArgs(null, null, null, null, null, null, null, null, noLogo: false, args.ToArray());
}
public static MSBuildArgs FromVerbosity(VerbosityOptions verbosity)
public static MSBuildArgs FromVerbosity(Verbosity verbosity)
{
return new MSBuildArgs(null, null, null, null, null, null, null, verbosity, noLogo: false, null);
}
Expand Down Expand Up @@ -327,7 +326,7 @@ public MSBuildArgs CloneWithAdditionalTargets(params ReadOnlySpan<string> additi
OtherMSBuildArgs.ToArray());
}

public MSBuildArgs CloneWithVerbosity(VerbosityOptions newVerbosity)
public MSBuildArgs CloneWithVerbosity(Verbosity newVerbosity)
{
return new MSBuildArgs(
GlobalProperties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static string MSBuildVersion

private const string SdksDirectoryName = "Sdks";

internal const VerbosityOptions DefaultVerbosity = VerbosityOptions.m;
internal const Verbosity DefaultVerbosity = Verbosity.minimal;

// Null if we're running MSBuild in-proc.
private ForwardingAppImplementation? _forwardingApp;
Expand Down
31 changes: 31 additions & 0 deletions src/Cli/Microsoft.DotNet.Cli.Utils/Verbosity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace Microsoft.DotNet.Cli.Utils;

/// <summary>
/// Represents the desired verbosity level for command output.
/// Maps mostly to MSBuild's verbosity levels.
/// </summary>
public enum Verbosity
{
quiet,
minimal,
normal,
detailed,
diagnostic
Comment on lines +9 to +13
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I asked this in the past, but I forgot the answer. Is it necessary for these to be lowercase? It is just anti-C# style to have public things be entirely lowercase.

}

public static class VerbosityData
{
public static string[] VerbosityNames =
[
"quiet",
"q",
"minimal",
"m",
"normal",
"n",
"detailed",
"d",
"diagnostic",
"diag"
];
}
21 changes: 0 additions & 21 deletions src/Cli/Microsoft.DotNet.Cli.Utils/VerbosityOptions.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/Cli/dotnet/CliSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ private static RootCommandDetails CreateRootCommandDetails(Command command)

/// <summary>
/// Maps some types that don't serialize well to more human-readable strings.
/// For example, <see cref="VerbosityOptions"/> is serialized as a string instead of an integer.
/// For example, <see cref="Verbosity"/> is serialized as a string instead of an integer.
/// </summary>
private static object? HumanizeValue(object? v) => v switch
{
VerbosityOptions o => Enum.GetName(o),
Verbosity o => Enum.GetName(o),
null => null,
_ => v // For other types, return as is
};
Expand Down
7 changes: 6 additions & 1 deletion src/Cli/dotnet/CliStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,12 @@
{1}.</value>
</data>
<data name="VerbosityOptionDescription" xml:space="preserve">
<value>Set the MSBuild verbosity level. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic].</value>
<value>Set the MSBuild verbosity level. Allowed values are: {0}.</value>
<comment>{0} is a comma-separated list of allowed string values</comment>
</data>
<data name="VerbosityParserInvalidToken" xml:space="preserve">
<value>'{0}' is not a valid value for --verbosity. Allowed values are: {1}.</value>
<comment>{0} is the invalid token, {1} is a comma-separated list of allowed string values</comment>
</data>
<data name="CmdVersionSuffixDescription" xml:space="preserve">
<value>Set the value of the $(VersionSuffix) property to use when building the project.</value>
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Commands/Build/BuildCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal static class BuildCommandParser
/// </summary>
public static readonly Option<string[]?> TargetOption = CommonOptions.MSBuildTargetOption();

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was probably a name-clash reason that it was prefixed with Utils.. Does that clash still exist with Verbosity?


private static readonly Command Command = ConstructCommand();

Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Commands/Clean/CleanCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal static class CleanCommandParser

public static readonly Option<string[]> TargetOption = CommonOptions.RequiredMSBuildTargetOption("Clean");

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


private static readonly Command Command = ConstructCommand();
Expand Down
3 changes: 2 additions & 1 deletion src/Cli/dotnet/Commands/CliCommandStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2280,7 +2280,8 @@ and the corresponding package Ids for installed tools using the command
<value>Shut down the VB/C# compiler build server.</value>
</data>
<data name="Verbosity_OptionDescription" xml:space="preserve">
<value>Sets the verbosity level. Allowed values are q[uiet], m[inimal], n[ormal], and diag[nostic].</value>
<value>Sets the verbosity level. Allowed values are: {0}.</value>
<comment>{0} is a comma separated list of verbosity levels: quiet, minimal, normal, detailed, diagnostic</comment>
</data>
<data name="VerbosityArgumentName" xml:space="preserve">
<value>Verbosity</value>
Expand Down
19 changes: 8 additions & 11 deletions src/Cli/dotnet/Commands/New/NewCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal static class NewCommandParser

private const string HostIdentifier = "dotnetcli";

private const VerbosityOptions DefaultVerbosity = VerbosityOptions.normal;
private const Verbosity DefaultVerbosity = Verbosity.normal;

private static readonly Option<bool> s_disableSdkTemplatesOption = new Option<bool>("--debug:disable-sdk-templates")
{
Expand All @@ -48,13 +48,10 @@ internal static class NewCommandParser
Recursive = true
}.Hide();

private static readonly Option<VerbosityOptions> s_verbosityOption = new("--verbosity", "-v")
{
DefaultValueFactory = _ => DefaultVerbosity,
Description = CliCommandStrings.Verbosity_OptionDescription,
HelpName = CliStrings.LevelArgumentName,
Recursive = true
};
private static readonly Option<Verbosity> s_verbosityOption =
CommonOptions.VerbosityOption(DefaultVerbosity)
.WithDescription(string.Format(CliCommandStrings.Verbosity_OptionDescription, string.Join(", ", VerbosityData.VerbosityNames)))
.Recursive();

private static readonly Option<bool> s_diagnosticOption =
CommonOptionsFactory
Expand Down Expand Up @@ -82,22 +79,22 @@ static CliTemplateEngineHost GetEngineHost(ParseResult parseResult)
FileInfo? outputPath = parseResult.GetValue(SharedOptions.OutputOption);

OptionResult? verbosityOptionResult = parseResult.GetResult(s_verbosityOption);
VerbosityOptions verbosity = DefaultVerbosity;
Verbosity verbosity = DefaultVerbosity;

if (diagnosticMode || CommandLoggingContext.IsVerbose)
{
CommandLoggingContext.SetError(true);
CommandLoggingContext.SetOutput(true);
CommandLoggingContext.SetVerbose(true);
verbosity = VerbosityOptions.diagnostic;
verbosity = Verbosity.diagnostic;
}
else if (verbosityOptionResult != null
&& !verbosityOptionResult.Implicit
// if verbosityOptionResult contains an error, ArgumentConverter.GetValueOrDefault throws an exception
// and callstack is pushed to process output
&& !parseResult.Errors.Any(error => error.SymbolResult == verbosityOptionResult))
{
VerbosityOptions userSetVerbosity = verbosityOptionResult.GetValueOrDefault<VerbosityOptions>();
Verbosity userSetVerbosity = verbosityOptionResult.GetValueOrDefault<Verbosity>();
if (userSetVerbosity.IsQuiet())
{
CommandLoggingContext.SetError(false);
Expand Down
8 changes: 4 additions & 4 deletions src/Cli/dotnet/Commands/NuGet/NuGetCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private static Command GetVerifyCommand()
verifyCommand.Options.Add(new Option<IEnumerable<string>>(fingerprint)
.ForwardAsManyArgumentsEachPrefixedByOption(fingerprint)
.AllowSingleArgPerToken());
verifyCommand.Options.Add(CommonOptions.VerbosityOption(Utils.VerbosityOptions.normal));
verifyCommand.Options.Add(CommonOptions.VerbosityOption(Utils.Verbosity.normal));

verifyCommand.SetAction(NuGetCommand.Run);

Expand Down Expand Up @@ -184,13 +184,13 @@ private static Command GetTrustCommand()
// as well as the standard NugetCommand.Run handler

trustCommand.Options.Add(configFile);
trustCommand.Options.Add(CommonOptions.VerbosityOption(Utils.VerbosityOptions.normal));
trustCommand.Options.Add(CommonOptions.VerbosityOption(Utils.Verbosity.normal));
trustCommand.SetAction(NuGetCommand.Run);

foreach (var command in trustCommand.Subcommands)
{
command.Options.Add(configFile);
command.Options.Add(CommonOptions.VerbosityOption(Utils.VerbosityOptions.normal));
command.Options.Add(CommonOptions.VerbosityOption(Utils.Verbosity.normal));
command.SetAction(NuGetCommand.Run);
}

Expand Down Expand Up @@ -261,7 +261,7 @@ private static Command GetSignCommand()
{
Arity = ArgumentArity.Zero
});
signCommand.Options.Add(CommonOptions.VerbosityOption(Utils.VerbosityOptions.normal));
signCommand.Options.Add(CommonOptions.VerbosityOption(Utils.Verbosity.normal));

signCommand.SetAction(NuGetCommand.Run);

Expand Down
10 changes: 5 additions & 5 deletions src/Cli/dotnet/Commands/Pack/PackCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ public static CommandBase FromParseResult(ParseResult parseResult, string? msbui
});
}

private static LogLevel MappingVerbosityToNugetLogLevel(VerbosityOptions? verbosity)
private static LogLevel MappingVerbosityToNugetLogLevel(Verbosity? verbosity)
{
return verbosity switch
{
VerbosityOptions.diagnostic or VerbosityOptions.diag => LogLevel.Debug,
VerbosityOptions.minimal or VerbosityOptions.m => LogLevel.Minimal,
VerbosityOptions.normal or VerbosityOptions.n => LogLevel.Information,
VerbosityOptions.detailed or VerbosityOptions.d => LogLevel.Verbose,
Verbosity.diagnostic => LogLevel.Debug,
Verbosity.minimal => LogLevel.Minimal,
Verbosity.normal => LogLevel.Information,
Verbosity.detailed => LogLevel.Verbose,
_ => LogLevel.Minimal
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Commands/Pack/PackCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ internal static class PackCommandParser
public static readonly Option<string?> ConfigurationOption = CommonOptions.ConfigurationOption(CliCommandStrings.PackConfigurationOptionDescription);

public static readonly Option<string[]> TargetOption = CommonOptions.RequiredMSBuildTargetOption("Pack", [("_IsPacking", "true")]);
public static readonly Option<Utils.VerbosityOptions?> VerbosityOption = BuildCommandParser.VerbosityOption;
public static readonly Option<Utils.Verbosity?> VerbosityOption = BuildCommandParser.VerbosityOption;

public static Option<NuGetVersion> VersionOption =
new Option<NuGetVersion>("--version")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ internal static class PackageListCommandParser
Arity = ArgumentArity.Zero
};

public static readonly Option VerbosityOption = new Option<Utils.VerbosityOptions>("--verbosity", "-v")
{
Description = CliStrings.VerbosityOptionDescription,
HelpName = CliStrings.LevelArgumentName
}.ForwardAsSingle(o => $"--verbosity:{o}");
public static readonly Option<Utils.Verbosity?> VerbosityOption = CommonOptions.VerbosityOption();

public static readonly Option FormatOption = new Option<ReportOutputFormat>("--format")
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Commands/Publish/PublishCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal static class PublishCommandParser
public static readonly Option<string?> ConfigurationOption = CommonOptions.ConfigurationOption(CliCommandStrings.PublishConfigurationOptionDescription);
public static readonly Option<string[]> TargetOption = CommonOptions.RequiredMSBuildTargetOption("Publish", [("_IsPublishing", "true")]);

public static readonly Option<Utils.VerbosityOptions?> VerbosityOption = BuildCommandParser.VerbosityOption;
public static readonly Option<Utils.Verbosity?> VerbosityOption = BuildCommandParser.VerbosityOption;

private static readonly Command Command = ConstructCommand();

Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Commands/Restore/RestoreCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal static class RestoreCommandParser
.AllowSingleArgPerToken();

public static readonly Option<string[]> TargetOption = CommonOptions.RequiredMSBuildTargetOption("Restore");
public static readonly Option<Utils.VerbosityOptions> VerbosityOption = CommonOptions.VerbosityOption(Utils.VerbosityOptions.minimal);
public static readonly Option<Utils.Verbosity> VerbosityOption = CommonOptions.VerbosityOption(Utils.Verbosity.minimal);
public static readonly Option<bool> NoLogoOption = CommonOptions.NoLogoOption();

private static IEnumerable<Option> FullRestoreOptions() => [
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Commands/Run/Api/RunApiCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public sealed class GetRunCommand : RunApiInput

public override RunApiOutput Execute()
{
var msbuildArgs = MSBuildArgs.FromVerbosity(VerbosityOptions.quiet);
var msbuildArgs = MSBuildArgs.FromVerbosity(Verbosity.quiet);
var buildCommand = new VirtualProjectBuildingCommand(
entryPointFileFullPath: EntryPointFileFullPath,
msbuildArgs: msbuildArgs)
Expand Down
8 changes: 4 additions & 4 deletions src/Cli/dotnet/Commands/Run/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class RunCommand
/// The verbosity of the run-portion of this command specifically. If implicit builds are performed, they will always happen
/// at a quiet verbosity by default, but it's important that we enable separate verbosity for the run command itself.
/// </summary>
public VerbosityOptions RunCommandVerbosity { get; private set; }
public Verbosity RunCommandVerbosity { get; private set; }

/// <summary>
/// True to ignore command line arguments specified by launch profile.
Expand Down Expand Up @@ -367,7 +367,7 @@ private MSBuildArgs SetupSilentBuildArgs(MSBuildArgs msbuildArgs)
{
msbuildArgs = msbuildArgs.CloneWithNoLogo(true);

if (msbuildArgs.Verbosity is VerbosityOptions userVerbosity)
if (msbuildArgs.Verbosity is Verbosity userVerbosity)
{
// if the user had a desired verbosity, we use that for the run command
RunCommandVerbosity = userVerbosity;
Expand All @@ -378,8 +378,8 @@ private MSBuildArgs SetupSilentBuildArgs(MSBuildArgs msbuildArgs)
// Apply defaults if the user didn't expressly set the verbosity.
// Setting RunCommandVerbosity to minimal ensures that we keep the previous launchsettings
// and related diagnostics messages on by default.
RunCommandVerbosity = VerbosityOptions.minimal;
return msbuildArgs.CloneWithVerbosity(VerbosityOptions.quiet);
RunCommandVerbosity = Verbosity.minimal;
return msbuildArgs.CloneWithVerbosity(Verbosity.quiet);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Commands/Run/RunCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ internal static class RunCommandParser

public static readonly Option NoSelfContainedOption = CommonOptions.NoSelfContainedOption;

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

public static readonly Argument<string[]> ApplicationArguments = new("applicationArguments")
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Commands/Test/MTP/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal record BuildOptions(
PathOptions PathOptions,
bool HasNoRestore,
bool HasNoBuild,
Utils.VerbosityOptions? Verbosity,
Utils.Verbosity? Verbosity,
bool NoLaunchProfile,
bool NoLaunchProfileArguments,
List<string> UnmatchedTokens,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ static RunProperties GetRunProperties(ProjectInstance project)
}

// If buildOptions.Verbosity is null, we still want to print the message.
if (buildOptions.Verbosity != VerbosityOptions.quiet)
if (buildOptions.Verbosity != Verbosity.quiet)
{
Reporter.Output.WriteLine(string.Format(CliCommandStrings.UsingLaunchSettingsFromMessage, launchSettingsPath));
}
Expand Down
Loading
Loading