#!/usr/bin/env php
<?php

/**
 * This script is an example of how you can use PowerProcess.
 *
 * Run this file followed by any command, and it will be executed via Power Process.
 *
 * Examples:
 *
 *    ./run git status
 *    ./run ping packagist.org -c 10
 *    ./run cat /etc/os-release
 */

// Include autoloader

function includeIfExists(string $file): bool
{
    return file_exists($file) && include $file;
}

if (
    !includeIfExists(__DIR__ . '/../../autoload.php') &&
    !includeIfExists(__DIR__ . '/vendor/autoload.php') &&
    !includeIfExists(__DIR__ . '/../../../../vendor/autoload.php')
) {
    fwrite(STDERR, 'Dependencies not found. Install with Composer.'.PHP_EOL);
    exit(1);
}

// PowerProcess needs IO.
$input = new \Symfony\Component\Console\Input\ArgvInput($argv);
$output = new \Symfony\Component\Console\Output\ConsoleOutput();

// Replace Style with your own to change the output style.
$io = new DevShop\Component\PowerProcess\PowerProcessStyle($input, $output);

// Load command from everything after the filename.
$command = array_slice($argv, 1);
$process = new DevShop\Component\PowerProcess\PowerProcess($command, $io);
$process->run();
exit($process->getExitCode());
