import { downloadApplication } from '../srv/download-application.js';
import { getApplicationOrVersionNamesCompletion } from './common/completions.js';

export const getMetadata = () => ({
    name: 'download',
    desc: 'Download the deployed application',
    usage: 'afctl download APPLICATION',
    options: {
        application: {
            keys: [],
            type: 'string',
            mandatory: true,
            multiple: false,
            helpLiteral: 'APPLICATION',
            helpText: 'Name of the deployed application',
            index: 0
        }
    }
});

export const getCompletion = getApplicationOrVersionNamesCompletion({versionCompletion: false});

export const run = async ({ args, config, console, fs, fetch }) => {
    const profile = config?.profiles?.[config?.active_profile];
    const result =  await downloadApplication({ console, profile, fetch, fs, application: args.application });
    return result;
};
