Comparing version 0.3.2 to 0.4.0
import { AstNode } from './newparser/parser'; | ||
import { Result } from './Result'; | ||
export declare type Nodes = AstNode[]; | ||
@@ -16,3 +17,2 @@ export declare type ParsingError = { | ||
export declare type FailedParse<Into> = { | ||
outcome: 'failure'; | ||
errors: ParsingError[]; | ||
@@ -22,6 +22,2 @@ /** The content that was parsed so far */ | ||
}; | ||
export declare type SuccessfulParse<Into> = { | ||
outcome: 'success'; | ||
value: Into; | ||
}; | ||
export declare type ParseContext = { | ||
@@ -38,3 +34,3 @@ /** The nodes we parsed */ | ||
}; | ||
export declare type ParsingResult<Into> = FailedParse<Into> | SuccessfulParse<Into>; | ||
export declare type ParsingResult<Into> = Result<FailedParse<Into>, Into>; | ||
export declare type RegisterOptions = { | ||
@@ -51,3 +47,3 @@ forceFlagLongNames: Set<string>; | ||
}; | ||
export declare type ArgParser<Into> = Register & { | ||
export declare type ArgParser<Into> = Partial<Register> & { | ||
/** | ||
@@ -54,0 +50,0 @@ * Parse from AST nodes into the value provided in [[Into]]. |
@@ -1,10 +0,11 @@ | ||
import { ArgParser } from './argparser'; | ||
import { ArgParser, Register } from './argparser'; | ||
import { ProvidesHelp } from './helpdoc'; | ||
import * as Result from './Result'; | ||
declare type CircuitBreaker = 'help' | 'version'; | ||
export declare const helpFlag: import("./argparser").Register & { | ||
parse(context: import("./argparser").ParseContext): Promise<import("./argparser").ParsingResult<boolean>>; | ||
} & ProvidesHelp & Partial<import("./helpdoc").Descriptive>; | ||
export declare const versionFlag: import("./argparser").Register & { | ||
parse(context: import("./argparser").ParseContext): Promise<import("./argparser").ParsingResult<boolean>>; | ||
} & ProvidesHelp & Partial<import("./helpdoc").Descriptive>; | ||
export declare const helpFlag: Partial<Register> & { | ||
parse(context: import("./argparser").ParseContext): Promise<Result.Result<import("./argparser").FailedParse<boolean>, boolean>>; | ||
} & ProvidesHelp & Register & Partial<import("./helpdoc").Descriptive>; | ||
export declare const versionFlag: Partial<Register> & { | ||
parse(context: import("./argparser").ParseContext): Promise<Result.Result<import("./argparser").FailedParse<boolean>, boolean>>; | ||
} & ProvidesHelp & Register & Partial<import("./helpdoc").Descriptive>; | ||
/** | ||
@@ -18,3 +19,3 @@ * Helper flags that are being used in `command` and `subcommands`: | ||
*/ | ||
export declare const circuitbreaker: ArgParser<CircuitBreaker> & ProvidesHelp; | ||
export declare const circuitbreaker: ArgParser<CircuitBreaker> & ProvidesHelp & Register; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const types_1 = require("./types"); | ||
const flag_1 = require("./flag"); | ||
const utils_1 = require("./utils"); | ||
const Result = tslib_1.__importStar(require("./Result")); | ||
exports.helpFlag = flag_1.flag({ | ||
@@ -37,16 +39,15 @@ long: 'help', | ||
const version = await exports.versionFlag.parse(context); | ||
if (help.outcome === 'failure' || version.outcome === 'failure') { | ||
const helpErrors = help.outcome === 'failure' ? help.errors : []; | ||
const versionErrors = version.outcome === 'failure' ? version.errors : []; | ||
return { outcome: 'failure', errors: [...helpErrors, ...versionErrors] }; | ||
if (Result.isErr(help) || Result.isErr(version)) { | ||
const helpErrors = Result.isErr(help) ? help.error.errors : []; | ||
const versionErrors = Result.isErr(version) ? version.error.errors : []; | ||
return Result.err({ errors: [...helpErrors, ...versionErrors] }); | ||
} | ||
if (help.value) { | ||
return { outcome: 'success', value: 'help' }; | ||
return Result.ok('help'); | ||
} | ||
else if (version.value) { | ||
return { outcome: 'success', value: 'version' }; | ||
return Result.ok('version'); | ||
} | ||
else { | ||
return { | ||
outcome: 'failure', | ||
return Result.err({ | ||
errors: [ | ||
@@ -58,3 +59,3 @@ { | ||
], | ||
}; | ||
}); | ||
} | ||
@@ -61,0 +62,0 @@ }, |
@@ -7,2 +7,3 @@ "use strict"; | ||
const circuitbreaker_1 = require("./circuitbreaker"); | ||
const Result = tslib_1.__importStar(require("./Result")); | ||
/** | ||
@@ -59,4 +60,5 @@ * A command line utility. | ||
register(opts) { | ||
var _a; | ||
for (const [, arg] of argEntries) { | ||
arg.register(opts); | ||
(_a = arg.register) === null || _a === void 0 ? void 0 : _a.call(arg, opts); | ||
} | ||
@@ -73,4 +75,4 @@ }, | ||
const result = await arg.parse(context); | ||
if (result.outcome === 'failure') { | ||
errors.push(...result.errors); | ||
if (Result.isErr(result)) { | ||
errors.push(...result.error.errors); | ||
} | ||
@@ -105,13 +107,9 @@ else { | ||
if (errors.length > 0) { | ||
return { | ||
outcome: 'failure', | ||
return Result.err({ | ||
errors: errors, | ||
partialValue: resultObject, | ||
}; | ||
}); | ||
} | ||
else { | ||
return { | ||
outcome: 'success', | ||
value: resultObject, | ||
}; | ||
return Result.ok(resultObject); | ||
} | ||
@@ -122,4 +120,4 @@ }, | ||
const breaker = await circuitbreaker_1.circuitbreaker.parse(context); | ||
const shouldShowHelp = breaker.outcome === 'success' && breaker.value === 'help'; | ||
const shouldShowVersion = breaker.outcome === 'success' && breaker.value === 'version'; | ||
const shouldShowHelp = Result.isOk(breaker) && breaker.value === 'help'; | ||
const shouldShowVersion = Result.isOk(breaker) && breaker.value === 'version'; | ||
if (shouldShowHelp) { | ||
@@ -133,10 +131,9 @@ this.printHelp(context); | ||
} | ||
if (parsed.outcome === 'failure') { | ||
return { | ||
outcome: 'failure', | ||
errors: parsed.errors, | ||
partialValue: { ...parsed.partialValue }, | ||
}; | ||
if (Result.isErr(parsed)) { | ||
return Result.err({ | ||
errors: parsed.error.errors, | ||
partialValue: { ...parsed.error.partialValue }, | ||
}); | ||
} | ||
return { outcome: 'success', value: this.handler(parsed.value) }; | ||
return Result.ok(this.handler(parsed.value)); | ||
}, | ||
@@ -143,0 +140,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
import { ArgParser } from './argparser'; | ||
import { ArgParser, Register } from './argparser'; | ||
import { ProvidesHelp, Descriptive, ShortDoc, LongDoc, EnvDoc } from './helpdoc'; | ||
@@ -21,3 +21,3 @@ import { Type, OutputOf, HasType } from './type'; | ||
*/ | ||
export declare function flag<Decoder extends Type<boolean, any>>(config: FlagConfig<Decoder>): ArgParser<OutputOf<Decoder>> & ProvidesHelp & Partial<Descriptive>; | ||
export declare function flag<Decoder extends Type<boolean, any>>(config: FlagConfig<Decoder>): ArgParser<OutputOf<Decoder>> & ProvidesHelp & Register & Partial<Descriptive>; | ||
export {}; |
@@ -7,2 +7,3 @@ "use strict"; | ||
const chalk_1 = tslib_1.__importDefault(require("chalk")); | ||
const Result = tslib_1.__importStar(require("./Result")); | ||
/** | ||
@@ -15,9 +16,6 @@ * A decoder from `string` to `boolean` | ||
if (str === 'true') | ||
return { result: 'ok', value: true }; | ||
return true; | ||
if (str === 'false') | ||
return { result: 'ok', value: false }; | ||
return { | ||
result: 'error', | ||
message: `expected value to be either "true" or "false". got: "${str}"`, | ||
}; | ||
return false; | ||
throw new Error(`expected value to be either "true" or "false". got: "${str}"`); | ||
}, | ||
@@ -86,4 +84,3 @@ displayName: 'true/false', | ||
if (options.length > 1) { | ||
return { | ||
outcome: 'failure', | ||
return Result.err({ | ||
errors: [ | ||
@@ -95,3 +92,3 @@ { | ||
], | ||
}; | ||
}); | ||
} | ||
@@ -108,10 +105,9 @@ const valueFromEnv = config.env ? process.env[config.env] : undefined; | ||
try { | ||
return { outcome: 'success', value: config.type.defaultValue() }; | ||
return Result.ok(config.type.defaultValue()); | ||
} | ||
catch (e) { | ||
const message = `Default value not found for '--${config.long}': ${e.message}`; | ||
return { | ||
outcome: 'failure', | ||
return Result.err({ | ||
errors: [{ message, nodes: [] }], | ||
}; | ||
}); | ||
} | ||
@@ -123,22 +119,20 @@ } | ||
else { | ||
return { | ||
outcome: 'failure', | ||
return Result.err({ | ||
errors: [ | ||
{ nodes: [], message: `No value provided for --${config.long}` }, | ||
], | ||
}; | ||
}); | ||
} | ||
const decoded = await decoder.from(rawValue); | ||
if (decoded.result === 'error') { | ||
return { | ||
outcome: 'failure', | ||
const decoded = await Result.safeAsync(decoder.from(rawValue)); | ||
if (Result.isErr(decoded)) { | ||
return Result.err({ | ||
errors: [ | ||
{ | ||
nodes: options, | ||
message: envPrefix + decoded.message, | ||
message: envPrefix + decoded.error.message, | ||
}, | ||
], | ||
}; | ||
}); | ||
} | ||
return { outcome: 'success', value: decoded.value }; | ||
return decoded; | ||
}, | ||
@@ -145,0 +139,0 @@ }; |
@@ -1,9 +0,2 @@ | ||
export declare type DecodeResult<T> = { | ||
result: 'ok'; | ||
value: T; | ||
} | { | ||
result: 'error'; | ||
message: string; | ||
}; | ||
export declare type FromFn<A, B> = (input: A) => Promise<DecodeResult<B>>; | ||
export declare type FromFn<A, B> = (input: A) => Promise<B>; | ||
/** A safe conversion from type A to type B */ | ||
@@ -10,0 +3,0 @@ export declare type From<A, B> = { |
@@ -9,3 +9,3 @@ "use strict"; | ||
async from(a) { | ||
return { result: 'ok', value: a }; | ||
return a; | ||
}, | ||
@@ -12,0 +12,0 @@ }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const findOption_1 = require("./newparser/findOption"); | ||
const flag_1 = require("./flag"); | ||
const Result = tslib_1.__importStar(require("./Result")); | ||
/** | ||
@@ -44,5 +46,5 @@ * Like `option`, but can accept multiple options, and expects a decoder from a list of strings. | ||
for (const option of options) { | ||
const decoded = await flag_1.boolean.from((_b = (_a = option.value) === null || _a === void 0 ? void 0 : _a.node.raw) !== null && _b !== void 0 ? _b : 'true'); | ||
if (decoded.result === 'error') { | ||
errors.push({ nodes: [option], message: decoded.message }); | ||
const decoded = await Result.safeAsync(flag_1.boolean.from((_b = (_a = option.value) === null || _a === void 0 ? void 0 : _a.node.raw) !== null && _b !== void 0 ? _b : 'true')); | ||
if (Result.isErr(decoded)) { | ||
errors.push({ nodes: [option], message: decoded.error.message }); | ||
} | ||
@@ -54,20 +56,18 @@ else { | ||
if (errors.length > 0) { | ||
return { | ||
outcome: 'failure', | ||
return Result.err({ | ||
errors, | ||
}; | ||
}); | ||
} | ||
const multiDecoded = await config.type.from(optionValues); | ||
if (multiDecoded.result === 'error') { | ||
return { | ||
outcome: 'failure', | ||
const multiDecoded = await Result.safeAsync(config.type.from(optionValues)); | ||
if (Result.isErr(multiDecoded)) { | ||
return Result.err({ | ||
errors: [ | ||
{ | ||
nodes: options, | ||
message: multiDecoded.message, | ||
message: multiDecoded.error.message, | ||
}, | ||
], | ||
}; | ||
}); | ||
} | ||
return { outcome: 'success', value: multiDecoded.value }; | ||
return multiDecoded; | ||
}, | ||
@@ -74,0 +74,0 @@ }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const findOption_1 = require("./newparser/findOption"); | ||
const Result = tslib_1.__importStar(require("./Result")); | ||
/** | ||
@@ -54,20 +56,11 @@ * Like `option`, but can accept multiple options, and expects a decoder from a list of strings. | ||
if (errors.length > 0) { | ||
return { | ||
outcome: 'failure', | ||
errors, | ||
}; | ||
return Result.err({ errors }); | ||
} | ||
const multiDecoded = await config.type.from(optionValues); | ||
if (multiDecoded.result === 'error') { | ||
return { | ||
outcome: 'failure', | ||
errors: [ | ||
{ | ||
nodes: options, | ||
message: multiDecoded.message, | ||
}, | ||
], | ||
}; | ||
const multiDecoded = await Result.safeAsync(config.type.from(optionValues)); | ||
if (Result.isErr(multiDecoded)) { | ||
return Result.err({ | ||
errors: [{ nodes: options, message: multiDecoded.error.message }], | ||
}); | ||
} | ||
return { outcome: 'success', value: multiDecoded.value }; | ||
return multiDecoded; | ||
}, | ||
@@ -74,0 +67,0 @@ }; |
@@ -6,2 +6,3 @@ "use strict"; | ||
const chalk_1 = tslib_1.__importDefault(require("chalk")); | ||
const Result = tslib_1.__importStar(require("./Result")); | ||
/** | ||
@@ -70,6 +71,3 @@ * Decodes an argument which is in the form of a key and a value, and allows parsing the following ways: | ||
}; | ||
return { | ||
outcome: 'failure', | ||
errors: [error], | ||
}; | ||
return Result.err({ errors: [error] }); | ||
} | ||
@@ -90,11 +88,7 @@ const valueFromEnv = config.env ? process.env[config.env] : undefined; | ||
try { | ||
return { | ||
outcome: 'success', | ||
value: defaultValueFn(), | ||
}; | ||
return Result.ok(defaultValueFn()); | ||
} | ||
catch (e) { | ||
const message = `Default value not found for '--${config.long}': ${e.message}`; | ||
return { | ||
outcome: 'failure', | ||
return Result.err({ | ||
errors: [ | ||
@@ -106,3 +100,3 @@ { | ||
], | ||
}; | ||
}); | ||
} | ||
@@ -114,4 +108,3 @@ } | ||
: `--${(_b = option === null || option === void 0 ? void 0 : option.key) !== null && _b !== void 0 ? _b : config.long}`; | ||
return { | ||
outcome: 'failure', | ||
return Result.err({ | ||
errors: [ | ||
@@ -123,15 +116,13 @@ { | ||
], | ||
}; | ||
}); | ||
} | ||
const decoded = await config.type.from(rawValue); | ||
if (decoded.result === 'error') { | ||
return { | ||
outcome: 'failure', | ||
errors: [{ nodes: options, message: envPrefix + decoded.message }], | ||
}; | ||
const decoded = await Result.safeAsync(config.type.from(rawValue)); | ||
if (Result.isErr(decoded)) { | ||
return Result.err({ | ||
errors: [ | ||
{ nodes: options, message: envPrefix + decoded.error.message }, | ||
], | ||
}); | ||
} | ||
return { | ||
outcome: 'success', | ||
value: decoded.value, | ||
}; | ||
return Result.ok(decoded.value); | ||
}, | ||
@@ -138,0 +129,0 @@ }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const Result = tslib_1.__importStar(require("./Result")); | ||
/** | ||
@@ -31,4 +33,3 @@ * A positional command line argument. | ||
if (!positional) { | ||
return { | ||
outcome: 'failure', | ||
return Result.err({ | ||
errors: [ | ||
@@ -40,18 +41,17 @@ { | ||
], | ||
}; | ||
}); | ||
} | ||
visitedNodes.add(positional); | ||
const decoded = await config.type.from(positional.raw); | ||
if (decoded.result === 'error') { | ||
return { | ||
outcome: 'failure', | ||
const decoded = await Result.safeAsync(config.type.from(positional.raw)); | ||
if (Result.isErr(decoded)) { | ||
return Result.err({ | ||
errors: [ | ||
{ | ||
nodes: [positional], | ||
message: decoded.message, | ||
message: decoded.error.message, | ||
}, | ||
], | ||
}; | ||
}); | ||
} | ||
return { outcome: 'success', value: decoded.value }; | ||
return Result.ok(decoded.value); | ||
}, | ||
@@ -58,0 +58,0 @@ }; |
import { ArgParser } from './argparser'; | ||
import { OutputOf } from './from'; | ||
import { Type } from './type'; | ||
import { ProvidesHelp } from './helpdoc'; | ||
declare type RestPositionalsConfig<Decoder extends Type<string, any>> = { | ||
type: Decoder; | ||
displayName?: string; | ||
}; | ||
import { Type, HasType } from './type'; | ||
import { ProvidesHelp, Displayed, Descriptive } from './helpdoc'; | ||
declare type RestPositionalsConfig<Decoder extends Type<string, any>> = HasType<Decoder> & Partial<Displayed & Descriptive>; | ||
/** | ||
@@ -10,0 +7,0 @@ * Read all the positionals and decode them using the type provided. |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const Result = tslib_1.__importStar(require("./Result")); | ||
/** | ||
@@ -11,3 +13,3 @@ * Read all the positionals and decode them using the type provided. | ||
helpTopics() { | ||
var _a, _b, _c; | ||
var _a, _b, _c, _d; | ||
const displayName = (_b = (_a = config.displayName) !== null && _a !== void 0 ? _a : config.type.displayName) !== null && _b !== void 0 ? _b : 'arg'; | ||
@@ -19,3 +21,3 @@ return [ | ||
defaults: [], | ||
description: (_c = config.type.description) !== null && _c !== void 0 ? _c : '', | ||
description: (_d = (_c = config.description) !== null && _c !== void 0 ? _c : config.type.description) !== null && _d !== void 0 ? _d : '', | ||
}, | ||
@@ -31,4 +33,4 @@ ]; | ||
visitedNodes.add(positional); | ||
const decoded = await config.type.from(positional.raw); | ||
if (decoded.result === 'ok') { | ||
const decoded = await Result.safeAsync(config.type.from(positional.raw)); | ||
if (Result.isOk(decoded)) { | ||
results.push(decoded.value); | ||
@@ -39,3 +41,3 @@ } | ||
nodes: [positional], | ||
message: decoded.message, | ||
message: decoded.error.message, | ||
}); | ||
@@ -45,11 +47,7 @@ } | ||
if (errors.length > 0) { | ||
return { | ||
outcome: 'failure', | ||
return Result.err({ | ||
errors, | ||
}; | ||
}); | ||
} | ||
return { | ||
outcome: 'success', | ||
value: results, | ||
}; | ||
return Result.ok(results); | ||
}, | ||
@@ -56,0 +54,0 @@ }; |
@@ -6,2 +6,3 @@ "use strict"; | ||
const errorBox_1 = require("./errorBox"); | ||
const Result_1 = require("./Result"); | ||
async function run(ap, strings) { | ||
@@ -21,4 +22,4 @@ const longOptionKeys = new Set(); | ||
const result = await ap.run({ nodes, visitedNodes: new Set(), hotPath }); | ||
if (result.outcome === 'failure') { | ||
console.error(errorBox_1.errorBox(nodes, result.errors, hotPath)); | ||
if (Result_1.isErr(result)) { | ||
console.error(errorBox_1.errorBox(nodes, result.error.errors, hotPath)); | ||
process.exit(1); | ||
@@ -25,0 +26,0 @@ } |
@@ -7,2 +7,3 @@ "use strict"; | ||
const circuitbreaker_1 = require("./circuitbreaker"); | ||
const Result = tslib_1.__importStar(require("./Result")); | ||
/** | ||
@@ -24,5 +25,5 @@ * Combine multiple `command`s into one | ||
if (cmd) { | ||
return { result: 'ok', value: cmd.cmdName }; | ||
return cmd.cmdName; | ||
} | ||
return { result: 'error', message: 'Not a valid subcommand name' }; | ||
throw new Error('Not a valid subcommand name'); | ||
}, | ||
@@ -78,7 +79,7 @@ }; | ||
const parsed = await subcommand.parse(context); | ||
if (parsed.outcome === 'failure') { | ||
return { | ||
...parsed, | ||
if (Result.isErr(parsed)) { | ||
return Result.err({ | ||
errors: parsed.error.errors, | ||
partialValue: {}, | ||
}; | ||
}); | ||
} | ||
@@ -88,16 +89,15 @@ (_a = context.hotPath) === null || _a === void 0 ? void 0 : _a.push(parsed.value); | ||
const parsedCommand = await cmd.parse(context); | ||
if (parsedCommand.outcome === 'failure') { | ||
return { | ||
outcome: 'failure', | ||
errors: parsedCommand.errors, | ||
if (Result.isErr(parsedCommand)) { | ||
return Result.err({ | ||
errors: parsedCommand.error.errors, | ||
partialValue: { | ||
command: parsed.value, | ||
args: { ...parsedCommand.partialValue }, | ||
args: { ...parsedCommand.error.partialValue }, | ||
}, | ||
}; | ||
}); | ||
} | ||
return { | ||
outcome: 'success', | ||
value: { args: parsedCommand.value, command: parsed.value }, | ||
}; | ||
return Result.ok({ | ||
args: parsedCommand.value, | ||
command: parsed.value, | ||
}); | ||
}, | ||
@@ -107,5 +107,5 @@ async run(context) { | ||
const parsedSubcommand = await subcommand.parse(context); | ||
if (parsedSubcommand.outcome === 'failure') { | ||
if (Result.isErr(parsedSubcommand)) { | ||
const breaker = await circuitbreaker_1.circuitbreaker.parse(context); | ||
if (breaker.outcome === 'success') { | ||
if (Result.isOk(breaker)) { | ||
if (breaker.value === 'help') { | ||
@@ -120,3 +120,3 @@ this.printHelp(context); | ||
} | ||
return { ...parsedSubcommand, partialValue: {} }; | ||
return Result.err({ ...parsedSubcommand.error, partialValue: {} }); | ||
} | ||
@@ -126,15 +126,15 @@ (_a = context.hotPath) === null || _a === void 0 ? void 0 : _a.push(parsedSubcommand.value); | ||
const commandRun = await cmd.run(context); | ||
if (commandRun.outcome === 'success') { | ||
return { | ||
outcome: 'success', | ||
value: { command: parsedSubcommand.value, value: commandRun.value }, | ||
}; | ||
if (Result.isOk(commandRun)) { | ||
return Result.ok({ | ||
command: parsedSubcommand.value, | ||
value: commandRun.value, | ||
}); | ||
} | ||
return { | ||
...commandRun, | ||
return Result.err({ | ||
...commandRun.error, | ||
partialValue: { | ||
command: parsedSubcommand.value, | ||
value: commandRun.partialValue, | ||
value: commandRun.error.partialValue, | ||
}, | ||
}; | ||
}); | ||
}, | ||
@@ -141,0 +141,0 @@ }; |
@@ -48,7 +48,3 @@ "use strict"; | ||
const f1Result = await base.from(a); | ||
if (f1Result.result === 'error') { | ||
return f1Result; | ||
} | ||
const f2Result = await t2From(f1Result.value); | ||
return f2Result; | ||
return await t2From(f1Result); | ||
}, | ||
@@ -55,0 +51,0 @@ }; |
@@ -13,6 +13,6 @@ "use strict"; | ||
if (Number.isNaN(decoded)) { | ||
return { result: 'error', message: 'Not a number' }; | ||
throw new Error('Not a number'); | ||
} | ||
else { | ||
return { result: 'ok', value: decoded }; | ||
return decoded; | ||
} | ||
@@ -19,0 +19,0 @@ }, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const type_1 = require("./type"); | ||
const Result = tslib_1.__importStar(require("./Result")); | ||
/** | ||
@@ -15,9 +17,9 @@ * Take one of the types. Merge the metadata from left to right. | ||
for (const t of ts) { | ||
const decoded = await type_1.fromFn(t)(input); | ||
if (decoded.result === 'ok') { | ||
return decoded; | ||
const decoded = await Result.safeAsync(type_1.fromFn(t)(input)); | ||
if (Result.isOk(decoded)) { | ||
return decoded.value; | ||
} | ||
errors.push(decoded.message); | ||
errors.push(decoded.error.message); | ||
} | ||
return { result: 'error', message: combineErrors(errors) }; | ||
throw new Error(combineErrors(errors)); | ||
}, | ||
@@ -24,0 +26,0 @@ }; |
{ | ||
"name": "cmd-ts", | ||
"version": "0.3.2", | ||
"homepage": "https://clio-ts.now.sh", | ||
"version": "0.4.0", | ||
"homepage": "https://cmd-ts.now.sh", | ||
"license": "MIT", | ||
@@ -15,3 +15,4 @@ "author": "Gal Schlezinger", | ||
"lint": "eslint src/**/*.ts test/**/*.ts", | ||
"now-build": "typedoc --out public", | ||
"// now-build": "typedoc --out public", | ||
"now-build": "mdbook build --dest-dir=public", | ||
"run-example": "yarn --silent ts-node src/example/app.ts", | ||
@@ -47,2 +48,3 @@ "start": "yarn build --watch", | ||
"@typescript-eslint/parser": "^2.23.0", | ||
"cargo-mdbook": "^0.3.5", | ||
"docs-ts": "^0.3.4", | ||
@@ -49,0 +51,0 @@ "eslint": "^6.8.0", |
@@ -89,6 +89,6 @@ # `cmd-ts` | ||
// Here is our error handling! | ||
return { result: 'error', message: 'File not found' }; | ||
throw new Error('File not found'); | ||
} | ||
return { result: 'ok', value: fs.createReadStream(str) }; | ||
return fs.createReadStream(str); | ||
}, | ||
@@ -95,0 +95,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
134520
81
2256
26