From 24961dc73419e9e657774fecbe81d2ace999e21d Mon Sep 17 00:00:00 2001 From: cheney Date: Tue, 27 Jan 2026 16:59:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kit/src/index.js | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/kit/src/index.js b/kit/src/index.js index a162516..36c66a9 100644 --- a/kit/src/index.js +++ b/kit/src/index.js @@ -121,11 +121,13 @@ kitcommand.regTo( parser ) // }); -parser.addCmdLine("platform", "平台信息", function (cli) { -// 调用主函数并打印结果 +parser.addCmdLine("platform [-json]", "平台信息", function (cli) { + + + // 调用主函数并打印结果 getAllDeviceInfo().then(info => { console.log('Device Information:'); - var table = [] + let table = [] for ( let k in info.os ){ table.push({ '项' : 'OS ' + k, '值' : info.os[k]}) } @@ -139,18 +141,24 @@ parser.addCmdLine("platform", "平台信息", function (cli) { table.push({ '项' : 'Mem ' + k, '值' : info.memory[k]}) } - console.table(table); - const disks = info.disk; - disks.forEach(disk => { - console.log(`磁盘 ${disk.mount}:`); - console.log(` 总空间: ${(disk.size / 1024 / 1024 / 1024).toFixed(2)} GB`); - console.log(` 已用空间: ${(disk.used / 1024 / 1024 / 1024).toFixed(2)} GB`); - console.log(` 可用空间: ${(disk.available / 1024 / 1024 / 1024).toFixed(2)} GB`); - console.log(` 使用率: ${disk.use}%`); - }); - console.log( JSON.stringify(info, null, 4)); - + if( cli.hasFlag("json") ) { + console.log( JSON.stringify(info, null, 4)); + } else { + console.table(table); + const disks = info.disk; + const diskTable = [] + disks.forEach(disk => { + diskTable.push({ + '盘符' : disk.mount + ,'总空间' : `${(disk.size / 1024 / 1024 / 1024).toFixed(2)} GB` + ,'已用空间' : `${(disk.used / 1024 / 1024 / 1024).toFixed(2)} GB` + ,'可用空间' : `${(disk.available / 1024 / 1024 / 1024).toFixed(2)} GB` + ,'使用率' : `${disk.use}%` + }) + }); + console.table(diskTable); + } }).catch(error => { console.error('Error getting device information:', error); });