5 require_once __DIR__
."/Version.php";
10 * Command line arguments
11 * @var pharext\CliArgs
17 * @see \pharext\Command::getArgs()
19 public function getArgs() {
24 * Output pharext vX.Y.Z header
27 printf("pharext v%s (c) Michael Wallner <mike@php.net>\n\n", VERSION
);
32 * @see \pharext\Command::info()
34 public function info($fmt) {
35 if (!$this->args
->quiet
) {
36 vprintf($fmt, array_slice(func_get_args(), 1));
42 * @see \pharext\Command::error()
44 public function error($fmt) {
45 if (!$this->args
->quiet
) {
48 $arg = error_get_last()["message"];
50 $arg = array_slice(func_get_args(), 1);
52 vfprintf(STDERR
, "ERROR: $fmt", $arg);
57 * Output command line help message
60 public function help($prog) {
61 printf("Usage:\n\n \$ %s", $prog);
66 foreach ($this->args
->getSpec() as $spec) {
67 if ($spec[3] & CliArgs
::REQARG
) {
68 if ($spec[3] & CliArgs
::REQUIRED
) {
79 printf(" [-%s]", implode("", array_column($flags, 0)));
81 foreach ($required as $req) {
82 printf(" -%s <arg>", $req[0]);
85 printf(" [-%s <arg>]", implode("|-", array_column($optional, 0)));
88 $spc = $this->args
->getSpec();
89 $max = max(array_map("strlen", array_column($spc, 1)));
91 foreach ($spc as $spec) {
92 if (isset($spec[0])) {
93 printf(" -%s|", $spec[0]);
97 printf("--%s ", $spec[1]);
98 if ($spec[3] & CliArgs
::REQARG
) {
100 } elseif ($spec[3] & CliArgs
::OPTARG
) {
105 printf("%s%s", str_repeat(" ", $max-strlen($spec[1])+
3*!isset($spec[0])), $spec[2]);
106 if ($spec[3] & CliArgs
::REQUIRED
) {
107 printf(" (REQUIRED)");
109 if (isset($spec[4])) {
110 printf(" [%s]", $spec[4]);
118 * Create temporary file/directory name
119 * @param string $prefix
120 * @param string $suffix
122 private function tempname($prefix, $suffix = null) {
123 if (!isset($suffix)) {
126 return sprintf("%s/%s.%s", sys_get_temp_dir(), $prefix, $suffix);