import { Command } from 'commander';
import { resolve } from 'node:path';
import { RegistryClient, readCredentials } from '@expxagents/registry-client';
export const publishCommand = new Command('publish')
    .description('Publish a squad to the registry')
    .argument('[dir]', 'Squad directory', '.')
    .option('--version <version>', 'Override version')
    .action(async (dir, options) => {
    const creds = readCredentials();
    if (!creds) {
        console.error('Not logged in. Run: expxagents login');
        process.exit(1);
    }
    const squadDir = resolve(dir);
    const client = new RegistryClient({ registryUrl: creds.registryUrl, apiKey: creds.apiKey });
    try {
        const result = await client.publish(squadDir, options.version);
        console.log(`\u2713 Published ${result.squad?.fullName || 'squad'}@${result.version?.version}`);
    }
    catch (err) {
        console.error(`\u2717 Publish failed: ${err.message}`);
        process.exit(1);
    }
});
