{"size": 1478, "ext": "js", "max_stars_repo_path": "src/cli/commands/account.js", "max_stars_repo_name": "Giancarl021/azure-tables-query", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/cli/commands/account.js", "max_issues_repo_name": "Giancarl021/azure-tables-query", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/cli/commands/account.js", "max_forks_repo_name": "Giancarl021/azure-tables-query", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.9803921569, "max_line_length": 94, "alphanum_fraction": 0.6136671177}
const input = require('../services/input');
const createCredentialsManager = require('../services/credentials');

const SERVICE_NAME = 'azure-tables-query';
const credentials = createCredentialsManager();

const operations = {
    async list() {
        const accounts = await credentials.list();
        return accounts
            .map(acc => '* ' + acc.account)
            .join('\n');
    },

    async set(args) {
        let [ storageAccountName, storageAccountKey ] = args;

        if (!storageAccountName) {
            storageAccountName = await input('Storage Account Name: ', true);
        }

        if (!storageAccountKey) {
            storageAccountKey = await input('Storage Account Key: ', true);
        }

        await credentials.set(storageAccountName, storageAccountKey);

        return 'Storage Account saved';
    },

    async delete(args) {
        let [ storageAccountName ] = args;

        if (!storageAccountName) {
            storageAccountName = await input('Storage Account Name: ', true);
        }

        const isDeleted = await credentials.remove(storageAccountName);
        
        return isDeleted ? 'Storage Account deleted' : 'This Storage Account does not exists';
    }
};

module.exports = async function (args, flags) {
    const index = args.shift();
    const operation = operations[index];
    if (!operation) {
        return `Operation "${index || ''}" does not exists`;
    }
    return await operation(args, flags);
}