mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-12 12:54:07 -07:00
refactor(editor): extract command construction to shared function
Extract the platform-specific command construction into getCommandExistsCmd() to avoid duplication between commandExists and commandExistsAsync.
This commit is contained in:
@@ -76,12 +76,15 @@ interface DiffCommand {
|
|||||||
|
|
||||||
const execAsync = promisify(exec);
|
const execAsync = promisify(exec);
|
||||||
|
|
||||||
|
function getCommandExistsCmd(cmd: string): string {
|
||||||
|
return process.platform === 'win32'
|
||||||
|
? `where.exe ${cmd}`
|
||||||
|
: `command -v ${cmd}`;
|
||||||
|
}
|
||||||
|
|
||||||
function commandExists(cmd: string): boolean {
|
function commandExists(cmd: string): boolean {
|
||||||
try {
|
try {
|
||||||
execSync(
|
execSync(getCommandExistsCmd(cmd), { stdio: 'ignore' });
|
||||||
process.platform === 'win32' ? `where.exe ${cmd}` : `command -v ${cmd}`,
|
|
||||||
{ stdio: 'ignore' },
|
|
||||||
);
|
|
||||||
return true;
|
return true;
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
@@ -90,9 +93,7 @@ function commandExists(cmd: string): boolean {
|
|||||||
|
|
||||||
async function commandExistsAsync(cmd: string): Promise<boolean> {
|
async function commandExistsAsync(cmd: string): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
await execAsync(
|
await execAsync(getCommandExistsCmd(cmd));
|
||||||
process.platform === 'win32' ? `where.exe ${cmd}` : `command -v ${cmd}`,
|
|
||||||
);
|
|
||||||
return true;
|
return true;
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user