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
feat: deprecateOption #1559
Conversation
* Added a method: `.deprecateOption(key, [message])` * Added a key in option conrtructor: `.option(key, { deprecated: [boolean|message] })` * Basic Tests * Updated Readme
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. |
There was a problem hiding this 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, |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
c7443b2
to
d285bf8
Compare
r.logs[0].should.include(' -x [deprecated: string]') | ||
}) | ||
}) | ||
describe('using .deprecateOption(x, [string])', () => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@laggingreflex thanks for the contribution 👍 |
@laggingreflex mind trying Thanks again for the contribution. |
Yep, working as expected. |
Nice feature! Any chance this can be included in the |
@friederbluemle In the |
Has this been released? I haven't been able to use this in a typescript project using yargs 15.3.1 |
Shows a
[deprecated]
notice in front of an option.deprecateOption(key, [message])
.option(key, { deprecated: [boolean|message] })
Work towards #1518