CLI: Add global options and environment variable support#40789
Open
dkbennett wants to merge 8 commits into
Open
CLI: Add global options and environment variable support#40789dkbennett wants to merge 8 commits into
dkbennett wants to merge 8 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request updates the WSLC CLI parsing pipeline to support a root-level “global options” pass (options-only, stop-on-unknown) and adds early configuration via environment variables, with corresponding unit test coverage.
Changes:
- Add a globals-scan parsing pass in
CoreMainand in execution tests, usingoptionsOnly+stopOnUnknownso subcommand resolution and command-specific parsing remain authoritative. - Introduce
EnvironmentOptionsto map selected environment variables (e.g.WSLC_CLI_DEBUG,NO_COLOR) toArgTypes and apply them early tocontext.GlobalArgs. - Extend the argument parser state machine to support “stop cleanly” behaviors and expose the stop position for two-pass parsing; add new/expanded unit tests for these behaviors.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/windows/wslc/WSLCCLIParserUnitTests.cpp | Updates parser test harness for options-only mode and adds targeted tests for stop/position behavior. |
| test/windows/wslc/WSLCCLIExecutionUnitTests.cpp | Mirrors the new three-pass pipeline (globals scan → subcommand resolution → leaf parse/validate). |
| test/windows/wslc/WSLCCLIEnvironmentOptionsUnitTests.cpp | New unit tests covering env-var bindings and precedence rules. |
| test/windows/wslc/WSLCCLICommandUnitTests.cpp | Adds assertions for RootCommand global/env argument exposure and binding completeness. |
| test/windows/wslc/ParserTestCases.h | Adds a Globals argument set and aligns globals definitions with RootCommand. |
| test/windows/wslc/CommandLineTestCases.h | Adds end-to-end command-line cases exercising global options placement/behavior. |
| src/windows/wslc/core/Main.cpp | Implements globals parsing + env application into CLIExecutionContext::GlobalArgs. |
| src/windows/wslc/core/Invocation.h | Adds consumeUntil() to support resuming parsing at an unconsumed token. |
| src/windows/wslc/core/EnvironmentOptions.h / .cpp | New environment-variable binding table and application logic. |
| src/windows/wslc/core/Command.h / Command.cpp | Extends Parse/Validate to accept explicit arg definitions and stop modes; supports partial parses. |
| src/windows/wslc/core/CLIExecutionContext.h / .cpp | Adds GlobalArgs and an ApplyGlobalOptions() hook. |
| src/windows/wslc/commands/RootCommand.h / .cpp | Defines root global options and env-eligible args. |
| src/windows/wslc/arguments/ArgumentParser.h / .cpp | Adds options-only / stop-on-unknown behavior and exposes stop position. |
| src/windows/wslc/arguments/ArgumentDefinitions.h | Adds Debug and NoColor argument definitions. |
| localization/strings/en-US/Resources.resw | Adds descriptions for the new arguments and a cancellation string. |
AmelBawa-msft
previously approved these changes
Jun 12, 2026
AmelBawa-msft
previously approved these changes
Jun 12, 2026
OneBlue
reviewed
Jun 13, 2026
OneBlue
left a comment
Collaborator
There was a problem hiding this comment.
Thank you for doing this !
I think the support "global" argument is going to make our life a lot easier (especially for --session) but I think we can simplify the env variable side. I think we'll realistically never need to look at more than one or two env variables, so we can probably simplify a bit there
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of the Pull Request
This updates the CLI to add support for Global Options, and allowing Environment Variables to be used to set certain Arguments.
The default global options added is just "-D, --debug" which doesn't do anything yet in this code, it just wires it up and tests that at works and is accessible.
The environment variables added are for setting Debug, and NoColor, with the unofficial standard "NO_COLOR" env var support.
The design is such that we reuse the ArgumentDefinitions and for defining global options and environment variable arguments like any other argument. This is intended for just the Root, but it is possible for individual commands to also have environment variables for their options, should the need arise.
Global options can be accessed off the context via "GlobalArgs"
Environment variable-populated args will also be added to GlobalArgs, even if they are not explicitly in the global args (for example, NoColor is not specified on command line and is only set via environment variable, but it is still accessed as if it were a GlobalArg).
Many tests added for the parser changes, new command line parsing, environment variable handling as well as new parser and command line cases.
Intentionally not included:
PR Checklist
Detailed Description of the Pull Request / Additional comments
See Copilot's first comment.
Validation Steps Performed