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

Document Command class in readme #790

Closed
nicojs opened this issue Apr 18, 2018 · 4 comments
Closed

Document Command class in readme #790

nicojs opened this issue Apr 18, 2018 · 4 comments
Labels
docs README (or other docs) could be improved

Comments

@nicojs
Copy link

nicojs commented Apr 18, 2018

I've noticed that by using the documented const program = require('command') syntax you're actually polluting a global Command object. This can be shared by other components resulting in weird issues (like nicojs/node-link-parent-bin#4 (comment))

After inspecting the source code, i see that a Command class is exported! Kudo's to you sir! I'll use this from now on. It also helps quite a bit with testability (injecting a mock object for Command at test time). Let's promote this way of working a bit by documenting it in the readme

My idea is to update the readme and use const Command = require('commander').Command; const program = new Command(); everywhere. I would like to place a remark to let people know that they could also use const program = require('commander'); but that it is not preferred and explain why it is not.

If you agree, I'm willing to create the PR.

I would personally like it if the const program = require('commander');-way-of-working would become deprecated and removed in a major release. What are your thoughts on that?

@shadowspawn
Copy link
Collaborator

We do need to get something into the README about the "new" pattern, thanks for raising.

I don't think we will deprecate the old way as such, but it should be the my-program-is-so-simple-globals-are-ok way of working.

@shadowspawn
Copy link
Collaborator

I have added the new pattern in a large update to README in #953

@nicojs
Copy link
Author

nicojs commented May 2, 2019

Awesome! LGTM

@shadowspawn
Copy link
Collaborator

Updated README with section right at start showing use of Command class
https://github.com/tj/commander.js#declaring-program-variable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs README (or other docs) could be improved
Projects
None yet
Development

No branches or pull requests

2 participants