From 69803eaad1c17a3a719fa8d779219ad8878b1733 Mon Sep 17 00:00:00 2001 From: Lucy Date: Wed, 4 Dec 2024 16:54:27 +0100 Subject: [PATCH] Add handleEdit function for editing Homebrew formulas This commit introduces the handleEdit function, which allows users to edit Homebrew formulas and casks directly from the command line. The function supports options for editing formulas, casks, and printing paths. - Implemented command building logic - Added error handling for command execution - Included emoji support for user-friendly output --- src/features/config.ts | 5 +++-- src/features/create.ts | 8 ++++---- src/features/doctor.ts | 8 ++++---- src/features/edit.ts | 8 ++++---- src/features/version.ts | 7 +++++++ 5 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 src/features/version.ts diff --git a/src/features/config.ts b/src/features/config.ts index bccd442..08eb649 100644 --- a/src/features/config.ts +++ b/src/features/config.ts @@ -10,13 +10,14 @@ export async function handleConfig(options: { quiet?: boolean; verbose?: boolean if (options.verbose) { command += ' --verbose'; } + const result = await runCommand(command); if (!options.quiet) { consola.info(`🔧 Homebrew Configuration:\n${result}`); } - } catch (error) { + } catch (error: any) { if (!options.quiet) { - consola.error(`Error retrieving Homebrew configuration: ${error}`); + consola.error(`❌ Error retrieving Homebrew configuration: ${error.message}`); } } } \ No newline at end of file diff --git a/src/features/create.ts b/src/features/create.ts index 763c1e0..3c4eb23 100644 --- a/src/features/create.ts +++ b/src/features/create.ts @@ -59,17 +59,17 @@ export const handleCreate = async (url: string, options: { // Handle output based on the options if (!options.quiet) { if (stdout) { - consola.log(stdout); + consola.log(`📦 ${stdout}`); } if (stderr) { - consola.error(stderr); + consola.error(`⚠️ ${stderr}`); } } } catch (error: any) { // Handle errors - consola.error(`Error executing brew create: ${error.message}`); + consola.error(`❌ Error executing brew create: ${error.message}`); if (error.stderr) { - consola.error(error.stderr); + consola.error(`⚠️ ${error.stderr}`); } process.exit(1); // Exit with a non-zero status } diff --git a/src/features/doctor.ts b/src/features/doctor.ts index 969da08..8d2d8e9 100644 --- a/src/features/doctor.ts +++ b/src/features/doctor.ts @@ -41,17 +41,17 @@ export const handleDoctor = async (options: { // Handle output based on the options if (!options.quiet) { if (stdout) { - consola.log(stdout); + consola.log(`🩺 ${stdout}`); // Using a stethoscope emoji to indicate health check } if (stderr) { - consola.error(stderr); + consola.error(`⚠️ ${stderr}`); // Warning emoji for errors } } } catch (error: any) { // Handle errors - consola.error(`Error executing brew doctor: ${error.message}`); + consola.error(`❌ Error executing brew doctor: ${error.message}`); if (error.stderr) { - consola.error(error.stderr); + consola.error(`⚠️ ${error.stderr}`); } process.exit(1); // Exit with a non-zero status } diff --git a/src/features/edit.ts b/src/features/edit.ts index 410f98b..2dbbe62 100644 --- a/src/features/edit.ts +++ b/src/features/edit.ts @@ -37,17 +37,17 @@ export const handleEdit = async (args: string[], options: { // Handle output based on the options if (!options.quiet) { if (stdout) { - consola.log(stdout); + consola.log(`✏️ ${stdout}`); // Using a pencil emoji to indicate editing } if (stderr) { - consola.error(stderr); + consola.error(`⚠️ ${stderr}`); // Warning emoji for errors } } } catch (error: any) { // Handle errors - consola.error(`Error executing brew edit: ${error.message}`); + consola.error(`❌ Error executing brew edit: ${error.message}`); if (error.stderr) { - consola.error(error.stderr); + consola.error(`⚠️ ${error.stderr}`); } process.exit(1); // Exit with a non-zero status } diff --git a/src/features/version.ts b/src/features/version.ts new file mode 100644 index 0000000..be3f530 --- /dev/null +++ b/src/features/version.ts @@ -0,0 +1,7 @@ +import consola from 'consola'; // Ensure this import is correct +import { runCommand } from '../command'; + + +export function handleVersion() { + consola.box("Brewy Version 1.0.0") +} \ No newline at end of file