Skip to content

gunshi / combinators / positional

Function: positional()

Call Signature

ts
function positional<T>(parser): ArgSchema & Combinator<T> & ArgSchemaPositionalType;

Experimental

Create a positional argument schema.

Without a parser, resolves to string. With a parser (e.g., positional(integer())), resolves to the parser's return type.

Type Parameters

Type ParameterDescription
TThe parser's resolved type.

Parameters

ParameterTypeDescription
parserCombinatorSchema<T>The parser combinator schema.

Returns

ArgSchema & Combinator<T> & ArgSchemaPositionalType

A positional argument schema resolving to the parser's type.

Example

ts
const args = {
  command: positional(),           // resolves to string
  port: positional(integer()),     // resolves to number
}

Call Signature

ts
function positional(parser?): ArgSchema & ArgSchemaPositionalType;

Experimental

Create a positional argument schema.

Without a parser, resolves to string. With a parser (e.g., positional(integer())), resolves to the parser's return type.

Parameters

ParameterTypeDescription
parser?BaseOptionsOptional base options (description, short, required).

Returns

ArgSchema & ArgSchemaPositionalType

A positional argument schema resolving to string.

Example

ts
const args = {
  command: positional(),           // resolves to string
  port: positional(integer()),     // resolves to number
}

Released under the MIT License.