Skip to content

CLI: Add global options and environment variable support#40789

Open
dkbennett wants to merge 8 commits into
masterfrom
user/dkbennett/goptions
Open

CLI: Add global options and environment variable support#40789
dkbennett wants to merge 8 commits into
masterfrom
user/dkbennett/goptions

Conversation

@dkbennett

@dkbennett dkbennett commented Jun 12, 2026

Copy link
Copy Markdown
Member

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:

  • Moving session to global options - this is a significant alteration that will be a separate PR, this one paves the way.
  • Help display of available global options and environment variables - this will be included in the larger help polish.
  • Debug actually doing anything - this will come in with the Reporter (or shortly after)

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

See Copilot's first comment.

Validation Steps Performed

  • Unit tests pass
  • Manual verification of the command line looks correct

Copilot AI review requested due to automatic review settings June 12, 2026 10:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 CoreMain and in execution tests, using optionsOnly + stopOnUnknown so subcommand resolution and command-specific parsing remain authoritative.
  • Introduce EnvironmentOptions to map selected environment variables (e.g. WSLC_CLI_DEBUG, NO_COLOR) to ArgTypes and apply them early to context.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.

Comment thread src/windows/wslc/core/EnvironmentOptions.cpp Outdated
Comment thread src/windows/wslc/core/EnvironmentOptions.cpp Outdated
Comment thread src/windows/wslc/core/Main.cpp Outdated
Comment thread src/windows/wslc/core/Main.cpp
@dkbennett dkbennett marked this pull request as ready for review June 12, 2026 21:09
@dkbennett dkbennett requested a review from a team as a code owner June 12, 2026 21:09
Copilot AI review requested due to automatic review settings June 12, 2026 21:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.

Comment thread src/windows/wslc/core/EnvironmentOptions.cpp Outdated
AmelBawa-msft
AmelBawa-msft previously approved these changes Jun 12, 2026
Comment thread src/windows/wslc/core/EnvironmentOptions.cpp Outdated
Comment thread src/windows/wslc/core/EnvironmentOptions.h Outdated
AmelBawa-msft
AmelBawa-msft previously approved these changes Jun 12, 2026

@OneBlue OneBlue left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Comment thread src/windows/wslc/core/EnvironmentOptions.cpp
Comment thread src/windows/wslc/core/EnvironmentOptions.h Outdated
Copilot AI review requested due to automatic review settings June 13, 2026 02:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.

Comment thread src/windows/wslc/arguments/ArgumentParser.cpp
Comment thread src/windows/wslc/core/EnvironmentOptions.h
Comment thread test/windows/wslc/WSLCCLIEnvironmentOptionsUnitTests.cpp Outdated
Comment thread src/windows/wslc/core/Main.cpp Outdated
Copilot AI review requested due to automatic review settings June 13, 2026 04:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.

Comment thread test/windows/wslc/WSLCCLIEnvironmentOptionsUnitTests.cpp Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants