mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-07 16:30:12 +08:00
Added missing functions from version 3.31
- reset - epilog/epilogue - locale - detectLocale - choices - exitProcess Added an extra prototype for version, accepting a function argument
This commit is contained in:
@@ -134,6 +134,16 @@ function Argv$options() {
|
||||
;
|
||||
}
|
||||
|
||||
function Argv$choices() {
|
||||
// example from documentation
|
||||
var argv = yargs
|
||||
.alias('i', 'ingredient')
|
||||
.describe('i', 'choose your sandwich ingredients')
|
||||
.choices('i', ['peanut-butter', 'jelly', 'banana', 'pickles'])
|
||||
.help('help')
|
||||
.argv
|
||||
}
|
||||
|
||||
function command() {
|
||||
var argv = yargs
|
||||
.usage('npm <command>')
|
||||
@@ -208,4 +218,58 @@ function Argv$version() {
|
||||
|
||||
var argv3 = yargs
|
||||
.version('1.0.0', '--version', 'description');
|
||||
|
||||
var argv4 = yargs
|
||||
.version( function() { return '1.0.0'; }, '--version', 'description');
|
||||
}
|
||||
|
||||
function Argv$locale() {
|
||||
var argv = yargs
|
||||
.usage('./$0 - follow ye instructions true')
|
||||
.option('option', {
|
||||
alias: 'o',
|
||||
describe: "'tis a mighty fine option",
|
||||
demand: true
|
||||
})
|
||||
.command('run', "Arrr, ya best be knowin' what yer doin'")
|
||||
.example('$0 run foo', "shiver me timbers, here's an example for ye")
|
||||
.help('help')
|
||||
.wrap(70)
|
||||
.locale('pirate')
|
||||
.argv
|
||||
}
|
||||
|
||||
function Argv$epilogue() {
|
||||
var argv = yargs
|
||||
.epilogue('for more information, find our manual at http://example.com');
|
||||
}
|
||||
|
||||
function Argv$reset() {
|
||||
var ya = yargs
|
||||
.usage('$0 command')
|
||||
.command('hello', 'hello command')
|
||||
.command('world', 'world command')
|
||||
.demand(1, 'must provide a valid command'),
|
||||
argv = yargs.argv,
|
||||
command = argv._[0];
|
||||
|
||||
if (command === 'hello') {
|
||||
ya.reset()
|
||||
.usage('$0 hello')
|
||||
.help('h')
|
||||
.example('$0 hello', 'print the hello message!')
|
||||
.argv
|
||||
|
||||
console.log('hello!');
|
||||
} else if (command === 'world'){
|
||||
ya.reset()
|
||||
.usage('$0 world')
|
||||
.help('h')
|
||||
.example('$0 world', 'print the world message!')
|
||||
.argv
|
||||
|
||||
console.log('world!');
|
||||
} else {
|
||||
ya.showHelp();
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+17
@@ -11,6 +11,13 @@ declare module "yargs" {
|
||||
(...args: any[]): any;
|
||||
parse(...args: any[]): any;
|
||||
|
||||
reset(): Argv;
|
||||
|
||||
locale(): string;
|
||||
locale(loc:string): Argv;
|
||||
|
||||
detectLocale(detect:boolean): Argv;
|
||||
|
||||
alias(shortName: string, longName: string): Argv;
|
||||
alias(aliases: { [shortName: string]: string }): Argv;
|
||||
alias(aliases: { [shortName: string]: string[] }): Argv;
|
||||
@@ -71,6 +78,9 @@ declare module "yargs" {
|
||||
string(key: string): Argv;
|
||||
string(keys: string[]): Argv;
|
||||
|
||||
choices(choices: Object): Argv;
|
||||
choices(key: string, values:any[]): Argv;
|
||||
|
||||
config(key: string): Argv;
|
||||
config(keys: string[]): Argv;
|
||||
|
||||
@@ -81,12 +91,18 @@ declare module "yargs" {
|
||||
help(): string;
|
||||
help(option: string, description?: string): Argv;
|
||||
|
||||
epilog(msg: string): Argv;
|
||||
epilogue(msg: string): Argv;
|
||||
|
||||
version(version: string, option?: string, description?: string): Argv;
|
||||
version(version: () => string, option?: string, description?: string): Argv;
|
||||
|
||||
showHelpOnFail(enable: boolean, message?: string): Argv;
|
||||
|
||||
showHelp(func?: (message: string) => any): Argv;
|
||||
|
||||
exitProcess(enabled:boolean): Argv;
|
||||
|
||||
/* Undocumented */
|
||||
|
||||
normalize(key: string): Argv;
|
||||
@@ -115,6 +131,7 @@ declare module "yargs" {
|
||||
description?: any;
|
||||
desc?: any;
|
||||
requiresArg?: any;
|
||||
choices?:string[];
|
||||
}
|
||||
|
||||
type SyncCompletionFunction = (current: string, argv: any) => string[];
|
||||
|
||||
Reference in New Issue
Block a user