ai-expert
Version:
AI Expert CLI - Advanced management system for specialized Claude assistants
123 lines • 4.07 kB
JavaScript
import { Command } from 'commander';
import { execSync } from 'child_process';
import { platform } from 'os';
import chalk from 'chalk';
export function openCommand(storage) {
const open = new Command('open');
open
.description('Open AI Experts directory in file explorer')
.option('-p, --path', 'Show path only')
.action(async (options) => {
try {
const baseDir = storage.getBaseDir();
if (options.path) {
console.log(baseDir);
return;
}
await openDirectory(baseDir);
}
catch (error) {
console.error(chalk.red('❌ Error:'), error.message);
console.log(chalk.gray(`Directory: ${storage.getBaseDir()}`));
}
});
// Subcommands for specific directories
open
.command('experts')
.description('Open experts directory')
.action(async () => {
try {
await openDirectory(storage.getExpertsDir());
}
catch (error) {
console.error(chalk.red('❌ Error:'), error.message);
}
});
open
.command('systems')
.description('Open systems directory')
.action(async () => {
try {
await openDirectory(storage.getSystemsDir());
}
catch (error) {
console.error(chalk.red('❌ Error:'), error.message);
}
});
open
.command('contexts')
.description('Open contexts directory')
.action(async () => {
try {
await openDirectory(storage.getContextsDir());
}
catch (error) {
console.error(chalk.red('❌ Error:'), error.message);
}
});
open
.command('rules')
.description('Open rules directory')
.action(async () => {
try {
await openDirectory(storage.getRulesDir());
}
catch (error) {
console.error(chalk.red('❌ Error:'), error.message);
}
});
return open;
}
async function openDirectory(dir) {
console.log(chalk.cyan(`📁 Opening: ${dir}`));
const os = platform();
let command;
switch (os) {
case 'darwin': // macOS
command = `open "${dir}"`;
break;
case 'win32': // Windows
command = `explorer "${dir}"`;
break;
case 'linux':
// Try xdg-open first, then fallback to specific file managers
const fileManagers = ['xdg-open', 'nautilus', 'dolphin', 'thunar', 'pcmanfm', 'nemo'];
let opened = false;
for (const fm of fileManagers) {
try {
// Check if command exists
execSync(`which ${fm}`, { stdio: 'ignore' });
// Try to open
execSync(`${fm} "${dir}" 2>/dev/null`, { stdio: 'ignore' });
opened = true;
console.log(chalk.green(`✅ Opened with ${fm}`));
break;
}
catch {
// Try next file manager
continue;
}
}
if (!opened) {
console.log(chalk.yellow('Could not detect file manager.'));
console.log(chalk.gray(`Directory location: ${dir}`));
console.log(chalk.gray('Try installing xdg-utils: sudo apt install xdg-utils'));
return;
}
return;
default:
console.log(chalk.yellow(`Unsupported platform: ${os}`));
console.log(chalk.gray(`Directory location: ${dir}`));
return;
}
// Execute command for macOS/Windows
try {
execSync(command, { stdio: 'ignore' });
console.log(chalk.green('✅ Directory opened'));
}
catch (error) {
console.log(chalk.yellow('Could not open directory automatically.'));
console.log(chalk.gray(`Location: ${dir}`));
}
}
//# sourceMappingURL=open.js.map