decline-ts
Version:
Composable command-line parser for TypeScript - a (partial) porting of Scala decline using fp-ts
83 lines (82 loc) • 6.49 kB
TypeScript
import { either, readonlyNonEmptyArray } from 'fp-ts';
import { Either } from 'fp-ts/Either';
import { Option } from 'fp-ts/Option';
import { ReadonlyNonEmptyArray } from 'fp-ts/ReadonlyNonEmptyArray';
import { Help } from '../Help';
import { Opts } from '../Opts';
import { Result } from '../Result';
import { ArgOut } from './ArgOut';
import { Match } from './Match';
import * as Ap from './types/Ap';
import * as Argument from './types/Argument';
import * as Arguments from './types/Arguments';
import * as Flag from './types/Flag';
import * as OrElse from './types/OrElse';
import * as Pure from './types/Pure';
import * as Regular from './types/Regular';
import * as Subcommand from './types/Subcommand';
import * as Validate from './types/Validate';
export declare type AccumulatorArgOut<A> = ArgOut<A>;
export declare const AccumulatorArgOut: typeof ArgOut;
export declare type AccumulatorMatch<A> = Match<A>;
export declare const AccumulatorMatch: {
fold: <A, B>({ onFlag, onOption, onAmbiguous }: {
readonly onFlag: (a: A) => B;
readonly onOption: (next: (str: string) => A) => B;
readonly onAmbiguous: import("fp-ts/lib/function").Lazy<B>;
}) => (fa: Match<A>) => B;
isMatchFlag: <A_1>(match: Match<A_1>) => match is import("./Match").MatchFlag<A_1>;
isMatchOption: <A_2>(match: Match<A_2>) => match is import("./Match").MatchOption<A_2>;
map: <A_3, B_1>(f: (a: A_3) => B_1) => (fa: Match<A_3>) => Match<B_1>;
match: import("fp-ts/lib/Functor").Functor1<"Match">;
matchAmbiguous: import("./Match").MatchAmbiguous;
matchFlag: <A_4>(next: A_4) => import("./Match").MatchFlag<A_4>;
matchOption: <A_5>(next: (str: string) => A_5) => import("./Match").MatchOption<A_5>;
};
declare type Err<A> = Either<ReadonlyArray<string>, A>;
declare type InstType<A, B> = {
readonly instance: A;
readonly innerType: B;
};
declare type InstanceKind<URI extends Accumulator.URIS, A> = Accumulators<A>[URI]['instance'];
declare type InnerTypeKind<URI extends Accumulator.URIS, A> = Accumulators<A>[URI]['innerType'];
declare type Accumulators<A> = {
readonly [Pure.URI]: InstType<Pure.Pure<A>, A>;
readonly [Ap.URI]: InstType<Ap.Ap<unknown, A>, A>;
readonly [OrElse.URI]: InstType<OrElse.OrElse<A>, A>;
readonly [Regular.URI]: InstType<Regular.Regular, ReadonlyNonEmptyArray<string>>;
readonly [Flag.URI]: InstType<Flag.Flag, ReadonlyNonEmptyArray<void>>;
readonly [Argument.URI]: InstType<Argument.Argument, string>;
readonly [Arguments.URI]: InstType<Arguments.Arguments, ReadonlyNonEmptyArray<string>>;
readonly [Subcommand.URI]: InstType<Subcommand.Subcommand<A>, A>;
readonly [Validate.URI]: InstType<Validate.Validate<unknown, A>, A>;
};
export declare type AccumulatorHKT<URI extends Accumulator.URIS> = {
readonly URI: URI;
readonly parseOption: (name: Opts.Name) => <A>(fa: InstanceKind<URI, A>) => Option<Match<Accumulator<InnerTypeKind<URI, A>>>>;
readonly parseArg?: (arg: string) => <A>(fa: InstanceKind<URI, A>) => ArgOut<InnerTypeKind<URI, A>>;
readonly parseSub: (command: string) => <A>(fa: InstanceKind<URI, A>) => Option<(opts: ReadonlyArray<string>) => Either<Help, Result<InnerTypeKind<URI, A>>>>;
readonly result: <A>(fa: InstanceKind<URI, A>) => Result<InnerTypeKind<URI, A>>;
};
export declare type Accumulator<A> = Accumulators<A>[Accumulator.URIS]['instance'];
export declare namespace Accumulator {
type URIS = keyof Accumulators<unknown>;
/**
* Constructors
*/
const orElse: <A>(left: Accumulator<A>, right: Accumulator<A>) => Accumulator<InnerTypeKind<OrElse.URI, A>>;
const fromOpts: <A>(opts: Opts<A>) => Regular.Regular | Flag.Flag | Argument.Argument | Arguments.Arguments | Pure.Pure<A> | OrElse.OrElse<A> | Subcommand.Subcommand<A> | Validate.Validate<unknown, A> | Ap.Ap<unknown, A>;
const instances: {
readonly [URI in URIS]: AccumulatorHKT<URI>;
};
/**
* Methods
*/
const parseOption: (name: Opts.Name) => <A>(fa: Regular.Regular | Flag.Flag | Argument.Argument | Arguments.Arguments | Pure.Pure<A> | OrElse.OrElse<A> | Subcommand.Subcommand<A> | Validate.Validate<unknown, A> | Ap.Ap<unknown, A>) => Option<Match<Regular.Regular | Flag.Flag | Argument.Argument | Arguments.Arguments | Pure.Pure<A> | OrElse.OrElse<A> | Subcommand.Subcommand<A> | Validate.Validate<unknown, A> | Ap.Ap<unknown, A>>>;
const parseArg: (arg: string) => <A>(fa: Regular.Regular | Flag.Flag | Argument.Argument | Arguments.Arguments | Pure.Pure<A> | OrElse.OrElse<A> | Subcommand.Subcommand<A> | Validate.Validate<unknown, A> | Ap.Ap<unknown, A>) => readonlyNonEmptyArray.ReadonlyNonEmptyArray<either.Either<Regular.Regular | Flag.Flag | Argument.Argument | Arguments.Arguments | Pure.Pure<A> | OrElse.OrElse<A> | Subcommand.Subcommand<A> | Validate.Validate<unknown, A> | Ap.Ap<unknown, A>, Regular.Regular | Flag.Flag | Argument.Argument | Arguments.Arguments | Pure.Pure<A> | OrElse.OrElse<A> | Subcommand.Subcommand<A> | Validate.Validate<unknown, A> | Ap.Ap<unknown, A>>>;
const parseSub: (command: string) => <A>(fa: Regular.Regular | Flag.Flag | Argument.Argument | Arguments.Arguments | Pure.Pure<A> | OrElse.OrElse<A> | Subcommand.Subcommand<A> | Validate.Validate<unknown, A> | Ap.Ap<unknown, A>) => Option<(opts: ReadonlyArray<string>) => either.Either<Help, Result<A>>>;
const result: <A>(fa: Regular.Regular | Flag.Flag | Argument.Argument | Arguments.Arguments | Pure.Pure<A> | OrElse.OrElse<A> | Subcommand.Subcommand<A> | Validate.Validate<unknown, A> | Ap.Ap<unknown, A>) => Result<A>;
const mapValidated: <A, B>(f: (a: A) => either.Either<readonly string[], B>) => (fa: Regular.Regular | Flag.Flag | Argument.Argument | Arguments.Arguments | Pure.Pure<A> | OrElse.OrElse<A> | Subcommand.Subcommand<A> | Validate.Validate<unknown, A> | Ap.Ap<unknown, A>) => Regular.Regular | Flag.Flag | Argument.Argument | Arguments.Arguments | Pure.Pure<B> | OrElse.OrElse<B> | Subcommand.Subcommand<B> | Validate.Validate<unknown, B> | Ap.Ap<unknown, B>;
const map: <A, B>(f: (a: A) => B) => (fa: Regular.Regular | Flag.Flag | Argument.Argument | Arguments.Arguments | Pure.Pure<A> | OrElse.OrElse<A> | Subcommand.Subcommand<A> | Validate.Validate<unknown, A> | Ap.Ap<unknown, A>) => Regular.Regular | Flag.Flag | Argument.Argument | Arguments.Arguments | Pure.Pure<B> | OrElse.OrElse<B> | Subcommand.Subcommand<B> | Validate.Validate<unknown, B> | Ap.Ap<unknown, B>;
}
export {};