"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const error_1 = require("@pnpm/error");
const list_1 = require("@pnpm/list");
async function default_1(args, opts, command) {
    const output = await render([opts.prefix], args, {
        ...opts,
        lockfileDirectory: opts.lockfileDirectory || opts.prefix,
    }, command);
    if (output)
        console.log(output);
}
exports.default = default_1;
async function render(prefixes, args, opts, command) {
    const isWhy = command === 'why';
    if (isWhy && !args.length) {
        throw new error_1.default('MISSING_PACKAGE_NAME', '`pnpm why` requires the package name');
    }
    opts.long = opts.long || command === 'll' || command === 'la';
    const listOpts = {
        alwaysPrintRootPackage: opts.alwaysPrintRootPackage,
        depth: isWhy ? Infinity : opts.depth || 0,
        include: opts.include,
        lockfileDirectory: opts.lockfileDirectory,
        long: opts.long,
        // tslint:disable-next-line: no-unnecessary-type-assertion
        reportAs: (opts.parseable ? 'parseable' : (opts.json ? 'json' : 'tree')),
    };
    return isWhy || args.length
        ? list_1.forPackages(args, prefixes, listOpts)
        : list_1.default(prefixes, listOpts);
}
exports.render = render;
