fix: report usage error for unknown CLI flags instead of opening the GUI#1163
Merged
Conversation
Running SysManager.exe with an unrecognized --flag (e.g. --bogus) fell through to launching the GUI and exited 0, contradicting the documented contract (the --help text and the runtime test kit both expect unknown options to exit 2). IsCliInvocation only matched a known-verb allowlist, so a typo'd flag wasn't treated as CLI input at all. It now also matches any unrecognized option flag — EXCEPT the internal startup sentinels (--relaunched-elevated, --apply-update), which must keep routing to their own OnStartup branches. The existing Parse/ Execute path already maps unknown flags to a usage error (exit 2 + help); it just never got reached. Bare non-flag tokens still don't trigger CLI mode. Found by running the dev-config runtime test kit (cli-smoke.ps1) on the secondary workstation; verified live that --bogus now prints 'Unknown option' and exits 2 while --relaunched-elevated still opens the elevated GUI. Adds regression tests: IsCliInvocation true for an unknown flag, false for bare tokens (the elevation/updater-sentinel exclusions were already covered).
Comment on lines
+53
to
+57
| foreach (var raw in args) | ||
| { | ||
| var a = raw.Trim(); | ||
| if (NonCliSentinels.Contains(a)) return false; | ||
| } |
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.
Bug
SysManager.exe --bogus(or any unrecognized--flag) fell through to launching the GUI and exiting 0, contradicting the documented contract — the app's own--helpsays "Exit codes: 0 success · 1 error · 2 usage error", and TC-4 / cli-smoke.ps1 both expect unknown flags to exit 2.Root cause
CliRunner.IsCliInvocationmatched only a known-verb allowlist, so a typo'd flag wasn't recognized as CLI input and startup proceeded to the GUI. TheParse/ExecuteAsyncpath already maps unknown flags toCliCommand.Unknown→ usage error (exit 2 + help) — it just never got reached.Fix
IsCliInvocationnow also returns true for any unrecognized option flag (leading-//), except the internal startup sentinels--relaunched-elevatedand--apply-update, which must keep routing to their ownOnStartupbranches (elevation relaunch / in-process updater). Bare non-flag tokens still never trigger CLI mode.Verification
cli-smoke.ps1) on the secondary workstation — it hung on the--boguscase.--bogus/--nope→ "Unknown option '…'" + help, exit 2;--version→ exit 0;--relaunched-elevated→ elevated GUI opens and stays alive (NOT treated as CLI).cli-smoke.ps1: 17/17 PASS (incl. mutating--cleanup/--trim-ram).IsCliInvocationtrue for an unknown flag, false for bare tokens (sentinel exclusions already covered).Patch bump 1.51.7 + CHANGELOG entry.