/** * @file Option * @module kronk/lib/Option */ import Parseable from '#lib/parseable.abstract'; import type { Flags, List, OptionData, OptionEventName, OptionInfo, OptionMetadata, OptionValues } from '@flex-development/kronk'; /** * A command option. * * The `Option` model is used to define the expected options of a command. * * Option flags and argument syntax are tokenized * using the {@linkcode initialOption} construct. * * @see {@linkcode Parseable} * * @class * @extends {Parseable} */ declare class Option extends Parseable { #private; /** * Option metadata. * * @see {@linkcode OptionMetadata} * * @protected * @instance * @override * @member {OptionMetadata} info */ protected info: OptionMetadata; /** * Create a new option. * * @see {@linkcode Flags} * @see {@linkcode OptionInfo} * * @param {Flags | OptionInfo} info * Option flags or info */ constructor(info: Flags | OptionInfo); /** * Create a new option. * * @see {@linkcode Flags} * @see {@linkcode OptionData} * * @param {Flags} flags * Option flags * @param {OptionData | null | undefined} [info] * Additional option data */ constructor(flags: Flags, info?: OptionData | null | undefined); /** * Whether the option is a boolean option. * Boolean options are options that do not take any option-arguments. * * > 👉 **Note**: Options are either boolean, optional, or required. * * @public * @instance * * @return {boolean} * `true` if option is a boolean option, `false` otherwise */ get boolean(): boolean; /** * The event name for the option. * * @see {@linkcode OptionEventName} * * @public * @instance * * @return {OptionEventName} * Option event name */ get event(): OptionEventName; /** * The normalized option flags. * * @see {@linkcode Flags} * * @public * @instance * * @return {Flags} * Option flags */ get flags(): Flags; /** * The option id. * * @public * @instance * * @return {string} * Option id */ get id(): string; /** * The option {@linkcode id} in a format * that can be used an object property key. * * @public * @instance * * @return {string} * Object property key */ get key(): string; /** * The long flag for the option. * * > 👉 **Note**: If `null`, {@linkcode short} will be a non-empty string. * * @public * @instance * * @return {string | null} * Long flag */ get long(): string | null; /** * Whether the option must have a value after parsing. * * @public * @instance * * @return {boolean} * `true` if option must have value after parsing, `false` otherwise */ get mandatory(): boolean; /** * Whether a value is optional when the option is specified. * * @public * @instance * * @return {boolean} * `true` if option-argument is optional, `false` otherwise */ get optional(): boolean; /** * The short flag for the option. * * > 👉 **Note**: If `null`, {@linkcode long} will be a non-empty string. * * @public * @instance * * @return {string | null} * Short flag */ get short(): string | null; /** * Set option names that conflict with this option. * * @see {@linkcode List} * * @public * @instance * * @param {List | string | null | undefined} conflicts * An option name, or list of option names, that conflict with the option * @return {this} * `this` option */ conflicts(conflicts: List | string | null | undefined): this; /** * Get a list of option names that conflict with this option. * * @public * @instance * * @return {Set} * List of conflicting option names */ conflicts(): Set; /** * Set required options. * * @see {@linkcode List} * * @public * @instance * * @param {List | string | null | undefined} depends * An option reference, or list of option references, * that the option depends on * @return {this} * `this` option */ depends(depends: List | string | null | undefined): this; /** * Get a list of required options. * * @public * @instance * * @return {Set} * The list of required options */ depends(): Set; /** * Set the environment variables to check for the value of the option. * * @see {@linkcode List} * * @public * @instance * * @param {List | string | null | undefined} env * The name of the environment variable to check, * or a list of names, in order of priority, to check * @return {this} * `this` option */ env(env: List | string | null | undefined): this; /** * Get a list of environment variables to check for the value of the option. * * @public * @instance * * @return {Set} * Environment variable names */ env(): Set; /** * Set implied option values. * * Implied option values are values that are set on other options when `this` * option is passed, but the implied option is not. * * Lone keys (string `implies`) imply `true`, i.e. `{ [implies]: true }`. * * The option-argument {@linkcode parser} will be called for implied values * that are strings and string arrays. * * @see {@linkcode OptionValues} * * @public * @instance * * @param {OptionValues | string | null | undefined} implies * The key of an implied option, or a map where each key * is an implied option key and each value is the value to use * when the option is set but the implied option is not * @return {this} * `this` option */ implies(implies: OptionValues | string | null | undefined): this; /** * Get implied option values. * * @see {@linkcode OptionValues} * * @public * @instance * * @template {OptionValues} T * Implied option values * * @return {T} * Map of implied option values */ implies(): T; /** * Specify if the option is mandatory. * * Mandatory options must have a value after parsing, which usually means the * option must be specified on the command line. * * > 👉 **Note**: This method is a no-op if mandatory option syntax was used * > when defining option flags (i.e. `new Option('--token ')`). * * @public * @instance * * @param {boolean | null | undefined} [mandatory=true] * Whether the option must have a value after parsing * @return {this} * `this` option */ mandate(mandatory?: boolean | null | undefined): this; /** * Set the preset to use when the option is specified without an argument. * * The handler used to parse option-arguments, {@linkcode ParseArg}, will be * called. * * @public * @instance * * @param {string | null | undefined} preset * The option-argument preset * @return {this} * `this` option */ preset(preset: string | null | undefined): this; /** * Get the preset to use when the option is specified without an argument. * * @public * @instance * * @template {string} T * Option-argument preset * * @return {string | null} * The option-argument preset */ preset(): T | null; /** * Get the option as a human-readable string. * * @public * @instance * * @return {string} * String representation of `this` option */ toString(): string; /** * Parse long and short flags from {@linkcode info.flags}. * * @see {@linkcode KronkError} * * @protected * @instance * * @return {undefined} * @throws {KronkError} * If any flags are invalid or no flags are found */ protected tokenizeFlags(): undefined; } export default Option;