Skip to content

wslc cli settings design spec#14367

Draft
yao-msft wants to merge 7 commits intofeature/wsl-for-appsfrom
user/yaosun/settingsdesign
Draft

wslc cli settings design spec#14367
yao-msft wants to merge 7 commits intofeature/wsl-for-appsfrom
user/yaosun/settingsdesign

Conversation

@yao-msft
Copy link

@yao-msft yao-msft commented Mar 6, 2026

For spec comments. Do not merge.


---

## 2. Recommended Format: YAML (JSON as fallback)
Copy link
Member

Choose a reason for hiding this comment

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

Agree with this on all points, very nicely laid out tradeoffs and discussion!


```
wslc settings Open settings file in default editor (or Notepad)
wslc settings --reset Restore settings to built-in defaults (prompts for confirmation)
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer "reset" being a subcommand instead of an option on the settings root command. This seems more consistent with the command pattern established in wslc.

wslc settings --reset Restore settings to built-in defaults (prompts for confirmation)
```

The primary usage (`wslc settings` with no flags) opens the file for editing. This is the most common workflow: a user wants to change something, they open it, edit, save, and the next invocation picks up the change.
Copy link
Member

Choose a reason for hiding this comment

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

This is good and familiar with WinGet and is nice to use. We could also leave the door open for additional setting subcommands like "wslc settings add " and similar delete, and settings list. For users who dont want to jump between console and an editor. For some settings this might be simpler and faster than the editor option and they wouldn't have to know the format.

Not important for p0 of course but those would be nice value-adds later on. This design does not prohibit this so could be incremental if we decide there is value.


Example: if `UserSettings.yaml` contains `memorySizeMb: 8192` and the user runs `wslc session --memory 4096`, the effective memory size is `4096`. If `--memory` is not given, it is `8192`. If the key is not in settings, it falls back to the built-in default.

This means commands must check whether an argument was explicitly provided by the user versus not present at all (not yet set in `ArgMap`), rather than checking for a default value. The existing `ArgMap::Contains()` method already provides this distinction cleanly.
Copy link
Member

Choose a reason for hiding this comment

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

We could also have a nice wrapper here for getting the default value based on ArgType which would follow the settings -> default value to encapsulate all of the settings vs default lookup and handle any errors in the settings by falling back to the default (and printing a warning).

Something different from WinGet is the ArgMap is an enum map like Data. It is also a multmap (different from WinGet), so setting multiple arg values via settings should be possible.

I'm just speculating a moment, but perhaps we can process arguments for a command, and then have a step which checks the settings for default argument values. If there is a default set, we can add the setting to the ArgMap if the argument isn't already there, or if it allows multiple, add new ones if they are different. Then the command execution could be completely agnostic of settings and defaults, it would just process the command as it did before with all of the magic happening in a settings step that is modifying the ArgMap for applicable settings.


### Setting Value Validation

After parsing, each known key is validated against its expected type and allowed values:
Copy link
Member

Choose a reason for hiding this comment

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

We do have some argument validation framework setup already for these things, assuming string input. We should ideally reuse that for settings if possible. I'm not sure how applicable since the arg validation is based on the ArgType enum, but for any settings that are arguments it should work and we would be running the same validation against it if we convert the input to a string. For argument settings this would be effectively free as long as they had an associated argtype for validating.


### Settings Loading

Settings are loaded once at startup in `CoreMain`, before command dispatch, and stored in `CLIExecutionContext`. Settings will be implemented as a singleton and globally read accessible.
Copy link
Member

Choose a reason for hiding this comment

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

Makes sense. If settings are stored as another type of EnumVariantMap we can get additional value from that and store them as a SettingsMap, and Settings off the context with the same access patterns as Args and Data use.


### Settings File Write (for `--reset`)

`--reset` overwrites `UserSettings.yaml` with the commented-out defaults template (the same content generated on first run) after prompting:
Copy link
Member

Choose a reason for hiding this comment

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

As above I would expect this to be a command, and then we could add --force Argument to it to skip the confirmation.


## 8. Out of Scope for Initial Implementation

- **`wslc settings set <key> <value>`** — programmatic key setting without opening an editor. Useful for scripting. Deferred to v2; manual editing covers the primary use case.
Copy link
Member

Choose a reason for hiding this comment

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

I got ahead of myself in earlier comments, but I like this as a future goal.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed, editing configuration files via the command line is tricky, so let's table this for now

- **System-wide settings** — a machine-level settings file (e.g., `%ProgramData%\Microsoft\WSL\wslc\UserSettings.yaml`) that applies to all users. Deferred; per-user is sufficient for v1.
- **Settings profiles** — named profiles for different environments. Deferred.
- **Schema export** — `wslc settings --schema` to print a JSON Schema or TOML template. Useful for editor autocompletion; deferred.
- **Environment variable overrides** — `WSLC_DEFAULTS_FORMAT=json` style overrides. Useful for CI pipelines; deferred.
Copy link
Member

Choose a reason for hiding this comment

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

May want a comment about GroupPolicy here and system administrator enforced settings. Probably out of scope for v1.


```
wslc settings Open settings file in default editor (or Notepad)
wslc settings --reset Restore settings to built-in defaults (prompts for confirmation)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we feel that there's a strong usecase for a --reset here ? This would pretty much be the equivalent of deleting the file, which can already be scripted easily if needed


## 8. Out of Scope for Initial Implementation

- **`wslc settings set <key> <value>`** — programmatic key setting without opening an editor. Useful for scripting. Deferred to v2; manual editing covers the primary use case.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed, editing configuration files via the command line is tricky, so let's table this for now

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.

3 participants