import {Command, command, metadata, param} from 'clime';
import Repo from "../lib/repo";
import {$log} from "ts-log-debug";

@command({
    description: 'Add a model to a nest workspace',
})
export default class extends Command {
    @metadata
    async execute(
        @param({
            description: 'Model ID',
            required: true,
        })
            modelID: string,
        @param({
            description: 'Workspace',
            required: false,
            default: 'default',
        })
            workspace: string,

    ) {
        const repo = Repo.findRepo();
        if (repo == null) {
            $log.fatal('not a nest repository (or any of the parent directories): .nest')
        } else {
            const packageVersion = Repo.splitPackageVersion(modelID);
            const version = await repo.add(workspace, packageVersion);
            if (!version) {
                console.log(`Not found.`)
            }
        }
    }
}
