import ora from 'ora'; import util from 'util'; import { pick } from 'lodash'; import postLog from '../service/post.log'; import logger from '../utils/logger'; import { getConfigByRunEnv, setCliConfig } from '../service/config'; /** * cli配置 */ export default function registerConfigCommand(program) { const child = program.command('config').description('工具初始化配置'); child .command('set') .description('工具初始化配置') .option('-i, --tool-id ', '工具的id') .option('-k, --private-key ', '工具密钥') .option('--proxy ', '代理地址') .action(function (options) { // 每次命令,都记录一次日志 postLog({ action: 'CONFIG_SET', }); const params = pick(options, ['toolId', 'privateKey', 'proxy']); setCliConfig(params); const spinner = ora().start(); spinner.succeed(`工具配置成功,查看当前配置可输入: alipaydev config list`); }); child .command('list') .description('展示工具配置信息') .action(async function () { const action = 'CONFIG_LIST'; postLog({ action, }); try { const res = await getConfigByRunEnv(); console.log( util.inspect(res, { depth: 3, }) ); } catch (e) { logger.error(e, { action, }); } }); }