Skip to content

Reject flag-like values for option arguments (#103) - #342

Merged
melvincarvalho merged 4 commits into
gh-pagesfrom
issue-103-flag-like-values
May 1, 2026
Merged

Reject flag-like values for option arguments (#103)#342
melvincarvalho merged 4 commits into
gh-pagesfrom
issue-103-flag-like-values

Conversation

@melvincarvalho

Copy link
Copy Markdown
Contributor

Summary

jss start --single-user-name --idp had Commander silently consume --idp as the username. The IdP flag was lost, /.well-known/openid-configuration returned 404, and the error surface was a confusing "issuer has no registration endpoint" plus a banner line Single-user: --idp (registration disabled).

This PR adds a single program.hook('preAction', …) validator in bin/jss.js that runs before every subcommand action and:

  • String options: errors with a clear value "--foo" looks like a flag, not a value message when the value starts with --.
  • Numeric options: errors with got a non-numeric value (parsed as NaN) when the value coercer (e.g. parseInt for --port) was fed a flag.
  • Both messages include a Hint: line with the canonical kebab-case flag name and an example value.

Test plan

  • New test/cli-flag-like-values.test.js spawns the bin via child_process.spawnSync and asserts:
    • --single-user-name --idp exits non-zero with the right error and hint.
    • --idp-issuer --unknown-flag exits non-zero with the analogous message.
    • --port --idp exits non-zero with the NaN-flavoured error.
    • A clean run with --print-config exits 0 (no false positives on legitimate values).
  • Live smoke matches:
    $ jss start --single-user-name --idp
    Error: --single-user-name value "--idp" looks like a flag, not a value.
    Hint: did you forget to provide a value? e.g. --single-user-name someValue
    
  • Full suite green: 537/537 (4 new tests).

Fixes #103.

`jss start --single-user-name --idp` previously had Commander silently
consume `--idp` as the username, which left --idp unset, broke the IdP
config (no /.well-known/openid-configuration), and surfaced as a
confusing downstream error: "issuer has no registration endpoint" —
plus a banner line of "Single-user: --idp (registration disabled)".

Adds a `program.hook('preAction', ...)` validator that runs before
every subcommand action and:

- Errors with a clear "looks like a flag, not a value" message for
  any string option whose value starts with `--`.
- Errors with "got a non-numeric value (parsed as NaN)" for numeric
  options like `--port` whose value-coercer was fed a flag.

Both messages include a "Hint:" line with the canonical kebab-case
form of the flag and an example value.

New `test/cli-flag-like-values.test.js` spawns the bin and asserts
the four cases: string-option flag value, unknown-follow-up flag,
numeric-option flag value, and a clean run that proves no
false-positive on legitimate values.

Full suite: 537/537.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a CLI guard to prevent Commander from treating the next flag token as an option value (e.g. --single-user-name --idp), improving error clarity and preventing downstream misconfiguration (notably IdP setup).

Changes:

  • Add a program.hook('preAction', …) validator to reject string option values that start with -- and numeric options parsed as NaN.
  • Add regression tests that spawn bin/jss.js and assert non-zero exits + helpful stderr messages for flag-like values.

Reviewed changes

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

File Description
bin/jss.js Adds a preAction hook to detect and error on flag-like option values / NaN numeric coercions before executing subcommand actions.
test/cli-flag-like-values.test.js Adds CLI-level regression coverage for the flag-swallowing behavior and verifies no false positives on a valid --print-config run.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +50 to +53
const r = runCli(['start',
'--port', '4582',
'--root', '/tmp/jss-103-sanity-doesnotneedtoexist',
'--single-user-name', 'alice',

Copilot AI left a comment

Copy link
Copy Markdown

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 1 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/cli-flag-like-values.test.js Outdated
Comment on lines +33 to +38
// value, which is the whole reason the bug exists. We use a flag
// commander doesn't know about ("--unknown-flag") so commander
// doesn't reroute it through its own argument-count error.
const r = runCli(['start', '--idp-issuer', '--unknown-flag']);
assert.notStrictEqual(r.status, 0);
assert.match(r.stderr, /--idp-issuer value "--unknown-flag" looks like a flag/);

Copilot AI left a comment

Copy link
Copy Markdown

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 1 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/cli-flag-like-values.test.js Outdated
Comment on lines +18 to +20

function runCli(args) {
return spawnSync(process.execPath, [BIN, ...args], { encoding: 'utf8' });

Copilot AI left a comment

Copy link
Copy Markdown

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 1 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@melvincarvalho
melvincarvalho merged commit f2b9987 into gh-pages May 1, 2026
4 checks passed
@melvincarvalho
melvincarvalho deleted the issue-103-flag-like-values branch May 1, 2026 23:14
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.

CLI accepts flag-like values for --single-user-name without warning

2 participants