combinators
WARNING
This module is experimental and may change in future versions.
Parser combinator entry point.
This entry point exports composable combinator factory functions for building type-safe argument schemas. These combinators produce ArgSchema objects that can be used anywhere regular argument schemas are accepted.
Example
ts
import { string, integer, boolean, required, withDefault, short } from 'gunshi/combinators'
import { define, cli } from 'gunshi'
const command = define({
name: 'serve',
args: {
host: withDefault(string(), 'localhost'),
port: withDefault(integer({ min: 1, max: 65535 }), 8080),
verbose: short(boolean(), 'v')
},
run: ctx => {
console.log(`Listening on ${ctx.values.host}:${ctx.values.port}`)
}
})Functions
| Function | Description |
|---|---|
| args | Type-safe schema factory. |
| boolean | Create a boolean argument schema. |
| choice | Create an enum-like argument schema with literal type inference. |
| combinator | Create a custom argument schema with a user-defined parse function. |
| describe | Set a description on a combinator schema for help text generation. |
| extend | Extend a schema by overriding or adding fields. |
| float | Create a floating-point argument schema with optional range validation. |
| integer | Create an integer argument schema with optional range validation. |
| map | Transform the output of a combinator schema. |
| merge | Compose multiple Args schemas into one. |
| multiple | Mark a combinator schema as accepting multiple values. |
| number | Create a number argument schema with optional range validation. |
| positional | Create a positional argument schema. |
| required | Mark a combinator schema as required. |
| short | Set a short alias on a combinator schema. |
| string | Create a string argument schema with optional validation. |
| unrequired | Mark a combinator schema as not required. |
| withDefault | Set a default value on a combinator schema. |
Interfaces
| Interface | Description |
|---|---|
| BaseOptions | Common options shared by all base combinators. |
| BooleanOptions | Options for the boolean combinator. |
| CombinatorOptions | Options for the combinator factory function. |
| FloatOptions | Options for the float combinator. |
| IntegerOptions | Options for the integer combinator. |
| NumberOptions | Options for the number combinator. |
| StringOptions | Options for the string combinator. |
Type Aliases
| Type Alias | Description |
|---|---|
| Combinator | A combinator produced by combinator factory functions. |
| CombinatorSchema | A schema produced by combinator factory functions. Any ArgSchema with a parse function qualifies. |
