export const getMetadata = () => ({
    name: 'uninstall',
    desc: 'Uninstall CLI plugin',
    usage: 'afctl uninstall PLUGIN',
    options: {
        plugin: {
            keys: [],
            type: 'string',
            mandatory: true,
            multiple: false,
            helpLiteral: 'PLUGIN',
            helpText: 'CLI plugin package name',
            index: 0
        }
    }
});

export const getCompletion = ({config}) => {
    const plugins = Object.keys(config.plugins || {});
    if (plugins.length) {
        return plugins;
    }
    return undefined;
};

export const run = async ({ args, config, console }) => {
    if (!config.plugins) {
        console.debug('Initializing plugins configuration');
        config.plugins = {};
    }
    if (!config.plugins[args.plugin]) {
        return [`CLI plugin '${args.plugin}' is not installed`];
    }
    delete config.plugins[args.plugin];
    await config.save();
    return [`CLI plugin '${args.plugin}' successfully uninstalled`];
};
