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

@@ -30,8 +30,10 @@ $commands = [
"revoke",
];
$help = implode("\n ", array_map(function ($command) {
return "bin/acme {$command}";
$binary = \Kelunik\AcmeClient\getBinary();
$help = implode("\n ", array_map(function ($command) use ($binary) {
return "{$binary} {$command}";
}, $commands));
$help = <<<EOT
@@ -90,12 +92,12 @@ try {
$climate->arguments->parse(array_values($args));
} catch (Exception $e) {
if (count($argv) === 3 && in_array($argv[2], ["h", "-h", "--help", "help"], true)) {
$climate->usage(["bin/acme {$argv[1]}"]);
$climate->usage(["{$binary} {$argv[1]}"]);
$climate->br();
exit(0);
} else {
$climate->usage(["bin/acme {$argv[1]}"]);
$climate->usage(["{$binary} {$argv[1]}"]);
$climate->br();
$climate->error($e->getMessage());
@@ -128,7 +130,7 @@ Amp\run(function () use ($command, $climate) {
$exitCode = (yield $command->execute($climate->arguments));
if ($exitCode === null) {
$logger->warning("Invalid exit code: null, falling back to 0. Please consider reporting this as bug.");
exit(0);
}
exit($exitCode);

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;
}