Commit 31d436d0 authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #671 in ZP/z-push from...

Merge pull request #671 in ZP/z-push from bugfix/ZP-1291-cli-tools-should-exit-with-0-if-called-with-help to develop

* commit '0ca4275a':
  ZP-1291 Exit with 0 if gab2contacts called with help.
  ZP-1291 Exit with 0 if gab-sync called with help.
  ZP-1291 Exit with 0 if z-push-top called with help.
  ZP-1291 Exit with 0 if z-push-admin called with help.
parents 1ecfcba2 0ca4275a
...@@ -52,6 +52,9 @@ require_once 'vendor/autoload.php'; ...@@ -52,6 +52,9 @@ require_once 'vendor/autoload.php';
fwrite(STDERR, ZPushAdminCLI::GetErrorMessage() . "\n"); fwrite(STDERR, ZPushAdminCLI::GetErrorMessage() . "\n");
echo ZPushAdminCLI::UsageInstructions(); echo ZPushAdminCLI::UsageInstructions();
if (ZPushAdminCLI::$help) {
exit(0);
}
exit(1); exit(1);
} }
...@@ -101,6 +104,8 @@ class ZPushAdminCLI { ...@@ -101,6 +104,8 @@ class ZPushAdminCLI {
static private $folderid = false; static private $folderid = false;
static private $flags = 0; static private $flags = 0;
static public $help = false;
/** /**
* Returns usage instructions * Returns usage instructions
* *
...@@ -172,7 +177,7 @@ class ZPushAdminCLI { ...@@ -172,7 +177,7 @@ class ZPushAdminCLI {
if (self::$errormessage) if (self::$errormessage)
return; return;
$options = getopt("u:d:a:t:sn:o:f:g::", array('user:', 'device:', 'action:', 'type:', 'days-old:', 'days-ago:', 'shared', 'foldername:', 'store', 'folderid:', 'flags::')); $options = getopt("u:d:a:t:sn:o:f:g::h", array('user:', 'device:', 'action:', 'type:', 'days-old:', 'days-ago:', 'shared', 'foldername:', 'store', 'folderid:', 'flags::', 'help'));
// get 'user' // get 'user'
if (isset($options['u']) && !empty($options['u'])) if (isset($options['u']) && !empty($options['u']))
...@@ -269,6 +274,11 @@ class ZPushAdminCLI { ...@@ -269,6 +274,11 @@ class ZPushAdminCLI {
} }
} }
if ((isset($options['h']) || isset($options['help'])) && $action === false) {
self::$help = true;
$action = 'help';
}
// get a command for the requested action // get a command for the requested action
switch ($action) { switch ($action) {
// list data // list data
...@@ -381,8 +391,12 @@ class ZPushAdminCLI { ...@@ -381,8 +391,12 @@ class ZPushAdminCLI {
self::$command = self::COMMAND_REMOVESHARED; self::$command = self::COMMAND_REMOVESHARED;
break; break;
case "help":
break;
default: default:
self::UsageInstructions(); self::UsageInstructions();
self::$help = false;
} }
} }
......
...@@ -51,7 +51,7 @@ require_once 'vendor/autoload.php'; ...@@ -51,7 +51,7 @@ require_once 'vendor/autoload.php';
// check if help was requested from CLI // check if help was requested from CLI
if (in_array('-h', $argv) || in_array('--help', $argv)) { if (in_array('-h', $argv) || in_array('--help', $argv)) {
echo $zpt->UsageInstructions(); echo $zpt->UsageInstructions();
exit(1); exit(0);
} }
if ($zpt->IsAvailable()) { if ($zpt->IsAvailable()) {
......
...@@ -42,6 +42,9 @@ include_once(SYNC_CONFIG); ...@@ -42,6 +42,9 @@ include_once(SYNC_CONFIG);
fwrite(STDERR, GabSyncCLI::GetErrorMessage() . PHP_EOL.PHP_EOL); fwrite(STDERR, GabSyncCLI::GetErrorMessage() . PHP_EOL.PHP_EOL);
echo GabSyncCLI::UsageInstructions(); echo GabSyncCLI::UsageInstructions();
if (GabSyncCLI::$help) {
exit(0);
}
exit(1); exit(1);
} }
else if (!GabSyncCLI::SetupSyncWorker()) { else if (!GabSyncCLI::SetupSyncWorker()) {
...@@ -74,6 +77,8 @@ class GabSyncCLI { ...@@ -74,6 +77,8 @@ class GabSyncCLI {
static private $targetGab = false; static private $targetGab = false;
static private $errormessage; static private $errormessage;
static public $help = false;
/** /**
* Returns usage instructions. * Returns usage instructions.
* *
...@@ -142,7 +147,7 @@ class GabSyncCLI { ...@@ -142,7 +147,7 @@ class GabSyncCLI {
if (self::$errormessage) if (self::$errormessage)
return; return;
$options = getopt("u:a:t:"); $options = getopt("u:a:t:h", array('help'));
// get 'unique-id' // get 'unique-id'
if (isset($options['u']) && !empty($options['u'])) if (isset($options['u']) && !empty($options['u']))
...@@ -163,6 +168,11 @@ class GabSyncCLI { ...@@ -163,6 +168,11 @@ class GabSyncCLI {
elseif (isset($options['action']) && !empty($options['action'])) elseif (isset($options['action']) && !empty($options['action']))
$action = strtolower(trim($options['action'])); $action = strtolower(trim($options['action']));
if ((isset($options['h']) || isset($options['help'])) && $action === false) {
self::$help = true;
$action = 'help';
}
// get a command for the requested action // get a command for the requested action
switch ($action) { switch ($action) {
// simulate // simulate
...@@ -195,8 +205,12 @@ class GabSyncCLI { ...@@ -195,8 +205,12 @@ class GabSyncCLI {
self::$command = self::COMMAND_DELETEALL; self::$command = self::COMMAND_DELETEALL;
break; break;
case "help":
break;
default: default:
self::UsageInstructions(); self::UsageInstructions();
self::$help = false;
} }
} }
......
...@@ -48,6 +48,9 @@ define('PATH_TO_ZPUSH', '../../src/'); ...@@ -48,6 +48,9 @@ define('PATH_TO_ZPUSH', '../../src/');
fwrite(STDERR, GAB2ContactsCLI::GetErrorMessage() . PHP_EOL.PHP_EOL); fwrite(STDERR, GAB2ContactsCLI::GetErrorMessage() . PHP_EOL.PHP_EOL);
echo GAB2ContactsCLI::UsageInstructions(); echo GAB2ContactsCLI::UsageInstructions();
if (GAB2ContactsCLI::$help) {
exit(0);
}
exit(1); exit(1);
} }
else if (!GAB2ContactsCLI::SetupContactWorker()) { else if (!GAB2ContactsCLI::SetupContactWorker()) {
...@@ -76,6 +79,8 @@ class GAB2ContactsCLI { ...@@ -76,6 +79,8 @@ class GAB2ContactsCLI {
static private $sourceGAB; static private $sourceGAB;
static private $errormessage; static private $errormessage;
static public $help = false;
/** /**
* Returns usage instructions. * Returns usage instructions.
* *
...@@ -144,7 +149,7 @@ class GAB2ContactsCLI { ...@@ -144,7 +149,7 @@ class GAB2ContactsCLI {
if (self::$errormessage) if (self::$errormessage)
return; return;
$options = getopt("a:"); $options = getopt("a:h", array('help'));
// get 'action' // get 'action'
$action = false; $action = false;
...@@ -153,6 +158,11 @@ class GAB2ContactsCLI { ...@@ -153,6 +158,11 @@ class GAB2ContactsCLI {
elseif (isset($options['action']) && !empty($options['action'])) elseif (isset($options['action']) && !empty($options['action']))
$action = strtolower(trim($options['action'])); $action = strtolower(trim($options['action']));
if ((isset($options['h']) || isset($options['help'])) && $action === false) {
self::$help = true;
$action = 'help';
}
// get a command for the requested action // get a command for the requested action
switch ($action) { switch ($action) {
// sync! // sync!
...@@ -165,8 +175,12 @@ class GAB2ContactsCLI { ...@@ -165,8 +175,12 @@ class GAB2ContactsCLI {
self::$command = self::COMMAND_DELETE; self::$command = self::COMMAND_DELETE;
break; break;
case "help":
break;
default: default:
self::UsageInstructions(); self::UsageInstructions();
self::$help = false;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment