Skip to content

Commit

Permalink
System.CommandLine update (#76948)
Browse files Browse the repository at this point in the history
This PR consists of #76851 (the maestro PR) and actual changes required
to update S.CL.
  • Loading branch information
JoeRobich authored Jan 28, 2025
2 parents d275717 + 55a896d commit 1b6cd2a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 44 deletions.
8 changes: 4 additions & 4 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
<Sha>be366997dfae0aa6e3c9a78bad10bfb3f79cbde1</Sha>
<SourceBuild RepoName="source-build-reference-packages" ManagedOnly="true" />
</Dependency>
<Dependency Name="System.CommandLine" Version="2.0.0-beta4.24528.1">
<Dependency Name="System.CommandLine" Version="2.0.0-beta4.25072.1">
<Uri>https://github.com/dotnet/command-line-api</Uri>
<Sha>feb61c7f328a2401d74f4317b39d02126cfdfe24</Sha>
<Sha>060374e56c1b2e741b6525ca8417006efb54fbd7</Sha>
</Dependency>
<!-- Intermediate is necessary for source build. -->
<Dependency Name="Microsoft.SourceBuild.Intermediate.command-line-api" Version="0.1.552801">
<Dependency Name="Microsoft.SourceBuild.Intermediate.command-line-api" Version="0.1.607201">
<Uri>https://github.com/dotnet/command-line-api</Uri>
<Sha>feb61c7f328a2401d74f4317b39d02126cfdfe24</Sha>
<Sha>060374e56c1b2e741b6525ca8417006efb54fbd7</Sha>
<SourceBuild RepoName="command-line-api" ManagedOnly="true" />
</Dependency>
<!-- Necessary for source-build. This allows the live version of the package to be used by source-build. -->
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
Versions managed by Arcade (see Versions.Details.xml)
-->
<PropertyGroup>
<SystemCommandLineVersion>2.0.0-beta4.24528.1</SystemCommandLineVersion>
<SystemCommandLineVersion>2.0.0-beta4.25072.1</SystemCommandLineVersion>
<SystemCompositionVersion>8.0.0</SystemCompositionVersion>
<SystemConfigurationConfigurationManagerVersion>8.0.0</SystemConfigurationConfigurationManagerVersion>
<SystemDiagnosticsEventLogVersion>8.0.0</SystemDiagnosticsEventLogVersion>
Expand Down
16 changes: 8 additions & 8 deletions src/Features/Lsif/Generator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ internal static class Program
{
public static Task Main(string[] args)
{
var solution = new CliOption<FileInfo>("--solution") { Description = "input solution file" }.AcceptExistingOnly();
var project = new CliOption<FileInfo>("--project") { Description = "input project file" }.AcceptExistingOnly();
var compilerInvocation = new CliOption<FileInfo>("--compiler-invocation") { Description = "path to a .json file that contains the information for a csc/vbc invocation" }.AcceptExistingOnly();
var binLog = new CliOption<FileInfo>("--binlog") { Description = "path to a MSBuild binlog that csc/vbc invocations will be extracted from" }.AcceptExistingOnly();
var output = new CliOption<string?>("--output") { Description = "file to write the LSIF output to, instead of the console", DefaultValueFactory = _ => null };
var solution = new Option<FileInfo>("--solution") { Description = "input solution file" }.AcceptExistingOnly();
var project = new Option<FileInfo>("--project") { Description = "input project file" }.AcceptExistingOnly();
var compilerInvocation = new Option<FileInfo>("--compiler-invocation") { Description = "path to a .json file that contains the information for a csc/vbc invocation" }.AcceptExistingOnly();
var binLog = new Option<FileInfo>("--binlog") { Description = "path to a MSBuild binlog that csc/vbc invocations will be extracted from" }.AcceptExistingOnly();
var output = new Option<string?>("--output") { Description = "file to write the LSIF output to, instead of the console", DefaultValueFactory = _ => null };
output.AcceptLegalFilePathsOnly();
var outputFormat = new CliOption<LsifFormat>("--output-format") { Description = "format of LSIF output", DefaultValueFactory = _ => LsifFormat.Line };
var log = new CliOption<string?>("--log") { Description = "file to write a log to", DefaultValueFactory = _ => null };
var outputFormat = new Option<LsifFormat>("--output-format") { Description = "format of LSIF output", DefaultValueFactory = _ => LsifFormat.Line };
var log = new Option<string?>("--log") { Description = "file to write a log to", DefaultValueFactory = _ => null };
log.AcceptLegalFilePathsOnly();

var generateCommand = new CliRootCommand("generates an LSIF file")
var generateCommand = new RootCommand("generates an LSIF file")
{
solution,
project,
Expand Down
33 changes: 16 additions & 17 deletions src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using Microsoft.CodeAnalysis.LanguageServer.Logging;
using Microsoft.CodeAnalysis.LanguageServer.Services;
using Microsoft.CodeAnalysis.LanguageServer.StarredSuggestions;
using Microsoft.CodeAnalysis.Options;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;
using Roslyn.Utilities;
Expand Down Expand Up @@ -103,7 +102,7 @@ static async Task RunAsync(ServerConfiguration serverConfiguration, Cancellation

// LSP server doesn't have the pieces yet to support 'balanced' mode for source-generators. Hardcode us to
// 'automatic' for now.
var globalOptionService = exportProvider.GetExportedValue<IGlobalOptionService>();
var globalOptionService = exportProvider.GetExportedValue<Microsoft.CodeAnalysis.Options.IGlobalOptionService>();
globalOptionService.SetGlobalOption(WorkspaceConfigurationOptionsStorage.SourceGeneratorExecution, SourceGeneratorExecutionPreference.Automatic);

// The log file directory passed to us by VSCode might not exist yet, though its parent directory is guaranteed to exist.
Expand Down Expand Up @@ -181,87 +180,87 @@ static async Task RunAsync(ServerConfiguration serverConfiguration, Cancellation
}
}

static CliRootCommand CreateCommandLineParser()
static RootCommand CreateCommandLineParser()
{
var debugOption = new CliOption<bool>("--debug")
var debugOption = new Option<bool>("--debug")
{
Description = "Flag indicating if the debugger should be launched on startup.",
Required = false,
DefaultValueFactory = _ => false,
};
var brokeredServicePipeNameOption = new CliOption<string?>("--brokeredServicePipeName")
var brokeredServicePipeNameOption = new Option<string?>("--brokeredServicePipeName")
{
Description = "The name of the pipe used to connect to a remote process (if one exists).",
Required = false,
};

var logLevelOption = new CliOption<LogLevel>("--logLevel")
var logLevelOption = new Option<LogLevel>("--logLevel")
{
Description = "The minimum log verbosity.",
Required = true,
};
var starredCompletionsPathOption = new CliOption<string?>("--starredCompletionComponentPath")
var starredCompletionsPathOption = new Option<string?>("--starredCompletionComponentPath")
{
Description = "The location of the starred completion component (if one exists).",
Required = false,
};

var telemetryLevelOption = new CliOption<string?>("--telemetryLevel")
var telemetryLevelOption = new Option<string?>("--telemetryLevel")
{
Description = "Telemetry level, Defaults to 'off'. Example values: 'all', 'crash', 'error', or 'off'.",
Required = false,
};
var extensionLogDirectoryOption = new CliOption<string>("--extensionLogDirectory")
var extensionLogDirectoryOption = new Option<string>("--extensionLogDirectory")
{
Description = "The directory where we should write log files to",
Required = true,
};

var sessionIdOption = new CliOption<string?>("--sessionId")
var sessionIdOption = new Option<string?>("--sessionId")
{
Description = "Session Id to use for telemetry",
Required = false
};

var extensionAssemblyPathsOption = new CliOption<string[]?>("--extension")
var extensionAssemblyPathsOption = new Option<string[]?>("--extension")
{
Description = "Full paths of extension assemblies to load (optional).",
Required = false
};

var devKitDependencyPathOption = new CliOption<string?>("--devKitDependencyPath")
var devKitDependencyPathOption = new Option<string?>("--devKitDependencyPath")
{
Description = "Full path to the Roslyn dependency used with DevKit (optional).",
Required = false
};

var razorSourceGeneratorOption = new CliOption<string?>("--razorSourceGenerator")
var razorSourceGeneratorOption = new Option<string?>("--razorSourceGenerator")
{
Description = "Full path to the Razor source generator (optional).",
Required = false
};

var razorDesignTimePathOption = new CliOption<string?>("--razorDesignTimePath")
var razorDesignTimePathOption = new Option<string?>("--razorDesignTimePath")
{
Description = "Full path to the Razor design time target path (optional).",
Required = false
};

var serverPipeNameOption = new CliOption<string?>("--pipe")
var serverPipeNameOption = new Option<string?>("--pipe")
{
Description = "The name of the pipe the server will connect to.",
Required = false
};

var useStdIoOption = new CliOption<bool>("--stdio")
var useStdIoOption = new Option<bool>("--stdio")
{
Description = "Use stdio for communication with the client.",
Required = false,
DefaultValueFactory = _ => false,

};

var rootCommand = new CliRootCommand()
var rootCommand = new RootCommand()
{
debugOption,
brokeredServicePipeNameOption,
Expand Down
18 changes: 9 additions & 9 deletions src/Tools/BuildValidator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,45 +31,45 @@ static int Main(string[] args)
{
System.Diagnostics.Trace.Listeners.Clear();

var assembliesPath = new CliOption<string[]>("--assembliesPath")
var assembliesPath = new Option<string[]>("--assembliesPath")
{
Description = BuildValidatorResources.Path_to_assemblies_to_rebuild_can_be_specified_one_or_more_times,
Required = true,
Arity = ArgumentArity.OneOrMore,
};
var exclude = new CliOption<string[]>("--exclude")
var exclude = new Option<string[]>("--exclude")
{
Description = BuildValidatorResources.Assemblies_to_be_excluded_substring_match,
Arity = ArgumentArity.ZeroOrMore,
};
var source = new CliOption<string>("--sourcePath")
var source = new Option<string>("--sourcePath")
{
Description = BuildValidatorResources.Path_to_sources_to_use_in_rebuild,
Required = true,
};
var referencesPath = new CliOption<string[]>("--referencesPath")
var referencesPath = new Option<string[]>("--referencesPath")
{
Description = BuildValidatorResources.Path_to_referenced_assemblies_can_be_specified_zero_or_more_times,
Arity = ArgumentArity.ZeroOrMore,
};
var verbose = new CliOption<bool>("--verbose")
var verbose = new Option<bool>("--verbose")
{
Description = BuildValidatorResources.Output_verbose_log_information
};
var quiet = new CliOption<bool>("--quiet")
var quiet = new Option<bool>("--quiet")
{
Description = BuildValidatorResources.Do_not_output_log_information_to_console
};
var debug = new CliOption<bool>("--debug")
var debug = new Option<bool>("--debug")
{
Description = BuildValidatorResources.Output_debug_info_when_rebuild_is_not_equal_to_the_original
};
var debugPath = new CliOption<string?>("--debugPath")
var debugPath = new Option<string?>("--debugPath")
{
Description = BuildValidatorResources.Path_to_output_debug_info
};

var rootCommand = new CliRootCommand
var rootCommand = new RootCommand
{
assembliesPath,
exclude,
Expand Down
10 changes: 5 additions & 5 deletions src/Workspaces/MSBuild/BuildHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ internal static class Program
{
internal static async Task Main(string[] args)
{
var pipeOption = new CliOption<string>("--pipe") { Required = true };
var propertyOption = new CliOption<string[]>("--property") { Arity = ArgumentArity.ZeroOrMore };
var binaryLogOption = new CliOption<string?>("--binlog") { Required = false };
var localeOption = new CliOption<string>("--locale") { Required = true };
var command = new CliRootCommand { pipeOption, binaryLogOption, propertyOption, localeOption };
var pipeOption = new Option<string>("--pipe") { Required = true };
var propertyOption = new Option<string[]>("--property") { Arity = ArgumentArity.ZeroOrMore };
var binaryLogOption = new Option<string?>("--binlog") { Required = false };
var localeOption = new Option<string>("--locale") { Required = true };
var command = new RootCommand { pipeOption, binaryLogOption, propertyOption, localeOption };
var parsedArguments = command.Parse(args);
var pipeName = parsedArguments.GetValue(pipeOption)!;
var properties = parsedArguments.GetValue(propertyOption)!;
Expand Down

0 comments on commit 1b6cd2a

Please sign in to comment.