Skip to content

Commit

Permalink
Fix handling of --delete argument in moduserprefs.sh script (#5296)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpl committed Jun 1, 2016
1 parent f466899 commit d61d33a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ CHANGELOG Roundcube Webmail
- Fix bug where "no body" alert could be displayed when sending mailvelope email
- Enigma: Fix keys import from inside of an encrypted message (#5285)
- Fix searching by email address in contacts with multiple addresses (#5291)
- Fix handling of --delete argument in moduserprefs.sh script (#5296)

RELEASE 1.2.0
-------------
Expand Down
4 changes: 2 additions & 2 deletions bin/moduserprefs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function print_usage()
// get arguments
$args = rcube_utils::get_opt(array(
'u' => 'user',
'd' => 'delete',
'd' => 'delete:bool',
't' => 'type',
'c' => 'config',
));
Expand All @@ -45,7 +45,7 @@ if ($_SERVER['argv'][1] == 'help') {
print_usage();
exit;
}
else if (empty($args[0]) || (!isset($args[1]) && !$args['delete'])) {
else if (empty($args[0]) || (empty($args[1]) && empty($args['delete']))) {
print "Missing required parameters.\n";
print_usage();
exit;
Expand Down
2 changes: 1 addition & 1 deletion bin/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' );
require_once INSTALL_PATH . 'program/include/clisetup.php';

// get arguments
$opts = rcube_utils::get_opt(array('v' => 'version', 'y' => 'accept'));
$opts = rcube_utils::get_opt(array('v' => 'version', 'y' => 'accept:bool'));

// ask user if no version is specified
if (!$opts['version']) {
Expand Down
14 changes: 14 additions & 0 deletions program/lib/Roundcube/rcube_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,16 @@ public static function words_match($haystack, $needle)
public static function get_opt($aliases = array())
{
$args = array();
$bool = array();

// find boolean (no value) options
foreach ($aliases as $key => $alias) {
if ($pos = strpos($alias, ':')) {
$aliases[$key] = substr($alias, 0, $pos);
$bool[] = $key;
$bool[] = $aliases[$key];
}
}

for ($i=1; $i < count($_SERVER['argv']); $i++) {
$arg = $_SERVER['argv'][$i];
Expand All @@ -985,10 +995,14 @@ public static function get_opt($aliases = array())
if ($arg[0] == '-') {
$key = preg_replace('/^-+/', '', $arg);
$sp = strpos($arg, '=');

if ($sp > 0) {
$key = substr($key, 0, $sp - 2);
$value = substr($arg, $sp+1);
}
else if (in_array($key, $bool)) {
$value = true;
}
else if (strlen($_SERVER['argv'][$i+1]) && $_SERVER['argv'][$i+1][0] != '-') {
$value = $_SERVER['argv'][++$i];
}
Expand Down

0 comments on commit d61d33a

Please sign in to comment.