Skip to content

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

FunctionDescription
args-
boolean-
choice-
combinator-
describe-
extend-
float-
integer-
map-
merge-
multiple-
number-
positional-
required-
short-
string-
unrequired-
withDefault-

Interfaces

InterfaceDescription
BaseOptionsCommon options shared by all base combinators.
BooleanOptionsOptions for the boolean combinator.
CombinatorOptionsOptions for the combinator factory function.
FloatOptionsOptions for the float combinator.
IntegerOptionsOptions for the integer combinator.
NumberOptionsOptions for the number combinator.
StringOptionsOptions for the string combinator.

Type Aliases

Type AliasDescription
CombinatorA combinator produced by combinator factory functions.
CombinatorSchemaA schema produced by combinator factory functions. Any ArgSchema with a parse function qualifies.

Released under the MIT License.