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

Add getOptionValueSourceWithGlobals #1832

Merged
merged 1 commit into from Dec 19, 2022

Conversation

shadowspawn
Copy link
Collaborator

@shadowspawn shadowspawn commented Dec 17, 2022

Pull Request

Problem

We added .optWithGlobals() to make working with globals easier. And .getOptionValueSource() for more complex programs. But how do you get the option value source including globals?

See #1713

Solution

Added .getOptionValueSourceWithGlobals().

Sticking with the obvious and long name for what is probably a seldom used routine. Not planning to add to README.

ChangeLog

  • Added: .getOptionValueSourceWithGlobals()


getOptionValueSourceWithGlobals(key) {
// global overwrites local, like optsWithGlobals
let source;
Copy link
Collaborator

Choose a reason for hiding this comment

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

For reference :
You can also write the following using findLast.

    return getCommandAndParents(this)
      .findLast((cmd) => cmd.getOptionValueSource(key) !== undefined)
      .getOptionValueSource(key);

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can use Node.js 18 or later.
My apologies.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I started out planning to target Commander v10.x just so I could use ??, but switched to old-school Node 12 compatible code for now. Eventually!

Copy link
Collaborator

@abetomo abetomo left a comment

Choose a reason for hiding this comment

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

👍

@shadowspawn shadowspawn merged commit 5a201ec into tj:develop Dec 19, 2022
@shadowspawn shadowspawn deleted the feature/combo-with-long-name branch December 19, 2022 06:02
@shadowspawn shadowspawn added the pending release Merged into a branch for a future release, but not released yet label Dec 19, 2022
@shadowspawn shadowspawn removed the pending release Merged into a branch for a future release, but not released yet label Jan 7, 2023
@shadowspawn
Copy link
Collaborator Author

Released with Commander v9.5.0

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