function _run()

in common/scripts/install-run-rush.js [158:210]


function _run() {
    const [nodePath /* Ex: /bin/node */, scriptPath /* /repo/common/scripts/install-run-rush.js */, ...packageBinArgs /* [build, --to, myproject] */] = process.argv;
    // Detect if this script was directly invoked, or if the install-run-rushx script was invokved to select the
    // appropriate binary inside the rush package to run
    const scriptName = path__WEBPACK_IMPORTED_MODULE_0__.basename(scriptPath);
    const bin = _getBin(scriptName);
    if (!nodePath || !scriptPath) {
        throw new Error('Unexpected exception: could not detect node path or script path');
    }
    let commandFound = false;
    let logger = { info: console.log, error: console.error };
    for (const arg of packageBinArgs) {
        if (arg === '-q' || arg === '--quiet') {
            // The -q/--quiet flag is supported by both `rush` and `rushx`, and will suppress
            // any normal informational/diagnostic information printed during startup.
            //
            // To maintain the same user experience, the install-run* scripts pass along this
            // flag but also use it to suppress any diagnostic information normally printed
            // to stdout.
            logger = {
                info: () => { },
                error: console.error
            };
        }
        else if (!arg.startsWith('-') || arg === '-h' || arg === '--help') {
            // We either found something that looks like a command (i.e. - doesn't start with a "-"),
            // or we found the -h/--help flag, which can be run without a command
            commandFound = true;
        }
    }
    if (!commandFound) {
        console.log(`Usage: ${scriptName} <command> [args...]`);
        if (scriptName === 'install-run-rush-pnpm.js') {
            console.log(`Example: ${scriptName} pnpm-command`);
        }
        else if (scriptName === 'install-run-rush.js') {
            console.log(`Example: ${scriptName} build --to myproject`);
        }
        else {
            console.log(`Example: ${scriptName} custom-command`);
        }
        process.exit(1);
    }
    runWithErrorAndStatusCode(logger, () => {
        const version = _getRushVersion(logger);
        logger.info(`The ${RUSH_JSON_FILENAME} configuration requests Rush version ${version}`);
        const lockFilePath = process.env[INSTALL_RUN_RUSH_LOCKFILE_PATH_VARIABLE];
        if (lockFilePath) {
            logger.info(`Found ${INSTALL_RUN_RUSH_LOCKFILE_PATH_VARIABLE}="${lockFilePath}", installing with lockfile.`);
        }
        return installAndRun(logger, PACKAGE_NAME, version, bin, packageBinArgs, lockFilePath);
    });
}