/** * Edit a temporary block of text with $EDITOR (or nano as fallback) * @param string $text The initial text of the document. * @param string $filename The (fake) filename passed to the editor (for syntax highlighting hint). * @return string The edited contents */ public static function edit($text, $filename = '') { $EDITOR = getenv('EDITOR') ?: 'nano'; $tmp = tempnam(sys_get_temp_dir(), "E-") . strtr($filename, '/', '_'); file_put_contents($tmp, $text); passthru("{$EDITOR} {$tmp}"); $result = file_get_contents($tmp); unlink($tmp); return $result; } } // Standard Help Message CLI::help(function () { echo 'Usage: ', CLI::name(), ' [commands]', PHP_EOL, 'Commands:', PHP_EOL; foreach (CLI::commands() as $cmd) { echo "\t", $cmd['name'], ' ', $cmd['params'], PHP_EOL; if ($cmd['description']) { echo "\t\t- ", str_replace("\n", "\n\t\t ", $cmd['description']), PHP_EOL, PHP_EOL; } } }); // Standard Error Message CLI::error(function ($message) { echo 'Error: ', $message, PHP_EOL; });