Show correct binary file in help texts

This commit is contained in:
Niklas Keller
2016-03-25 13:29:37 +01:00
parent 9c8d67b2e9
commit 1bc25c738c
2 changed files with 34 additions and 5 deletions

View File

@@ -142,4 +142,31 @@ function getArgumentDescription($argument) {
default:
throw new \InvalidArgumentException("Unknown argument: " . $argument);
}
}
function getBinary() {
$binary = "bin/acme";
if (isPhar()) {
$binary = substr(Phar::running(true), strlen("phar://"));
$path = getenv("PATH");
$locations = explode(PATH_SEPARATOR, $path);
$binaryPath = dirname($binary);
foreach ($locations as $location) {
if ($location === $binaryPath) {
return substr($binary, strlen($binaryPath) + 1);
}
}
$cwd = getcwd();
if ($cwd && strpos($binary, $cwd) === 0) {
$binary = "." . substr($binary, strlen($cwd));
}
}
return $binary;
}