import {CLIOption} from './CLIOption' /** * Non-positional, flag-based CLI option. */ export class FlagOption extends CLIOption { constructor( /** * The long-form flag for this option. * @example --path, --create */ public readonly longFlag?: string, /** * The short-form flag for this option. * @example -p, -c */ public readonly shortFlag?: string, /** * Usage message describing this flag. */ public readonly message?: string, /** * Description of the argument required by this flag. * If this is set, the flag will expect a positional argument to follow as a param. */ public readonly argumentDescription?: string, ) { super() } /** * Get the referential name for this option. * Defaults to the long flag (without the '--'). If this cannot * be found, the short flag (without the '-') is used. * @returns {string} */ getArgumentName(): string { if ( this.longFlag ) { return this.longFlag.replace('--', '') } else if ( this.shortFlag ) { return this.shortFlag.replace('-', '') } throw new Error('Missing either a long- or short-flag for FlagOption.') } }