decline-ts
Version:
Composable command-line parser for TypeScript - a (partial) porting of Scala decline using fp-ts
65 lines (64 loc) • 2.24 kB
TypeScript
import { alt as Alt, semigroup as Semigroup, apply, either } from 'fp-ts';
import { Either } from 'fp-ts/Either';
import { Lazy } from 'fp-ts/function';
import { Opts } from './Opts';
declare const URI_ = "Result";
declare type URI_ = typeof URI_;
declare module 'fp-ts/HKT' {
interface URItoKind<A> {
readonly [URI_]: Result<A>;
}
}
export declare type Result<A> = {
readonly get: Either<Result.Failure, Lazy<Either<ReadonlyArray<string>, A>>>;
};
export declare function Result<A>(get: Either<Result.Failure, Lazy<Either<ReadonlyArray<string>, A>>>): Result<A>;
export declare namespace Result {
/**
* Constructors
*/
const success: <A>(value: A) => Result<A>;
const failure: (reversedMissing: ReadonlyArray<Missing>) => Result<never>;
const fail: Result<never>;
const missingCommand: (command: string) => Result<never>;
const missingFlag: (flag: Opts.Name) => Result<never>;
const missingArgument: Result<never>;
/**
* Methods
*/
const mapValidated: <A, B>(f: (a: A) => either.Either<readonly string[], B>) => (res: Result<A>) => Result<B>;
const map: <A, B>(f: (a: A) => B) => (fa: Result<A>) => Result<B>;
const ap: <A, B>(fab: Result<(a: A) => B>) => (fa: Result<A>) => Result<B>;
const alt: <A>(that: Lazy<Result<A>>) => (fa: Result<A>) => Result<A>;
/**
* Instance
*/
const URI = "Result";
type URI = URI_;
const result: apply.Apply1<URI> & Alt.Alt1<URI>;
/**
* Failure
*/
type Failure = {
readonly reversedMissing: ReadonlyArray<Missing>;
};
function Failure(reversedMissing: ReadonlyArray<Missing>): Failure;
namespace Failure {
const semigroup: Semigroup.Semigroup<Failure>;
const messages: (f: Failure) => ReadonlyArray<string>;
}
/**
* Missing
*/
type Missing = {
readonly flags: ReadonlyArray<Opts.Name>;
readonly commands: ReadonlyArray<string>;
readonly argument: boolean;
};
function Missing({ flags, commands, argument, }?: Partial<Missing>): Missing;
namespace Missing {
const semigroup: Semigroup.Semigroup<Missing>;
const message: (m: Missing) => string;
}
}
export {};