import { Type } from "https://deno.land/x/cliffy@v1.0.0-rc.1/command/type.ts";
import { Type } from "https://deno.land/x/cliffy@v1.0.0-rc.1/command/type.ts";
Base class for custom types.
Custom type example:
import { Type, ArgumentValue } from "./mod.ts";
export class ColorType extends Type<string> {
public parse({ label, name, value, type }: ArgumentValue): string {
if (["red", "blue"].includes(value)) {
throw new Error(
`${label} "${name}" must be of type "${type}", but got "${value}".` +
"Valid colors are: red, blue"
);
}
return value;
}
public complete(): string[] {
return ["red", "blue"];
}
}
Methods
optional
complete(cmd: Command, parent?: Command): CompleteHandlerResultReturns shell completion values. If no complete method is provided, values from the values method are used.
abstract
parse(type: ArgumentValue): TValueoptional
values(cmd: Command, parent?: Command): ValuesHandlerResultReturns values displayed in help text. If no complete method is provided, these values are also used for shell completions.