diff --git a/src/command.ts b/src/command.ts index d3ccf10..3db675f 100644 --- a/src/command.ts +++ b/src/command.ts @@ -8,8 +8,7 @@ export function runCommand(command: string, options?: { cwd?: string }): Promise consola.error(`❌ Error executing command: "${command}"\n${stderr}`); reject(`Error: ${stderr}`); } else { - consola.success(`✅ Command executed successfully: "${command}"`); - // Convert stdout to string and trim it + // consola.success(`✅ Command executed successfully: "${command}"`); resolve(stdout.toString().trim()); } }); diff --git a/src/features/search.ts b/src/features/search.ts index 5315ed1..842374b 100644 --- a/src/features/search.ts +++ b/src/features/search.ts @@ -1,3 +1,4 @@ +import ora from "ora"; import { runCommand } from "../command"; import { consola } from "consola"; @@ -38,9 +39,14 @@ export async function searchPackage({ term, options }: { term: string; options: command += ' --quiet'; } + const spinner = ora('🔍 Searching...').start(); const result = await runCommand(command); if (!options.quiet) { - consola.info(`📦 Search results for "${term}":\n${result}`); + const formattedResults = result.split('\n').map(line => line.trim()).filter(line => line); + console.log("\n"); + formattedResults.forEach(line => { + consola.info(`📦 ${line}`); + }); } } catch (error: any) { consola.error(`❌ Error searching for package "${term}": ${error.message}`); diff --git a/src/features/services.ts b/src/features/services.ts new file mode 100644 index 0000000..e16b032 --- /dev/null +++ b/src/features/services.ts @@ -0,0 +1,50 @@ +import { runCommand } from "../command"; // Assuming runCommand is a function that executes shell commands +import { consola } from "consola"; +import ora from "ora"; + +interface ServiceOptions { + all?: boolean; + json?: boolean; + debug?: boolean; + quiet?: boolean; + verbose?: boolean; + file?: string; + serviceUser ?: string; + maxWait?: number; + noWait?: boolean; +} + +export async function handleServices(subcommand: string, formula?: string, options?: ServiceOptions) { + const spinner = ora(`🔄 Executing brew services ${subcommand}...`).start(); // Start spinner with emoji + + try { + let command = `brew services ${subcommand}`; + + // Handle options + if (options) { + if (options.all) command += ' --all'; + if (options.json) command += ' --json'; + if (options.debug) command += ' --debug'; + if (options.quiet) command += ' --quiet'; + if (options.verbose) command += ' --verbose'; + if (options.file) command += ` --file=${options.file}`; + if (options.serviceUser ) command += ` --sudo-service-user=${options.serviceUser }`; + if (options.maxWait !== undefined) command += ` --max-wait=${options.maxWait}`; + if (options.noWait) command += ' --no-wait'; + } + + if (formula) { + command += ` ${formula}`; + } + + const result = await runCommand(command); + spinner.succeed(`✅ Successfully executed: ${command}`); // Success message with emoji + + // Output the result + if (!options?.quiet) { + consola.info(`📜 ${result}`); // Output result with an emoji + } + } catch (error: any) { + spinner.fail(`❌ Error executing brew services ${subcommand}: ${error.message}`); // Error message with emoji + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 32bb564..5fa0d90 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,7 @@ import { handleConfig } from './features/config'; import { handleCreate } from './features/create'; import { handleEdit } from './features/edit'; import { handleVersion } from './features/version'; +import { handleServices } from './features/services'; const program = new Command(); program @@ -141,6 +142,22 @@ program.command('uninstall ') handleVersion(); }); + program + .command('services [formula]') + .description('Manage background services with Homebrew') + .option('-a, --all', 'Run subcommand on all services') + .option('--json', 'Output as JSON') + .option('-d, --debug', 'Display any debugging information') + .option('-q, --quiet', 'Make some output more quiet') + .option('-v, --verbose', 'Make some output more verbose') + .option('--file ', 'Use the service file from this location to start the service') + .option('--sudo-service-user ', 'When run as root on macOS, run the service(s) as this user') + .option('--max-wait ', 'Wait at most this many seconds for stop to finish stopping a service') + .option('--no-wait', 'Don\'t wait for stop to finish stopping the service') + .action(async (subcommand, formula, options) => { + await handleServices(subcommand, formula, options); + }); + program.parse(process.argv);