UNPKG

@fromsvenwithlove/devops-issues-cli

Version:

AI-powered CLI tool and library for Azure DevOps work item management with Claude agents

88 lines (73 loc) 2.83 kB
import chalk from 'chalk'; import { getConfig } from '../config/index.js'; import { AzureDevOpsClient } from '../api/azure-client.js'; import { CacheManager } from '../cache/index.js'; export default async function cacheCommand(action = 'status') { try { const config = getConfig(); const cache = new CacheManager(config); switch (action.toLowerCase()) { case 'status': await showCacheStatus(cache); break; case 'clear': await clearCache(cache); break; case 'refresh': await refreshCache(config); break; default: console.error(chalk.red(`Unknown cache action: ${action}`)); console.log('Available actions: status, clear, refresh'); process.exit(1); } } catch (error) { console.error(chalk.red('Error:'), error.message); process.exit(1); } } async function showCacheStatus(cache) { const status = await cache.getCacheStatus(); console.log(chalk.blue('Cache Status')); console.log('━'.repeat(40)); if (!status.exists) { console.log(chalk.yellow('No cache found')); if (status.error) { console.log(chalk.red('Error:'), status.error); } return; } console.log(`Status: ${status.valid ? chalk.green('Valid') : chalk.yellow('Expired/Invalid')}`); console.log(`Root Issue ID: ${chalk.cyan(status.rootIssueId || 'Not set')}`); console.log(`Last Updated: ${chalk.cyan(status.lastUpdated)}`); console.log(`TTL: ${chalk.cyan(status.ttl)} seconds`); console.log(`Work Items: ${chalk.cyan(status.workItemCount)}`); console.log('\nCache Files:'); console.log(` Hierarchy: ${status.files.hierarchy ? chalk.green('✓') : chalk.red('✗')}`); console.log(` Details: ${status.files.details ? chalk.green('✓') : chalk.red('✗')}`); console.log(` Metadata: ${status.files.metadata ? chalk.green('✓') : chalk.red('✗')}`); } async function clearCache(cache) { const result = await cache.clearCache(); if (result.success) { console.log(chalk.green(`Cache cleared successfully. Removed ${result.filesRemoved} file(s).`)); } else { console.error(chalk.red('Failed to clear cache:'), result.error); process.exit(1); } } async function refreshCache(config) { if (!config.rootIssueId) { console.error(chalk.red('Error: Root Issue ID not configured. Set AZ_DEVOPS_ROOT_ISSUE_ID in your .env file.')); process.exit(1); } console.log(chalk.blue('Refreshing cache...')); const client = new AzureDevOpsClient(config); await client.connect(); // Force a fresh fetch by clearing cache first const cache = new CacheManager(config); await cache.clearCache(); // Fetch work items to populate cache await client.getAssignedWorkItems(); console.log(chalk.green('Cache refreshed successfully')); }