#!/usr/bin/env php error("Please run this script as command line script!"); exit(1); } if (count($argv) === 1 || $argv[1] === "-h" || $argv[1] === "--help" || $argv[1] === "help") { print $help; exit(0); } if (!in_array($argv[1], $commands)) { $climate->error("Unknown command: '{$argv[1]}'"); exit(1); } $class = \Kelunik\AcmeClient\commandToClass($argv[1]); $definition = $class::getDefinition(); try { $climate->arguments->add($definition); $climate->arguments->parse(); } catch (Exception $e) { $climate->usage(["bin/acme {$argv[1]}"]); $climate->br(); if (count($argv) !== 3 || !in_array($argv[2], ["-h", "--help", "help"])) { $climate->error($e->getMessage()); } exit(1); } if (posix_geteuid() !== 0) { $climate->error("Please run this script as root!"); exit(1); } $handler = new StreamHandler("php://stdout", Logger::DEBUG); $handler->setFormatter(new ColoredLineFormatter(new LoggerColorScheme, null, null, true, true)); $logger = new Logger("ACME"); $logger->pushHandler($handler); $injector->alias(LoggerInterface::class, Logger::class); $injector->share($logger); $command = $injector->make($class); Amp\run(function () use ($command, $climate, $logger) { try { yield $command->execute($climate->arguments); } catch (Throwable $e) { $error = (string) $e; $lines = explode("\n", $error); $lines = array_filter($lines, function ($line) { return strlen($line) && $line[0] !== "#" && $line !== "Stack trace:"; }); foreach ($lines as $line) { $logger->error($line); } exit(1); } Amp\stop(); });