UNPKG

@sudoo/coco

Version:

:ocean: A simple command line tool framework

64 lines (63 loc) 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class Option { constructor(...keys) { this._name = null; this._description = null; this._isBoolean = false; this._isOptional = true; this._keys = keys; } static create(...keys) { return new Option(...keys); } get isBoolean() { return this._isBoolean; } get isValue() { return !this._isBoolean; } get isOptional() { return this._isOptional; } get isRequired() { return !this._isOptional; } get description() { return this._description || ''; } get name() { return this._name || this._keys[0]; } boolean() { this._isBoolean = true; return this; } optional() { this._isOptional = true; return this; } required() { this._isOptional = false; return this; } alias(key, ...keys) { this._keys.push(key, ...keys); return this; } setName(name) { this._name = name; return this; } setDescription(description) { this._description = description; return this; } match(target) { if (this._keys.some((key) => key === target.replace(/-/g, ''))) { return true; } return false; } } exports.Option = Option;