Skip to content

fix: report usage error for unknown CLI flags instead of opening the GUI#1163

Merged
laurentiu021 merged 1 commit into
mainfrom
fix/cli-unknown-flag-usage-error
Jun 29, 2026
Merged

fix: report usage error for unknown CLI flags instead of opening the GUI#1163
laurentiu021 merged 1 commit into
mainfrom
fix/cli-unknown-flag-usage-error

Conversation

@laurentiu021

Copy link
Copy Markdown
Owner

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 --help says "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.IsCliInvocation matched only a known-verb allowlist, so a typo'd flag wasn't recognized as CLI input and startup proceeded to the GUI. The Parse/ExecuteAsync path already maps unknown flags to CliCommand.Unknown → usage error (exit 2 + help) — it just never got reached.

Fix

IsCliInvocation now also returns true for any unrecognized option flag (leading -//), except the internal startup sentinels --relaunched-elevated and --apply-update, which must keep routing to their own OnStartup branches (elevation relaunch / in-process updater). Bare non-flag tokens still never trigger CLI mode.

Verification

  • Found by running the runtime test kit (cli-smoke.ps1) on the secondary workstation — it hung on the --bogus case.
  • Verified live after the fix: --bogus/--nope → "Unknown option '…'" + help, exit 2; --version → exit 0; --relaunched-elevated → elevated GUI opens and stays alive (NOT treated as CLI).
  • Full cli-smoke.ps1: 17/17 PASS (incl. mutating --cleanup/--trim-ram).
  • Regression tests added: IsCliInvocation true for an unknown flag, false for bare tokens (sentinel exclusions already covered).

Patch bump 1.51.7 + CHANGELOG entry.

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;
}
@laurentiu021 laurentiu021 merged commit bad4d18 into main Jun 29, 2026
4 checks passed
@laurentiu021 laurentiu021 deleted the fix/cli-unknown-flag-usage-error branch June 29, 2026 18:59
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.

2 participants