Skip to content

Commit

Permalink
Switch to ES2022
Browse files Browse the repository at this point in the history
  • Loading branch information
surol committed Sep 16, 2023
1 parent a22d0ea commit 7fd2ef8
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 34 deletions.
5 changes: 4 additions & 1 deletion src/colors/chalk-color-options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { helpZOptionReader } from '../help/help-option-reader.js';
import { ZOptionError } from '../option-error.js';
import type { ZOption } from '../option.js';
import { SimpleZOptionsParser, simpleZOptionsParser } from '../simple-options-parser.js';
import { SupportedZOptions } from '../supported-options.js';
import { type ChalkZColorConfig } from './chalk-color-config.js';
import { chalkZColorOptions } from './chalk-color-options.js';

Expand Down Expand Up @@ -116,7 +117,9 @@ describe('chalkZColorOptions', () => {
});

it('has help', async () => {
const options = [...asArray(chalkZColorOptions())];
const options = [
...asArray<SupportedZOptions.Map | SupportedZOptions.Provider>(chalkZColorOptions()),
];
const display: MockedFunction<(...args: unknown[]) => void> = jest.fn(noop);

options.push({
Expand Down
5 changes: 3 additions & 2 deletions src/help/help-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ZOption } from '../option.js';
import type { ZOptionMeta } from '../option-meta.js';
import type { ZOption } from '../option.js';

/**
* Configuration for {@link helpZOptionReader help option reader}.
Expand All @@ -22,7 +22,8 @@ export interface ZHelpConfig<TOption extends ZOption = ZOption> {
/**
* Compares two options meta.
*
* By default sorts options by their {@link ZOptionMeta.group group} first, and then - by their keys.
* By default sorts options by their {@link @run-z/optionz!ZOptionMeta.Help#group group} first, and then - by their
* keys.
*
* @param key1 - First option key.
* @param meta1 - First option meta.
Expand Down
2 changes: 1 addition & 1 deletion src/option-location.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from '@jest/globals';
import { ZOptionLocation } from './option-location';
import { ZOptionLocation } from './option-location.js';

describe('ZOptionLocation', () => {
describe('by', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/option-syntax.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from '@jest/globals';
import type { ZOptionInput } from './option-input';
import { ZOptionSyntax } from './option-syntax';
import type { ZOptionInput } from './option-input.js';
import { ZOptionSyntax } from './option-syntax.js';

describe('ZOptionSyntax', () => {
describe('by', () => {
Expand Down
15 changes: 8 additions & 7 deletions src/option-syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import { ZOptionInput } from './option-input.js';
* to be recognized by {@link ZOptionReader option readers}.
*
* A syntax should be {@link ZOptionsParser.Config.syntax registered} for options parser to respect it.
*
* @param args - An array of command line arguments to process.
*
* @returns A read-only array of option inputs. May be empty if the command line argument has another syntax.
*/
export type ZOptionSyntax =
/**
* @param args - An array of command line arguments to process.
*
* @returns A read-only array of option inputs. May be empty if the command line argument has another syntax.
*/
(this: void, args: readonly [string, ...string[]]) => readonly ZOptionInput[];
export type ZOptionSyntax = (
this: void,
args: readonly [string, ...string[]],
) => readonly ZOptionInput[];

/**
* @internal
Expand Down
8 changes: 7 additions & 1 deletion src/options-parser.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ export class ZOptionsParser$<TOption extends ZOption, TCtx> {
): Promise<TCtx> {
const allOptions = supportedZOptionsMap(
context,
asArray(this.#config.options).concat(asArray(options)),
asArray<SupportedZOptions.Map<TOption> | SupportedZOptions.Provider<TOption, TCtx>>(
this.#config.options,
).concat(
asArray<SupportedZOptions.Map<TOption> | SupportedZOptions.Provider<TOption, TCtx>>(
options,
),
),
);
const optionMeta = lazyValue(() => supportedZOptionsMeta(allOptions));
const optionClass = this.optionClass;
Expand Down
26 changes: 12 additions & 14 deletions src/simple-options-parser.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import type { ZOption } from './option.js';
import type { ZOptionSyntax } from './option-syntax.js';
import type { ZOption } from './option.js';
import { customZOptionsParser, ZOptionsParser } from './options-parser.js';
import type { SupportedZOptions } from './supported-options.js';

/**
* Simple command line options parser signature.
*
* @param args - Array of command line arguments
* @param fromIndex - An index of command line argument to start processing from.
* @param opts - Parser options.
*
* @returns A promise resolved to parse result.
*/
export type SimpleZOptionsParser =
/**
* @param args - Array of command line arguments
* @param fromIndex - An index of command line argument to start processing from.
* @param opts - Parser options.
*
* @returns A promise resolved to parse result.
*/
(
this: void,
args: readonly string[],
opts?: ZOptionsParser.Opts,
) => Promise<SimpleZOptionsParser.Result>;
export type SimpleZOptionsParser = (
this: void,
args: readonly string[],
opts?: ZOptionsParser.Opts,
) => Promise<SimpleZOptionsParser.Result>;

export namespace SimpleZOptionsParser {
/**
Expand Down
12 changes: 6 additions & 6 deletions src/supported-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,36 @@ export namespace SupportedZOptions {

/**
* Fallback option reader consulted when none of the readers recognized the option in.
* {@link ZOptionSyntax.longOptions `--name=VALUE` syntax}.
* {@link ZOptionSyntax:var#longOptions `--name=VALUE` syntax}.
*/
readonly '--*=*'?: ZOptionReader<TOption, this> | undefined;

/**
* Fallback option reader consulted when none of the readers recognized the option in
* {@link ZOptionSyntax.longOptions long syntax}.
* {@link ZOptionSyntax:var#longOptions long syntax}.
*/
readonly '--*'?: ZOptionReader<TOption, this> | undefined;

/**
* Fallback option reader consulted when none of the readers recognized the option in
* {@link ZOptionSyntax.shortOptions one-letter syntax}.
* {@link ZOptionSyntax:var#shortOptions one-letter syntax}.
*/
readonly '-?'?: ZOptionReader<TOption, this> | undefined;

/**
* Fallback option reader consulted when none of the readers recognized the option in
* {@link ZOptionSyntax.shortOptions `-name=VALUE` syntax}.
* {@link ZOptionSyntax:var#shortOptions `-name=VALUE` syntax}.
*/
readonly '-*=*'?: ZOptionReader<TOption, this> | undefined;

/**
* Fallback option reader consulted when none of the readers recognized the option in
* {@link ZOptionSyntax.shortOptions short syntax}.
* {@link ZOptionSyntax:var#shortOptions short syntax}.
*/
readonly '-*'?: ZOptionReader<TOption, this> | undefined;

/**
* Fallback option reader consulted when none of the readers the option in {@link ZOptionSyntax.any any syntax}.
* Fallback option reader consulted when none of the readers the option in {@link ZOptionSyntax:var#any any syntax}.
*/
readonly '*'?: ZOptionReader<TOption, this> | undefined;
}
Expand Down

0 comments on commit 7fd2ef8

Please sign in to comment.