yargs: Add array and demand types for positional arguments (#41721)

* yargs: Add array and demand types for positional arguments

* Fix formatting
This commit is contained in:
Cameron Hunter 2020-01-31 15:15:24 -08:00 committed by GitHub
parent 7a44c8e8de
commit 7ede30d4fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 82 additions and 0 deletions

View File

@ -682,6 +682,8 @@ declare namespace yargs {
interface PositionalOptions {
/** string or array of strings, see `alias()` */
alias?: string | ReadonlyArray<string>;
/** boolean, interpret option as an array, see `array()` */
array?: boolean;
/** value or array of values, limit valid option arguments to a predefined set, see `choices()` */
choices?: Choices;
/** function, coerce or transform parsed command line values into another value, see `coerce()` */
@ -690,6 +692,8 @@ declare namespace yargs {
conflicts?: string | ReadonlyArray<string> | { [key: string]: string | ReadonlyArray<string> };
/** value, set a default value for the option, see `default()` */
default?: any;
/** boolean or string, demand the option be given, with optional error message, see `demandOption()` */
demandOption?: boolean | string;
/** string, the option description for help content, see `describe()` */
desc?: string;
/** string, the option description for help content, see `describe()` */

View File

@ -284,6 +284,7 @@ declare namespace yargs {
interface PositionalOptions {
alias?: string | string[];
array?: boolean;
choices?: Choices;
coerce?: (arg: any) => any;
conflicts?: string | string[] | { [key: string]: string | string[] };

View File

@ -298,6 +298,17 @@ function Argv$command() {
.argv;
}
function Argv$positional() {
yargs
.command('test [paths...]', 'run tests', yargs => {
yargs.positional('paths', {
type: 'string',
array: true,
});
})
.help().argv;
}
function Argv$completion_sync() {
const argv = yargs
.completion('completion', (current, argv) => {

View File

@ -299,6 +299,7 @@ declare namespace yargs {
interface PositionalOptions {
alias?: string | string[];
array?: boolean;
choices?: Choices;
coerce?: (arg: any) => any;
conflicts?: string | string[] | { [key: string]: string | string[] };

View File

@ -298,6 +298,17 @@ function Argv$command() {
.argv;
}
function Argv$positional() {
yargs
.command('test [paths...]', 'run tests', yargs => {
yargs.positional('paths', {
type: 'string',
array: true,
});
})
.help().argv;
}
function Argv$completion_sync() {
const argv = yargs
.completion('completion', (current, argv) => {

View File

@ -359,10 +359,12 @@ declare namespace yargs {
interface PositionalOptions {
alias?: string | ReadonlyArray<string>;
array?: boolean;
choices?: Choices;
coerce?: (arg: any) => any;
conflicts?: string | ReadonlyArray<string> | { [key: string]: string | ReadonlyArray<string> };
default?: any;
demandOption?: boolean | string;
desc?: string;
describe?: string;
description?: string;

View File

@ -321,6 +321,22 @@ function Argv$command() {
.argv;
}
function Argv$positional() {
const module: yargs.CommandModule<{}, { paths: string[] }> = {
command: 'test <paths...>',
builder(yargs) {
return yargs.positional('paths', {
type: 'string',
array: true,
demandOption: true
});
},
handler(argv) {
argv.paths.map((path) => path);
}
};
}
function Argv$commandModule() {
class CommandOne implements yargs.CommandModule {
handler(args: yargs.Arguments): void {

View File

@ -676,6 +676,8 @@ declare namespace yargs {
interface PositionalOptions {
/** string or array of strings, see `alias()` */
alias?: string | ReadonlyArray<string>;
/** boolean, interpret option as an array, see `array()` */
array?: boolean;
/** value or array of values, limit valid option arguments to a predefined set, see `choices()` */
choices?: Choices;
/** function, coerce or transform parsed command line values into another value, see `coerce()` */
@ -684,6 +686,8 @@ declare namespace yargs {
conflicts?: string | ReadonlyArray<string> | { [key: string]: string | ReadonlyArray<string> };
/** value, set a default value for the option, see `default()` */
default?: any;
/** boolean or string, demand the option be given, with optional error message, see `demandOption()` */
demandOption?: boolean | string;
/** string, the option description for help content, see `describe()` */
desc?: string;
/** string, the option description for help content, see `describe()` */

View File

@ -322,6 +322,22 @@ function Argv$command() {
.argv;
}
function Argv$positional() {
const module: yargs.CommandModule<{}, { paths: string[] }> = {
command: 'test <paths...>',
builder(yargs) {
return yargs.positional('paths', {
type: 'string',
array: true,
demandOption: true
});
},
handler(argv) {
argv.paths.map((path) => path);
}
};
}
function Argv$commandModule() {
class CommandOne implements yargs.CommandModule {
handler(args: yargs.Arguments): void {

View File

@ -322,6 +322,22 @@ function Argv$command() {
.argv;
}
function Argv$positional() {
const module: yargs.CommandModule<{}, { paths: string[] }> = {
command: 'test <paths...>',
builder(yargs) {
return yargs.positional('paths', {
type: 'string',
array: true,
demandOption: true
});
},
handler(argv) {
argv.paths.map((path) => path);
}
};
}
function Argv$commandModule() {
class CommandOne implements yargs.CommandModule {
handler(args: yargs.Arguments): void {