import {Command, command, param} from 'clime';
import Repo from "../lib/repo";
import chalk from "chalk";

@command({
    description: 'Update the specified model',
})
export default class extends Command {
    async execute(
        @param({
            description: 'Workspace',
            required: false,
        })
            workspace: string,
        @param({
            description: 'Asset',
            required: false,
        })
            asset: string,
        ) {
            const repo = Repo.findRepo();
            const statuses = await repo.status();
            const outdated = statuses.filter(value => value.updateAvailable);
            if (outdated.length === 0) {
                console.log('\nEverything is up-to-date\n');
                return;
            }
            const newVersions = await repo.update(workspace, asset);
            for(const version of newVersions) {
                console.log('Updated');
                console.log(chalk.green(`      updated: ${version.workspace} ${version.local.name}`));
            }
    }
}
