mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
tools/convert-world: improve error messages and exit codes
die with a string exits with zero? wtf?
This commit is contained in:
parent
05e2bef5ce
commit
43b2e1a0e8
@ -43,29 +43,35 @@ $plainArgs = getopt("", array_map(function(string $str){ return "$str:"; }, arra
|
|||||||
$args = [];
|
$args = [];
|
||||||
foreach($requiredOpts as $opt => $desc){
|
foreach($requiredOpts as $opt => $desc){
|
||||||
if(!isset($plainArgs[$opt]) || !is_string($plainArgs[$opt])){
|
if(!isset($plainArgs[$opt]) || !is_string($plainArgs[$opt])){
|
||||||
die($usageMessage);
|
fwrite(STDERR, $usageMessage);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
$args[$opt] = $plainArgs[$opt];
|
$args[$opt] = $plainArgs[$opt];
|
||||||
}
|
}
|
||||||
if(!array_key_exists($args["format"], $writableFormats)){
|
if(!array_key_exists($args["format"], $writableFormats)){
|
||||||
die($usageMessage);
|
fwrite(STDERR, $usageMessage);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$inputPath = realpath($args["world"]);
|
$inputPath = realpath($args["world"]);
|
||||||
if($inputPath === false){
|
if($inputPath === false){
|
||||||
die("Cannot find input world at location: " . $args["world"]);
|
fwrite(STDERR, "Cannot find input world at location: " . $args["world"] . PHP_EOL);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
$backupPath = realpath($args["backup"]);
|
$backupPath = realpath($args["backup"]);
|
||||||
if($backupPath === false || (!@mkdir($backupPath, 0777, true) and !is_dir($backupPath)) or !is_writable($backupPath)){
|
if($backupPath === false || (!@mkdir($backupPath, 0777, true) and !is_dir($backupPath)) or !is_writable($backupPath)){
|
||||||
die("Backup file path " . $args["backup"] . " is not writable (permission error or doesn't exist), aborting");
|
fwrite(STDERR, "Backup file path " . $args["backup"] . " is not writable (permission error or doesn't exist), aborting" . PHP_EOL);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$oldProviderClasses = $providerManager->getMatchingProviders($inputPath);
|
$oldProviderClasses = $providerManager->getMatchingProviders($inputPath);
|
||||||
if(count($oldProviderClasses) === 0){
|
if(count($oldProviderClasses) === 0){
|
||||||
die("Unknown input world format");
|
fwrite(STDERR, "Unknown input world format" . PHP_EOL);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
if(count($oldProviderClasses) > 1){
|
if(count($oldProviderClasses) > 1){
|
||||||
die("Ambiguous input world format: matched " . count($oldProviderClasses) . " (" . implode(array_keys($oldProviderClasses)) . ")");
|
fwrite(STDERR, "Ambiguous input world format: matched " . count($oldProviderClasses) . " (" . implode(array_keys($oldProviderClasses)) . ")" . PHP_EOL);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
$oldProviderClass = array_shift($oldProviderClasses);
|
$oldProviderClass = array_shift($oldProviderClasses);
|
||||||
$oldProvider = $oldProviderClass->fromPath($inputPath);
|
$oldProvider = $oldProviderClass->fromPath($inputPath);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user