From 8260a3265ba1a588dc67839673bbbff8213aaa06 Mon Sep 17 00:00:00 2001 From: Jefferson Rylee Date: Fri, 29 Mar 2024 21:29:21 +0800 Subject: [PATCH] Update spec, fix spec error message --- src/core/spec.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/core/spec.ts b/src/core/spec.ts index 4a02f95..a1e6238 100644 --- a/src/core/spec.ts +++ b/src/core/spec.ts @@ -11,7 +11,7 @@ import { Spec, SpecOptions } from './spec.types.js'; * @returns The Spec object. */ export function spec(options?: SpecOptions): Spec { - return _spec(null, normalize(options)); + return _spec(normalize(options)); } function normalize(options: SpecOptions | undefined) { @@ -39,7 +39,7 @@ function normalize(options: SpecOptions | undefined) { // NOTE: always keep reference to _options // direct mutation should be safe since this is internal -function _spec(raw: string | null, _options: Options): Spec { +function _spec(_options: Options, raw: string | null = null): Spec { const _args: { [arg: string]: Options | null | undefined } = Object.create(null); let _curr: { arg: string; options: Options; spec?: Spec } | undefined; @@ -58,7 +58,9 @@ function _spec(raw: string | null, _options: Options): Spec { function current(context: string) { if (!_curr) { - throw error(`Missing \`add()\` call before \`${context}\` call.`); + throw error( + `Requires \`option()\` or \`command()\` call before \`${context}\`.` + ); } return _curr; } @@ -109,7 +111,7 @@ function _spec(raw: string | null, _options: Options): Spec { spec(setup) { // cache spec to curr to reuse for multiple spec calls const curr = current('spec()'); - setup((curr.spec ||= _spec(curr.arg, curr.options))); + setup((curr.spec ||= _spec(curr.options, curr.arg))); return spec; }, aliases(alias) {