Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: onFinishCommand handler #1473

Merged
merged 4 commits into from Dec 3, 2019

Conversation

petrgrishin
Copy link
Contributor

Example usage:
image

@petrgrishin petrgrishin force-pushed the feat/on-finish-command branch 2 times, most recently from 03e2507 to b449cd1 Compare November 7, 2019 21:29
test/yargs.js Outdated Show resolved Hide resolved
@mleguen
Copy link
Member

mleguen commented Nov 8, 2019

@bcoe Perhaps redundant with #1452?

Or perhaps not if #1452 only lands in yargsa...

Not incompatible, anyway.

Copy link
Member

@mleguen mleguen left a comment

Choose a reason for hiding this comment

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

Thanks for this PR. Would you mind checking/fixing the few points @Goodluckhf and I mentioned?

docs/advanced.md Show resolved Hide resolved
test/yargs.js Show resolved Hide resolved
yargs.js Outdated Show resolved Hide resolved
@bcoe
Copy link
Member

bcoe commented Nov 10, 2019

rather than adding additional functionality to yargs for handling async behavior, I'd rather see us combine efforts here and figure out what an async-first version of yargs might look like.

@bcoe
Copy link
Member

bcoe commented Nov 12, 2019

@mleguen @petrgrishin if there was a stop gap between a fully async version of yargs, and something better than what we have today, I'd be open to this too; but would love for folks to collaborate and figure out what those two versions of the library are.

@mleguen
Copy link
Member

mleguen commented Nov 13, 2019

@bcoe @petrgrishin Sure, this was the idea behind my comments on this issue.

I feel however that yargsa and this issue are complementary:

  • yargs focuses on async API (ie medling with promises)
  • this issue could bring the "tell application the command handler is done" feature for sync applications

I would then recommend sticking here to a standard sync API, ie:

  • adding an optional done argument to the command handler
  • calling onFinishCommand when done is called (if the handler uses it) or when the handler returns (if not using it)

And applications using promise-returning command handler should be encouraged to use yargsa.

What would you think of this?

@bcoe
Copy link
Member

bcoe commented Nov 16, 2019

@mleguen your suggestion of using this work as an intermediate step towards a fully async API seems reasonable to me (my wish would be for us to get down to a healthier number of open issues on the existing yargs API, before we made the sweeping change proposed in yargsa).

@petrgrishin would you be open to addressing some of the code review brought up here?

@petrgrishin petrgrishin force-pushed the feat/on-finish-command branch 4 times, most recently from 19cd8d6 to f1d41ef Compare November 20, 2019 17:37
Copy link
Member

@mleguen mleguen left a comment

Choose a reason for hiding this comment

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

@petrgrishin Thanks!

@petrgrishin petrgrishin changed the title PoC: onFinishCommand handler feat: onFinishCommand handler Nov 28, 2019
Copy link

@Goodluckhf Goodluckhf left a comment

Choose a reason for hiding this comment

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

LGTM

@mleguen mleguen merged commit fe380cd into yargs:master Dec 3, 2019
@dapplion
Copy link
Contributor

dapplion commented Dec 3, 2019

Great feature! When will a version with this feature be released?

Copy link
Contributor

@dapplion dapplion left a comment

Choose a reason for hiding this comment

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

@petrgrishin Small typo in the docs

### Example
```
yargs
.comand('cmd', ..., async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo, should be command not comand

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @dapplion. Mind doing a small PR to fix this typo?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @dapplion. Mind doing a small PR to fix this typo?

Sure @mleguen: #1506

@bcoe
Copy link
Member

bcoe commented Jan 2, 2020

@petrgrishin this is released now, take it for a spin and make sure it's working for you?

One thought for the future, should we potentially make onFinishCommand cause yargs to return a Promise, so that you could await a command finishing? might be a potential API improvement in the future?

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.

None yet

5 participants