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

WIP: CommandStrict #1404

Closed

Conversation

shadowspawn
Copy link
Collaborator

@shadowspawn shadowspawn commented Nov 29, 2020

Pull Request

Problem

  1. We are slow to adopt new best practices which break backwards compatibility. However, it isn't easy for new programs to start with best practices. Likewise it is not easy to switch existing programs to follow what we consider current best practices as they are now and change in future.

  2. We get weak typings in TypeScript because the Command object may have options stored as properties, meaning TypeScript is not able to warn about typos etc.

The big example of a new best practice is .storeOptionsAsProperties(false).

Solution

Add a CommandStrict class. The implementation sets our best practice configuration. The TypeScript typings do not include options as properties.

const { CommandStrict } = require('commander);
const program = new CommandStrict();

In the future this class might also error if deprecated code is used, but not looking at that now.

Alternatives considered: I did try adding a .strict() method in an earlier attempted solution, but that did not help with the TypeScript typings.

@shadowspawn shadowspawn changed the title CommandStrict WIP: CommandStrict Nov 30, 2020
@cravler
Copy link
Contributor

cravler commented Dec 2, 2020

Better to start using strict mode by default with version 7. Mostly major updates are non-compatible, meaning consumers can not upgrade without changing their software. And just create example for BC.

@shadowspawn
Copy link
Collaborator Author

Hmm, interesting feedback @cravler , thanks! I have been putting off actually changing the defaults. I'll think about that.

@shadowspawn
Copy link
Collaborator Author

On hold, looking at changing default behaviour: #1409

@shadowspawn shadowspawn closed this Dec 3, 2020
@shadowspawn shadowspawn deleted the feature/command-strict branch December 20, 2020 08:53
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

2 participants