cost-claude
Version:
Claude Code cost monitoring, analytics, and optimization toolkit
76 lines ⢠3.69 kB
JavaScript
import chalk from 'chalk';
import { logger } from '../../utils/logger.js';
import { SyncManager } from '../../services/sync-manager.js';
import { homedir } from 'os';
import { join } from 'path';
export async function syncCommand(options) {
try {
const syncManager = new SyncManager();
const projectPath = options.path?.replace('~', homedir()) || join(homedir(), '.claude/projects');
if (options.list) {
const syncFiles = syncManager.listAvailableSyncs();
if (syncFiles.length === 0) {
console.log(chalk.yellow('No sync files found'));
console.log(chalk.dim('Export data first with: cost-claude sync --export'));
return;
}
console.log(chalk.bold('\nš Available Sync Files:'));
console.log('='.repeat(50));
syncFiles.forEach(file => {
console.log(` ${file}`);
});
console.log(chalk.dim(`\nLocation: ${join(homedir(), '.cost-claude/sync')}`));
return;
}
if (options.export) {
console.log(chalk.blue('Exporting data for sync...'));
const exportPath = await syncManager.exportForSync(projectPath, options.output);
console.log(chalk.green(`ā
Data exported to: ${exportPath}`));
console.log(chalk.dim('Share this file with other machines for syncing'));
return;
}
if (options.import && options.import.length > 0) {
console.log(chalk.blue('Importing and merging data...'));
const mergeOptions = {
strategy: options.strategy || 'newest',
backup: !options.noBackup,
dryRun: options.dryRun || false
};
if (options.dryRun) {
console.log(chalk.yellow('š Running in dry-run mode (no changes will be made)'));
}
const report = await syncManager.importAndMerge(options.import, projectPath, mergeOptions);
console.log('\n' + syncManager.formatSyncReport(report));
if (options.dryRun) {
console.log(chalk.yellow('\nā ļø This was a dry run. Use without --dry-run to apply changes.'));
}
return;
}
if (options.compare) {
console.log(chalk.blue('Comparing local and remote data...'));
await syncManager.compareWithRemote(projectPath, options.compare);
return;
}
console.log(chalk.bold('\nš Claude Cost Checker - Sync Tool'));
console.log('='.repeat(50));
console.log('\nUsage:');
console.log(' Export data: cost-claude sync --export');
console.log(' Import data: cost-claude sync --import <file1> [file2...]');
console.log(' Compare: cost-claude sync --compare <remote-path>');
console.log(' List syncs: cost-claude sync --list');
console.log('\nOptions:');
console.log(' --strategy Conflict resolution: newest, oldest, cost, manual');
console.log(' --dry-run Preview changes without applying them');
console.log(' --no-backup Skip backup when importing');
console.log('\nExample workflow:');
console.log(' 1. On machine A: cost-claude sync --export');
console.log(' 2. Copy the export file to machine B');
console.log(' 3. On machine B: cost-claude sync --import <export-file>');
}
catch (error) {
logger.error('Sync command failed:', error);
console.error(chalk.red('Error:'), error.message);
process.exit(1);
}
}
//# sourceMappingURL=sync.js.map