hdw2
Version:
鸿蒙前端hdc调试工具
47 lines (41 loc) • 1.62 kB
JavaScript
/*
* @Author: tankunpeng
* @Date: 2024-06-26 19:47:35
* @LastEditTime: 2025-08-06 10:22:37
* @LastEditors: tankunpeng
* @Description: 查询映射列表
* Come on, worker!
*/
const shell = require('shelljs');
const chalk = require('chalk');
const { getHdc, printTitle, shellLog } = require('./util');
function list(options = {}, command = {}, logOps = {}) {
const hdc = getHdc();
printTitle('=====>调试端口映射查询<=====', logOps, { beforeLine: true, afterLine: true });
const fportLsCmd = `${hdc} fport ls`;
const fportLsExec = shell.exec(fportLsCmd, { silent: true });
if (fportLsExec.code !== 0) {
shellLog(`${chalk.cyan('查询调试端口映射结果: ')}${chalk.red('失败')}`, logOps, { hideLog: false });
shellLog(
`${chalk.cyan('处理建议: ')}${chalk.yellow(
'查询端口映射列表命令执行失败,请手动执行命令尝试\n命令:' + chalk.green(fportLsCmd)
)}`,
logOps,
{ hideLog: false }
);
shell.exit(1);
}
const fportLsStdout = fportLsExec.stdout;
const isEmpty = fportLsStdout.includes('[Empty]');
if (isEmpty) {
shellLog(chalk.yellow('当前无调试端口映射'), logOps);
if (!logOps.hideLog) {
shell.exit(0);
}
} else {
shellLog(`${chalk.cyan('调试端口映射列表: \n')}${chalk.green(fportLsStdout)}`, logOps);
}
shellLog(`${chalk.cyan('查询调试端口映射结果: ')}${chalk.green('成功')}`, logOps);
return isEmpty ? '' : fportLsStdout;
}
exports.list = list;