UNPKG

alia

Version:
59 lines (58 loc) 1.57 kB
import logger from '../utils/logger.js'; import { Flag } from './flag.js'; export class ListFlag extends Flag { #alias = this.confService.alias; #aliaKeys = this.confService.keys; #jsonFormat = false; flag = { key: 'list', short: 'l', desc: 'list available alias', run: () => this.#list() }; mods = [ { key: 'sort', short: 's', desc: 'sort alphabetically', run: () => this.#sort() }, { key: 'json', short: 'j', desc: 'list alias info as json', run: () => this.#json() }, { key: 'filter', short: 'f', desc: 'filter alias list', run: (args) => this.#filter(args) } ]; #sort() { this.#aliaKeys = this.#aliaKeys.sort(); return true; } #json() { this.#jsonFormat = true; return true; } #filter(data) { this.#aliaKeys = this.#aliaKeys.filter((a) => data.includes(a)); return true; } #list() { if (this.#jsonFormat) { const alias = this.#aliaKeys.reduce((acc, val) => { acc[val] = this.#alias[val]; return acc; }, {}); logger.info(JSON.stringify(alias, null, 2)); return true; } const list = this.#aliaKeys.map((key) => `${key} \t=> \t${this.#alias[key].command.join(' ')}`).join('\n'); logger.info(list); return true; } }