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: deprecateOption #1559

Merged
merged 5 commits into from Feb 22, 2020
Merged

Conversation

laggingreflex
Copy link
Contributor

Shows a [deprecated] notice in front of an option

  • Added a method: .deprecateOption(key, [message])
  • Added a key in option conrtructor: .option(key, { deprecated: [boolean|message] })
  • Basic Tests
  • Updated Readme

Work towards #1518

* Added a method: `.deprecateOption(key, [message])`
* Added a key in option conrtructor: `.option(key, { deprecated: [boolean|message] })`
* Basic Tests
* Updated Readme
@mleguen
Copy link
Member

mleguen commented Feb 13, 2020

Thank you @laggingreflex

I will try to review this ASAP, but I am afraid I won't have time to do it before next week.

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 @laggingreflex

Would it be possible to address the translation issues before I merge?

lib/usage.js Outdated
@@ -294,6 +295,9 @@ module.exports = function usage (yargs, y18n) {
if (~options.number.indexOf(key)) type = `[${__('number')}]`

const extra = [
(key in deprecatedOptions)
? `[${__('deprecated')}${typeof deprecatedOptions[key] === 'string'
? `: ${deprecatedOptions[key]}` : ''}]` : null,
Copy link
Member

Choose a reason for hiding this comment

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

The ':' should be part of the string to translate, as in some languages (French for example) it is translated as ' :' (with a space). I would then recommend using 2 different translated strings: __('deprecated') (if no string is provided) and __('deprecated: %s') (if deprectedOptions[key] is a string).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

lib/usage.js Outdated
@@ -294,6 +295,9 @@ module.exports = function usage (yargs, y18n) {
if (~options.number.indexOf(key)) type = `[${__('number')}]`

const extra = [
(key in deprecatedOptions)
? `[${__('deprecated')}${typeof deprecatedOptions[key] === 'string'
Copy link
Member

Choose a reason for hiding this comment

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

Could you please add the new translation(s) to locales/en.json?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

r.logs[0].should.include(' -x [deprecated: string]')
})
})
describe('using .deprecateOption(x, [string])', () => {
Copy link
Member

Choose a reason for hiding this comment

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

this option should apply globally right, could we add a test that a deprecated command set at the top level carries to sub-commands?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@bcoe bcoe merged commit 8aae333 into yargs:master Feb 22, 2020
@bcoe
Copy link
Member

bcoe commented Feb 22, 2020

@laggingreflex thanks for the contribution 👍

@laggingreflex laggingreflex deleted the feat/deprecate-option branch February 22, 2020 05:30
@bcoe
Copy link
Member

bcoe commented Mar 8, 2020

@laggingreflex mind trying npm i yargs@next, and making sure your feature works as expected?

Thanks again for the contribution.

@laggingreflex
Copy link
Contributor Author

Yep, working as expected.

@friederbluemle
Copy link

Nice feature! Any chance this can be included in the @types/yargs TypeScript definitions as well?

@mleguen
Copy link
Member

mleguen commented Apr 23, 2020

@friederbluemle In the @types/yargs definitions, I am not sure, but it the typescript definitions yargs should soon ship directly, yes.

@tamj0rd2
Copy link

Has this been released? I haven't been able to use this in a typescript project using yargs 15.3.1

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