-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
60 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,47 @@ | ||
import { program, command } from '../src' | ||
|
||
/** | ||
* Keep in mind that argument/option types are not validated at runtime. | ||
* For example, when providing a default value with type boolean, it can be set | ||
* to a string value at runtime. | ||
*/ | ||
|
||
const string = command('string') | ||
.argument('arg', 'Required string argument') | ||
.option('opt', 'Optional string option', { type: 'string' }) | ||
.argument('arg', { description: 'Required string argument' }) | ||
.option('opt', { description: 'Optional string option', type: 'string' }) | ||
.action((args) => { | ||
console.log('Args are', args) | ||
}) | ||
|
||
const choices = command('string') | ||
.argument('arg', 'Required string argument') | ||
.option('opt', 'Optional string option', { type: 'string' }) | ||
const choices = command('choices') | ||
.argument('arg', { | ||
description: 'Argument with choices', | ||
choices: ['foo', 'bar'] as const, | ||
}) | ||
.option('opt', { | ||
description: 'Option with choices', | ||
choices: ['option1', 'option2'] as const, | ||
default: 'option3', | ||
}) | ||
.action((args) => { | ||
console.log('Args are', args) | ||
}) | ||
|
||
const defaultValues = command('default') | ||
.argument('arg', { | ||
description: 'Optional argument with default value', | ||
default: 5, | ||
optional: true, | ||
}) | ||
.option('opt', { description: 'Default value', default: true }) | ||
.action((args) => { | ||
console.log('Args are', args) | ||
}) | ||
|
||
const app = program().description('All argument and option types').add(string) | ||
const app = program() | ||
.description('All argument and option types') | ||
.add(string) | ||
.add(choices) | ||
.add(defaultValues) | ||
|
||
app.withHelp().runOrRepl() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters