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

[yargs] Example can take an array of args #47885

Merged
merged 2 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions types/yargs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ declare namespace yargs {
* Examples will be printed out as part of the help message.
*/
example(command: string, description: string): Argv<T>;
example(command: ReadonlyArray<[string, string?]>): Argv<T>;

/** Manually indicate that the program should exit, and provide context about why we wanted to exit. Follows the behavior set by `.exitProcess().` */
exit(code: number, err: Error): void;
Expand Down
27 changes: 27 additions & 0 deletions types/yargs/yargs-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,33 @@ function Argv$command() {
.argv;
}

function Argv$example() {
yargs
.command({
command: 'get',
handler: () => {
// command
},
})
.command({
command: 'post',
handler: () => {
// command
},
})
.command({
command: 'delete',
handler: () => {
// command
},
})
.example([
['$0 get', 'get https://example.com/'],
['$0 post', 'post https://example.com/'],
])
.example('$0 delete', 'delete https://example.com').argv;
}

function Argv$positional() {
const module: yargs.CommandModule<{}, { paths: string[] }> = {
command: 'test <paths...>',
Expand Down