Show correct binary file in help texts
This commit is contained in:
12
bin/acme
12
bin/acme
@@ -30,8 +30,10 @@ $commands = [
|
|||||||
"revoke",
|
"revoke",
|
||||||
];
|
];
|
||||||
|
|
||||||
$help = implode("\n ", array_map(function ($command) {
|
$binary = \Kelunik\AcmeClient\getBinary();
|
||||||
return "bin/acme {$command}";
|
|
||||||
|
$help = implode("\n ", array_map(function ($command) use ($binary) {
|
||||||
|
return "{$binary} {$command}";
|
||||||
}, $commands));
|
}, $commands));
|
||||||
|
|
||||||
$help = <<<EOT
|
$help = <<<EOT
|
||||||
@@ -90,12 +92,12 @@ try {
|
|||||||
$climate->arguments->parse(array_values($args));
|
$climate->arguments->parse(array_values($args));
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
if (count($argv) === 3 && in_array($argv[2], ["h", "-h", "--help", "help"], true)) {
|
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();
|
$climate->br();
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
} else {
|
} else {
|
||||||
$climate->usage(["bin/acme {$argv[1]}"]);
|
$climate->usage(["{$binary} {$argv[1]}"]);
|
||||||
$climate->br();
|
$climate->br();
|
||||||
|
|
||||||
$climate->error($e->getMessage());
|
$climate->error($e->getMessage());
|
||||||
@@ -128,7 +130,7 @@ Amp\run(function () use ($command, $climate) {
|
|||||||
$exitCode = (yield $command->execute($climate->arguments));
|
$exitCode = (yield $command->execute($climate->arguments));
|
||||||
|
|
||||||
if ($exitCode === null) {
|
if ($exitCode === null) {
|
||||||
$logger->warning("Invalid exit code: null, falling back to 0. Please consider reporting this as bug.");
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
exit($exitCode);
|
exit($exitCode);
|
||||||
|
|||||||
@@ -142,4 +142,31 @@ function getArgumentDescription($argument) {
|
|||||||
default:
|
default:
|
||||||
throw new \InvalidArgumentException("Unknown argument: " . $argument);
|
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;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user