Skip to content

Apply quality of life improvements to the opennextjs-cloudflare CLI#1097

Merged
dario-piotrowicz merged 9 commits intomainfrom
dario/unknown-command
Feb 10, 2026
Merged

Apply quality of life improvements to the opennextjs-cloudflare CLI#1097
dario-piotrowicz merged 9 commits intomainfrom
dario/unknown-command

Conversation

@dario-piotrowicz
Copy link
Contributor

@dario-piotrowicz dario-piotrowicz commented Jan 26, 2026

This PR improves the opennextjs-cloudflare CLI by:

  • ensuring that unknown commands (e.g., opennextjs-cloudflare foo) display a clear and helpful error message
  • adding a -h|--help flag to display the CLI's help message
  • adding a -v|--version flag to display the package's version

@changeset-bot
Copy link

changeset-bot bot commented Jan 26, 2026

🦋 Changeset detected

Latest commit: f571523

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@opennextjs/cloudflare Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 26, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@opennextjs/cloudflare@1097

commit: f571523

@dario-piotrowicz dario-piotrowicz requested a review from vicb January 27, 2026 11:11
Copy link
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

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

Thanks Dario 🙏
LGTM with one suggestion

@dario-piotrowicz
Copy link
Contributor Author

oof... I guess I need to also instruct yargs to ignore the flags we forward to wrangler 😓
https://github.com/opennextjs/opennextjs-cloudflare/actions/runs/21395938691/job/61594141196?pr=1097#step:6:31

@james-elicx
Copy link
Collaborator

oof... I guess I need to also instruct yargs to ignore the flags we forward to wrangler 😓 opennextjs/opennextjs-cloudflare/actions/runs/21395938691/job/61594141196?pr=1097#step:6:31

I guess that's a result of where .strictCommands() is used perhaps?

@dario-piotrowicz
Copy link
Contributor Author

dario-piotrowicz commented Jan 28, 2026

I guess that's a result of where .strictCommands() is used perhaps?

No, I think that only checks commands and that's not the issue here 🤔

maybe...? but without it passing wrong stuff to the opennext CLI doesn't trigger the error message 😓

@dario-piotrowicz dario-piotrowicz marked this pull request as draft January 28, 2026 11:41
@james-elicx
Copy link
Collaborator

james-elicx commented Jan 28, 2026

Just pushed a change that should get the args working properly.

There's a couple things at play now:

  • we're asking yargs to treat unknown options as args instead of failing, and so yargs was treating them like positionals.
  • there's a syntax for "variadic positional arguments" that we weren't using that would turns the unrecognised flags into args.
  • since we're still stripping out the -- separator, all unrecognised flags that are treated as positionals should now get parsed into an args array.

You can see the args ending up in the expected properties in the below screenshot:

image

@james-elicx
Copy link
Collaborator

james-elicx commented Jan 28, 2026

Hmm I guess I broke something else with the e2es 😅 Should be working now.

@dario-piotrowicz
Copy link
Contributor Author

Thanks for the fix @james-elicx 🙂

With your fix I think that things are a bit un-ideal since any flag passed to a command won't trigger any error/warning, however I don't think we can reasonably do much better given how the CLI accepts arguments

Looks good to me 🙂👍

@dario-piotrowicz dario-piotrowicz marked this pull request as ready for review January 29, 2026 10:16
@dario-piotrowicz dario-piotrowicz requested a review from vicb January 29, 2026 10:16
@vicb
Copy link
Contributor

vicb commented Jan 29, 2026

@dario-piotrowicz

image

I won't at time to look at this before at least tomorrow.
Feel free to merge unless you think I really need to look at this.
Thanks!

@dario-piotrowicz
Copy link
Contributor Author

The current changes look ok... one small thing I noticed is that providing a wrong flag like --test-123 errors saying Unknown command instead of Unknown argument:
Screenshot 2026-02-05 at 10 30 02

I'm not sure why... it's probably not a huge deal, this is definitely more helpful that the current behavior, so I'd say that this is ok and we can possibly improve it as a followup

what do you think @james-elicx?

@james-elicx
Copy link
Collaborator

james-elicx commented Feb 5, 2026

The current changes look ok... one small thing I noticed is that providing a wrong flag like --test-123 errors saying Unknown command instead of Unknown argument: Screenshot 2026-02-05 at 10 30 02

I'm not sure why... it's probably not a huge deal, this is definitely more helpful that the current behavior, so I'd say that this is ok and we can possibly improve it as a followup

what do you think @james-elicx?

It's because unknown-options-as-args treats them as positionals instead of erroring from what i understand.

@dario-piotrowicz dario-piotrowicz linked an issue Feb 10, 2026 that may be closed by this pull request
@dario-piotrowicz dario-piotrowicz merged commit fea645f into main Feb 10, 2026
7 checks passed
@dario-piotrowicz dario-piotrowicz deleted the dario/unknown-command branch February 10, 2026 10:47
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.

Invalid command fails silently

3 participants