import {Command, command, metadata, param} from 'clime';
import Repo from "../lib/repo";
import {$log} from "ts-log-debug";
const chalk = require('chalk');

@command({
    description: 'Get the status of your local files',
})
export default class extends Command {
    @metadata
    async execute() {
        const repo = Repo.findRepo();
        const statuses = await repo.status();
        const outdated = statuses.filter(value => value.updateAvailable);
        $log.debug(`Status ${outdated}`);
        if (outdated.length > 0) {
            console.log('\nNew versions available:');
            console.log(`  (Use model-nest update <asset>)\n\n`);
            for (var status of outdated) {
                console.log(chalk.green(`      update available: ${status.workspace} ${status.local.name}`));
            }
            console.log('\n');
        } else {
            console.log('\nEverything is up-to-date\n')
        }
    }
}
