Skip to content

Commit

Permalink
docs(command, flags): add integer type to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed May 6, 2021
1 parent 2cc7e57 commit 6aec3db
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
16 changes: 9 additions & 7 deletions command/README.md
Expand Up @@ -48,8 +48,8 @@
- [Install](#-install)
- [Usage](#-usage)
- [Options](#-options)
- [Common option types: string, number and
boolean](#common-option-types-string-number-and-boolean)
- [Common option types: boolean, string, number and
integer](#common-option-types-boolean-string-number-and-integer)
- [List option types](#list-option-types)
- [Variadic options](#variadic-options)
- [Dotted options](#dotted-options)
Expand Down Expand Up @@ -190,17 +190,19 @@ the command in the `options` object, all arguments in the `args` array and all
literal arguments in the literal array. For all unknown options the command will
throw an error message and exit the program with `Deno.exit(1)`.

### Common option types: string, number and boolean
### Common option types: boolean, string, number and integer

Optionally you can declare a type after the argument name, separated by colon
`<name:type>`. If no type is specified, the type defaults to `string`. Following
types are availeble per default (_more will be added_):

- **string:** can be any value
- **boolean:** Can be one of: `true`, `false`, `1` or `0`.

- **number:** can be any numeric value
- **string:** Can be any value.

- **boolean:** can be one of: `true`, `false`, `1` or `0`,
- **number:** Can be any numeric value.

- **integer:** Can be any integer value.

```typescript
import { Command } from "https://deno.land/x/cliffy/command/mod.ts";
Expand All @@ -211,7 +213,7 @@ const { options } = await new Command()
// required string value
.option("-p, --pizza-type <type>", "Flavour of pizza.")
// required number value
.option("-a, --amount <amount:number>", "Pieces of pizza.")
.option("-a, --amount <amount:integer>", "Pieces of pizza.")
.parse(Deno.args);

console.log(options);
Expand Down
2 changes: 1 addition & 1 deletion examples/command/common_option_types.ts
Expand Up @@ -8,7 +8,7 @@ const { options } = await new Command()
// required string value
.option("-p, --pizza-type <type>", "Flavour of pizza.")
// required number value
.option("-a, --amount <amount:number>", "Pieces of pizza.")
.option("-a, --amount <amount:integer>", "Pieces of pizza.")
.parse(Deno.args);

console.log(options);
4 changes: 3 additions & 1 deletion flags/README.md
Expand Up @@ -239,11 +239,13 @@ $ deno run https://deno.land/x/cliffy/examples/flags/error_handling.ts -d

### OptionType

- `OptionType.BOOLEAN`

- `OptionType.STRING`

- `OptionType.NUMBER`

- `OptionType.BOOLEAN`
- `OptionType.INTEGER`

## ❯ Custom type processing

Expand Down

0 comments on commit 6aec3db

Please sign in to comment.