UNPKG

tiny-bin

Version:

A library for building tiny and beautiful command line apps.

26 lines (25 loc) 735 B
/* IMPORT */ import Addon from './addon.js'; /* MAIN */ class Argument extends Addon { /* CONSTRUCTOR */ constructor(bin, options) { super(bin); this.ids = [this.parse(options.name)]; this.name = options.name; this.description = options.description; this.required = (options.name[0] === '<'); this.variadic = options.name.includes('...'); } /* PRIVATE API */ parse(name) { const re = /^\[([^\].]+)(?:\.\.\.)?\]$|^<([^>.]+)(?:\.\.\.)?>$/; const match = re.exec(name); if (!match) this.bin.fail(`Invalid argument: "${name}"`); const id = match[1] || match[2]; return id; } } /* EXPORT */ export default Argument;