gunshi / combinators
combinators
Experimental
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}`)
}
})This module is experimental and may change in future versions.
Functions
| Function | Description |
|---|---|
| args | - |
| boolean | - |
| choice | - |
| combinator | - |
| describe | - |
| extend | - |
| float | - |
| integer | - |
| map | - |
| merge | - |
| multiple | - |
| number | - |
| positional | - |
| required | - |
| short | - |
| string | - |
| unrequired | - |
| withDefault | - |
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. |
