Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deprecate ExtendedArgument #321

Merged
merged 1 commit into from
Nov 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/lib/structures/ExtendedArgument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { isOk } from '../parsers/Result';
import { Argument, ArgumentContext, ArgumentOptions, ArgumentResult, AsyncArgumentResult, IArgument } from './Argument';

/**
* @deprecated {@link ExtendedArgument} is deprecated and will be removed in v3.0.0.
* Use {@link Argument} instead, and abstract the resolving of the argument data to an external resolver.
* ---
* The extended argument class. This class is abstract and is to be extended by subclasses which
* will implement the {@link ExtendedArgument#handle} method.
* Much like the {@link Argument} class, this class handles parsing user-specified command arguments
Expand Down Expand Up @@ -52,6 +55,9 @@ import { Argument, ArgumentContext, ArgumentOptions, ArgumentResult, AsyncArgume
export abstract class ExtendedArgument<K extends keyof ArgType, T> extends Argument<T> {
public baseArgument: K;

/**
* @deprecated {@link ExtendedArgument} is deprecated and will be removed in v3.0.0.
*/
public constructor(context: PieceContext, options: ExtendedArgumentOptions<K>) {
super(context, options);
this.baseArgument = options.baseArgument;
Expand All @@ -60,11 +66,15 @@ export abstract class ExtendedArgument<K extends keyof ArgType, T> extends Argum
/**
* Represents the underlying argument that transforms the raw argument
* into the value used to compute the extended argument's value.
* @deprecated {@link ExtendedArgument} is deprecated and will be removed in v3.0.0.
*/
public get base(): IArgument<ArgType[K]> {
return this.container.stores.get('arguments').get(this.baseArgument) as IArgument<ArgType[K]>;
}

/**
* @deprecated {@link ExtendedArgument} is deprecated and will be removed in v3.0.0.
*/
public async run(parameter: string, context: ArgumentContext<T>): AsyncArgumentResult<T> {
const result = await this.base.run(parameter, context as unknown as ArgumentContext<ArgType[K]>);
// If the result was successful (i.e. is of type `Ok<ArgType[K]>`), pass its
Expand All @@ -73,9 +83,15 @@ export abstract class ExtendedArgument<K extends keyof ArgType, T> extends Argum
return isOk(result) ? this.handle(result.value, { ...context, parameter }) : result;
}

/**
* @deprecated {@link ExtendedArgument} is deprecated and will be removed in v3.0.0.
*/
public abstract handle(parsed: ArgType[K], context: ExtendedArgumentContext): ArgumentResult<T>;
}

/**
* @deprecated {@link ExtendedArgument} is deprecated and will be removed in v3.0.0.
*/
export interface ExtendedArgumentOptions<K extends keyof ArgType> extends ArgumentOptions {
/**
* The name of the underlying argument whose value is used to compute
Expand All @@ -84,6 +100,9 @@ export interface ExtendedArgumentOptions<K extends keyof ArgType> extends Argume
baseArgument: K;
}

/**
* @deprecated {@link ExtendedArgument} is deprecated and will be removed in v3.0.0.
*/
export interface ExtendedArgumentContext extends ArgumentContext {
/**
* The canonical parameter specified by the user in the command, as
Expand Down