From c305e1e62c439dc5ae26d7e3f84c7d2b88647f69 Mon Sep 17 00:00:00 2001 From: KevinNitroG Date: Wed, 11 Dec 2024 09:59:20 +0700 Subject: [PATCH] fix: hide desc by default --- docs/README.md | 19 +++++++++---------- src/index.ts | 2 +- src/modules/commander.ts | 5 +++-- src/modules/processInfo.ts | 12 +++++++----- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/docs/README.md b/docs/README.md index 1641b2b..c2f535c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -37,7 +37,7 @@ Check battery health for Windows > [!IMPORTANT] > Require [NodeJS](https://nodejs.org/en/download/) -```bash +```sh # Install via npm npm i -g win-check-bat win-check-bat @@ -64,12 +64,10 @@ $ win-check-bat ├─────────────────┼───────────────────────┼────────┼───────────┤ │ 54,000 mWh │ 49,680 mWh │ 92% │ Excellent │ └─────────────────┴───────────────────────┴────────┴───────────┘ - -The battery is in optimal condition, exhibiting minimal degradation and maintaining near-peak performance. It retains most of its original capacity. ``` ``` -$ win-check-bat -l +$ win-check-bat --line --description Design capacity: 54,000 mWh Full charged capacity: 49,680 mWh @@ -86,14 +84,15 @@ Usage: win-check-bat [options] check battery health for Windows Options: - --no-status don't print out the status and description + --no-status don't print out the status + -d, --description show silly description -l, --line print line by line -p, --precise-health calculate precise health (not round) -o, --open-html open HTML exported file - -T, --open-html-timeout open HTML timeout (s) before deleting temp - file. Increase if your browser cannot open - soon enough before open HTML file. - (default: "1") + -t, --open-html-timeout open HTML timeout (s) before deleting + temp file. Increase if your browser + cannot open soon enough before open + HTML file. (default: "1") -h, --help display help for command ``` @@ -101,7 +100,7 @@ Options: ## DEV -```bash +```sh npm i npm run dev -- -- -- -t -p -o ``` diff --git a/src/index.ts b/src/index.ts index 2d90950..f949eaf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,7 +24,7 @@ async function init(): Promise { } catch (e) { console.error(`Fail to process info: ${e}`); } - if (options.openHtml) { + if (options.openHtml as boolean | string) { await open(tempFile); await sleep(options.openHtmlTimeout * 1000); } diff --git a/src/modules/commander.ts b/src/modules/commander.ts index 23a6b1a..8a9f86a 100644 --- a/src/modules/commander.ts +++ b/src/modules/commander.ts @@ -3,12 +3,13 @@ import { OptionValues, program } from 'commander'; program .name('win-check-bat') .description('check battery health for Windows') - .option('--no-status', "don't print out the status and description") + .option('--no-status', "don't print out the status") + .option('-d, --description', 'show silly description') .option('-l, --line', 'print line by line') .option('-p, --precise-health', 'calculate precise health (not round)') .option('-o, --open-html', 'open HTML exported file') .option( - '-T, --open-html-timeout ', + '-t, --open-html-timeout ', 'open HTML timeout (s) before deleting temp file. Increase if your browser cannot open soon enough before open HTML file.', '1', ); diff --git a/src/modules/processInfo.ts b/src/modules/processInfo.ts index 6b9c1c8..43c75a8 100644 --- a/src/modules/processInfo.ts +++ b/src/modules/processInfo.ts @@ -46,7 +46,7 @@ class ProcessInfo { const fullChargedNum: number = ProcessInfo.#extractCapacityNumber(fullCharged); let health: number = (fullChargedNum / designNum) * 100; - if (options.preciseHealth) { + if (options.preciseHealth as boolean | string) { health = Math.round(health); } const status: Status = getStatus(health); @@ -57,8 +57,10 @@ class ProcessInfo { console.log(`Design capacity: ${this.#info.design}`); console.log(`Full charged capacity: ${this.#info.fullCharged}`); console.log(`Battery health: ${this.#info.health}%`); - if (options.status) { + if (options.status as boolean | string) { console.log(`Status: ${this.#info.status}`); + } + if (options.description as boolean | string) { console.log(`Description: ${getStatusDesc(this.#info.status)}`); } } @@ -80,7 +82,7 @@ class ProcessInfo { color: getStatusColor(this.#info.status), }, ], - disabledColumns: [!options.status ? 'status' : ''], + disabledColumns: [(!options.status as boolean | string) ? 'status' : ''], }); table.addRow({ design: this.#info.design, @@ -90,13 +92,13 @@ class ProcessInfo { }); table.printTable(); console.log(); - if (options.status) { + if (options.description as boolean | string) { console.log(getStatusDesc(this.#info.status)); } } printInfo(): void { - if (options.line) { + if (options.line as boolean | string) { this.#printInfoLineByLine(); } else { this.#printInfoTable();