alia
Version:
Alias To Go
69 lines (68 loc) • 1.88 kB
JavaScript
import logger from '../utils/logger.js';
import { Flag } from './flag.js';
import { toBool } from '../utils/to-bool.js';
export class ConfFlag extends Flag {
flag = {
key: 'conf',
short: 'c',
desc: 'alia config (must specify an option)'
};
mods = [
{
key: 'shell',
short: 'sh',
desc: 'set global shell mode',
run: (args) => this.#setShell(args)
},
{
key: 'token',
short: 't',
desc: 'set the personal access token for gist sync',
run: (args) => this.#setToken(args)
},
{
key: 'gist',
short: 'g',
desc: 'set the gist id to use for sync',
run: (args) => this.#setGist(args)
},
{
key: 'path',
short: 'p',
desc: 'show config file path',
run: () => this.#showPath()
}
];
#setGist(args) {
if (!args[0]) {
logger.info('must specify a gist id');
return false;
}
this.confService.gistId = args[0];
logger.set('gist', this.confService.gistId);
return true;
}
#setToken(args) {
if (!args[0]) {
logger.info('must specify a token');
return false;
}
this.confService.token = args[0];
logger.set('token', this.confService.token);
return true;
}
#setShell(args) {
const shell = toBool(args);
if (shell === undefined) {
logger.info(`invalid value for shell flag: ${args[0]}`);
return false;
}
this.confService.shell = shell;
logger.set('shell', this.confService.shell);
return true;
}
#showPath() {
logger.info(this.confService.filePath);
return true;
}
}