<commit_before>var utils = require('../utils'),
    logger = require('../logger'),
    repository = require('../repository'),
    argParse = require('../args').parse,
    url = require('url'),
    urlParse = url.parse,
    urlFormat = url.format;


exports.summary = 'Remove a published package from a repository';

exports.usage = '' +
'kanso unpublish PACKAGE[@VERSION]\n' +
'\n' +
'Parameters:\n' +
'  PACKAGE       Package name to unpublish\n' +
'  VERSION       Package version to unpublish, if no version is specified\n' +
'                all versions of the package are removed\n' +
'\n' +
'Options:\n' +
'  --repo    Target repository URL (otherwise uses "default" in kansorc)';


exports.run = function (settings, args) {
    var a = argParse(args, {
        'repo': {match: '--repo', value: true},
        'force': {match: ['--force', '-f']}
    });
    var repo = a.options.repo || settings.repositories[0];

    var name = a.positional[0];
    var version;

    if (!name) {
        return logger.error('No package name specified');
    }
    if (name.indexOf('@') !== -1) {
        var parts = name.split('@');
        name = parts[0];
        version = parts.slice(1).join('@');
    }

    exports.unpublish(repo, name, version, a.options, function (err) {
        if (err) {
            return logger.error(err);
        }
        logger.end();
    });
};


exports.unpublish = function (repo, name, version, options, callback) {
    var parsed = urlParse(repo);
    // if only a username has been specified, ask for password
    if (parsed.auth && parsed.auth.split(':').length === 1) {
        utils.getPassword(function (err, password) {
            delete parsed.host;
            parsed.auth += ':' + encodeURIComponent(password);
            repo = urlFormat(parsed);
            exports.unpublish(repo, name, version, options, callback);
        });
        return;
    }
    repository.unpublish(repo, name, version, options, function (err) {
        if (err && err.response && err.response.statusCode === 401) {
            logger.error(err);
            utils.getAuth(repo, function (err, new_repo) {
                if (err) {
                    return callback(err);
                }
                exports.unpublish(new_repo, name, version, options, callback);
            });
            return;
        }
        else {
            callback(err);
        }
    });
};<commit_msg>update unpublish command to use new auth utils<commit_after>var utils = require('../utils'),
    logger = require('../logger'),
    repository = require('../repository'),
    argParse = require('../args').parse,
    url = require('url'),
    urlParse = url.parse,
    urlFormat = url.format;


exports.summary = 'Remove a published package from a repository';

exports.usage = '' +
'kanso unpublish PACKAGE[@VERSION]\n' +
'\n' +
'Parameters:\n' +
'  PACKAGE       Package name to unpublish\n' +
'  VERSION       Package version to unpublish, if no version is specified\n' +
'                all versions of the package are removed\n' +
'\n' +
'Options:\n' +
'  --repo    Target repository URL (otherwise uses "default" in kansorc)';


exports.run = function (settings, args) {
    var a = argParse(args, {
        'repo': {match: '--repo', value: true},
        'force': {match: ['--force', '-f']}
    });
    var repo = a.options.repo || settings.repositories[0];

    var name = a.positional[0];
    var version;

    if (!name) {
        return logger.error('No package name specified');
    }
    if (name.indexOf('@') !== -1) {
        var parts = name.split('@');
        name = parts[0];
        version = parts.slice(1).join('@');
    }

    utils.completeAuth(repo, true, function (err, repo) {
        if (err) {
            return logger.error(err);
        }
        utils.catchAuthError(
            repository.unpublish, repo, [name, version, a.options],
            function (err) {
                if (err) {
                    return logger.error(err);
                }
                logger.end();
            }
        );
    });
};
{'fraction_non_alphanumeric': 0.15638062453897222, 'fraction_numerical': 0.0034423407917383822, 'mean_word_length': 2.114854517611026, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4860206', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1183, 'n_words': 315}