Skip to content

pass flags to subcommands - #98

Merged
leo merged 2 commits into
vercel:masterfrom
codyzu:pass-flags-to-subcommands
Nov 26, 2016
Merged

leo merged 2 commits into
vercel:masterfrom
codyzu:pass-flags-to-subcommands

Conversation

@codyzu

@codyzu codyzu commented Oct 27, 2016

Copy link
Copy Markdown
Contributor

Instead of assuming the subcommand is the first argument, this enhancement searches for the first valid subcommand in all of the process arguments. The result being the arguments are more or less "re-ordered" to push all the flags after the subcommand. Processing of the the help command was then refactored to work with the new parsing.

@leo @rauchg this fixes #3. Let me know if there is something I can improve. cheers!

@rauchg

rauchg commented Oct 28, 2016

Copy link
Copy Markdown
Member

This is really really great. Thanks @codyzu

@codyzu

codyzu commented Oct 28, 2016

Copy link
Copy Markdown
Contributor Author

Glad to help!

I could probably add tests for this module by mocking cross-spawn (I'm a fan of simple-mock)... would this be interesting to you guys?

The other bin scripts seem harder to test because the flag validation is mixed in with the business logic, but maybe that could be improved later...

What do you think? @rauchg?

@rauchg

rauchg commented Oct 28, 2016

Copy link
Copy Markdown
Member

@codyzu that actually would be really awesome.

One clever way to avoid mocking could be to test for the --help flag?

now --help alias should equal now alias --help

A simple test for which help is reported (right now it incorrectly shows the now global help) would make this very solid IMHO

Let me know what you think

@codyzu

codyzu commented Oct 28, 2016 •

Copy link
Copy Markdown
Contributor Author

@rauchg ok, this would involve some tests that spawn the now script and capture stdout to verify the correct help message is outputted... that seems possible. I can add that to verify everything works together (more like an integration test).

If you're not opposed, I'll give the mocking a stab (I've done this a lot during my day job) and see if the tests aren't too ugly. That way we can unit test all the flag combinations...

Let me know if that's not direction you want to go.

btw, I tested this pull request manually, so if you're feeling pressed to get the issue resolved and released, you can merge it and I'll create a new one for the tests. Otherwise I'll keep working on this one.

@codyzu

codyzu commented Oct 28, 2016

Copy link
Copy Markdown
Contributor Author

ah yeah, @rauchg, it gets messy with mocks... maybe you saw that coming... trying to spawn a child process with mocks :-( no no... I'll stick with your test idea :-)

@codyzu
codyzu force-pushed the pass-flags-to-subcommands branch from 7844cdd to b3bcbf0 Compare November 1, 2016 20:08
@codyzu
codyzu force-pushed the pass-flags-to-subcommands branch from b3bcbf0 to 8316035 Compare November 1, 2016 20:12
@codyzu

codyzu commented Nov 1, 2016

Copy link
Copy Markdown
Contributor Author

@rauchg I added the tests. I was forced to add compile as a pretest npm script because bin/now.js cannot be executed directly (issue with relative imports in update.js). So, the tests execute with the compiled script.

This is ready to merge.

Let me know what you think.

@codyzu

codyzu commented Nov 26, 2016

Copy link
Copy Markdown
Contributor Author

ping @rauchg @leo

@leo
leo merged commit 50db54f into vercel:master Nov 26, 2016
@leo

leo commented Nov 26, 2016

Copy link
Copy Markdown
Contributor

@codyzu Thanks a lot!

TooTallNate pushed a commit that referenced this pull request Aug 23, 2019
TooTallNate pushed a commit that referenced this pull request Aug 23, 2019
* Implement base generators API

* Status updates

* Update readme and events

* Consistent lint and code cleanup

* Improve error handling
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