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
Changes from 1 commit
3ef37c8
4c1ac6e
d285bf8
bc48704
c7d421e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,6 +155,7 @@ module.exports = function usage (yargs, y18n) { | |
const base$0 = yargs.customScriptName ? yargs.$0 : path.basename(yargs.$0) | ||
const demandedOptions = yargs.getDemandedOptions() | ||
const demandedCommands = yargs.getDemandedCommands() | ||
const deprecatedOptions = yargs.getDeprecatedOptions() | ||
const groups = yargs.getGroups() | ||
const options = yargs.getOptions() | ||
|
||
|
@@ -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 commentThe 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: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
type, | ||
(key in demandedOptions) ? `[${__('required')}]` : null, | ||
options.choices && options.choices[key] ? `[${__('choices:')} ${ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -313,6 +313,47 @@ describe('usage tests', () => { | |
}) | ||
}) | ||
|
||
describe('deprecate options', () => { | ||
describe('using .option(x, {deprecate: [boolean|string]})', () => { | ||
it('{deprecated: true} should show [deprecated]', () => { | ||
const r = checkUsage(() => yargs('--help') | ||
.option('x', { deprecated: true }) | ||
.wrap(null) | ||
.parse() | ||
) | ||
r.logs[0].should.include(' -x [deprecated]') | ||
}) | ||
it('{deprecated: string} should show [deprecated: string]', () => { | ||
const r = checkUsage(() => yargs('--help') | ||
.option('x', { deprecated: 'string' }) | ||
.wrap(null) | ||
.parse() | ||
) | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. this option should apply There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
it('.deprecateOption(x) should show [deprecated]', () => { | ||
const r = checkUsage(() => yargs('--help') | ||
.option('x') | ||
.deprecateOption('x') | ||
.wrap(null) | ||
.parse() | ||
) | ||
r.logs[0].should.include(' -x [deprecated]') | ||
}) | ||
it('.deprecateOption(x, string) should show [deprecated: string]', () => { | ||
const r = checkUsage(() => yargs('--help') | ||
.option('x') | ||
.deprecateOption('x', 'string') | ||
.wrap(null) | ||
.parse() | ||
) | ||
r.logs[0].should.include(' -x [deprecated: string]') | ||
}) | ||
}) | ||
}) | ||
|
||
it('should return valid values when check passes', () => { | ||
const r = checkUsage(() => yargs('-x 10 -y 20') | ||
.usage('Usage: $0 -x NUM -y NUM') | ||
|
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