From 506fec6a088b49ebd8103868e78bf1a805a65ca3 Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Thu, 2 Nov 2023 05:08:04 +0000 Subject: [PATCH] fix: catch all `fluentci doctor` errors --- README.md | 2 +- main.ts | 2 +- src/cmd/doctor.ts | 53 ++++++++++++++++++++++++++++++----------------- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 09ad401..ed4813b 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ fluentci # Run the pipeline fluentci --help Usage: fluentci [pipeline] [jobs...] -Version: 0.6.7 +Version: 0.6.8 Description: diff --git a/main.ts b/main.ts index 7f10e82..6cd251f 100644 --- a/main.ts +++ b/main.ts @@ -16,7 +16,7 @@ import doctor from "./src/cmd/doctor.ts"; export async function main() { await new Command() .name("fluentci") - .version("0.6.7") + .version("0.6.8") .description( ` . diff --git a/src/cmd/doctor.ts b/src/cmd/doctor.ts index 5d24f38..5d37e9a 100644 --- a/src/cmd/doctor.ts +++ b/src/cmd/doctor.ts @@ -42,16 +42,21 @@ const verifyGlow = async () => { stderr: "piped", }); - const { stdout, code } = await command.output(); - - if (code !== 0) { + try { + const { stdout, code } = await command.output(); + + if (code !== 0) { + console.log(`${red("[✗]")} Glow (not installed)`); + return false; + } + + console.log( + `${green("[✓]")} Glow (${new TextDecoder().decode(stdout).trimEnd()})` + ); + } catch (_) { console.log(`${red("[✗]")} Glow (not installed)`); return false; } - - console.log( - `${green("[✓]")} Glow (${new TextDecoder().decode(stdout).trimEnd()})` - ); return true; }; @@ -62,17 +67,22 @@ const verifyDeno = async () => { stderr: "piped", }); - const { stdout, code } = await command.output(); + try { + const { stdout, code } = await command.output(); - if (code !== 0) { + if (code !== 0) { + console.log(`${red("[✗]")} Deno (not installed)`); + return false; + } + + const version = new TextDecoder().decode(stdout).split("\n")[0].trimEnd(); + + console.log(`${green("[✓]")} Deno (${version})`); + } catch (_) { console.log(`${red("[✗]")} Deno (not installed)`); return false; } - const version = new TextDecoder().decode(stdout).split("\n")[0].trimEnd(); - - console.log(`${green("[✓]")} Deno (${version})`); - return true; }; @@ -83,17 +93,22 @@ const verifyDagger = async () => { stderr: "piped", }); - const { stdout, code } = await command.output(); + try { + const { stdout, code } = await command.output(); - if (code !== 0) { + if (code !== 0) { + console.log(`${red("[✗]")} Dagger (not installed)`); + return false; + } + + console.log( + `${green("[✓]")} Dagger (${new TextDecoder().decode(stdout).trimEnd()})` + ); + } catch (_) { console.log(`${red("[✗]")} Dagger (not installed)`); return false; } - console.log( - `${green("[✓]")} Dagger (${new TextDecoder().decode(stdout).trimEnd()})` - ); - return true; };