Commit 3cd24441 authored by Guillaume Rousse's avatar Guillaume Rousse

use a single options, accepting two syntaxes

parent b4865866
...@@ -30,11 +30,7 @@ Argument Description ...@@ -30,11 +30,7 @@ Argument Description
--metadata-idp-file <file> File containing Service Providers --metadata-idp-file <file> File containing Service Providers
--metadata-sp-file <file> File containing Identity Providers --metadata-sp-file <file> File containing Identity Providers
--min-idp-count <count> Minimum expected number of IdPs in metadata --min-idp-count <count> Minimum expected number of IdPs in metadata
--min-idp-quota <quota> Minimum expected number of IdPs in metadata,
as a percentage of current number
--min-sp-count <count> Minimum expected number of SPs in metadata --min-sp-count <count> Minimum expected number of SPs in metadata
--min-sp-quota <quoat> Minimum expected number of SPs in metadata,
as a percentage of current number
--language <locale> Language locale, e.g. 'en', 'jp', ... --language <locale> Language locale, e.g. 'en', 'jp', ...
--verbose | -v Verbose mode --verbose | -v Verbose mode
--help | -h Print this man page --help | -h Print this man page
...@@ -54,9 +50,7 @@ $longopts = array( ...@@ -54,9 +50,7 @@ $longopts = array(
"metadata-idp-file:", "metadata-idp-file:",
"metadata-sp-file:", "metadata-sp-file:",
"min-idp-count:", "min-idp-count:",
"min-idp-quota:",
"min-sp-count:", "min-sp-count:",
"min-sp-quota:",
"language:", "language:",
"verbose", "verbose",
"help", "help",
...@@ -91,36 +85,28 @@ if (!isset($options['metadata-idp-file'])) { ...@@ -91,36 +85,28 @@ if (!isset($options['metadata-idp-file'])) {
} }
if (isset($options['min-sp-count'])) { if (isset($options['min-sp-count'])) {
if (!is_numeric($options['min-sp-count'])) { if (preg_match('/^(\d+)%$/', $options['min-sp-count'], $matches)) {
exit("Exiting: invalid value for --min-sp-count parameter\n");
} else {
$minSPCount = $options['min-sp-count'];
}
} elseif (isset($options['min-sp-quota'])) {
if (!is_numeric($options['min-sp-quota'])) {
exit("Exiting: invalid value for --min-sp-quota parameter\n");
} else {
require_once($metadataSPFile); require_once($metadataSPFile);
$SPCount = count($metadataSProviders); $SPCount = count($metadataSProviders);
$minSPCount = floor($SPCount * $options['min-sp-quota'] / 100); $minSPCount = floor($SPCount * $matches[1] / 100);
} elseif (preg_match('/^\d+$/', $options['min-sp-count'])) {
$minSPCount = $options['min-sp-count'];
} else {
exit("Exiting: invalid value for --min-sp-count parameter\n");
} }
} else { } else {
$minSPCount = 0; $minSPCount = 0;
} }
if (isset($options['min-idp-count'])) { if (isset($options['min-idp-count'])) {
if (!is_numeric($options['min-idp-count'])) { if (preg_match('/^(\d+)%$/', $options['min-idp-count'], $matches)) {
exit("Exiting: invalid value for --min-idp-count parameter\n");
} else {
$minIDPCount = $options['min-idp-count'];
}
} elseif (isset($options['min-idp-quota'])) {
if (!is_numeric($options['min-idp-quota'])) {
exit("Exiting: invalid value for --min-idp-quota parameter\n");
} else {
require_once($metadataIDPFile); require_once($metadataIDPFile);
$IDPCount = count($metadataIDProviders); $IDPCount = count($metadataIDProviders);
$minIDPCount = floor($IDPCount * $options['min-idp-quota'] / 100); $minIDPCount = floor($IDPCount * $matches[1] / 100);
} elseif (preg_match('/^\d+$/', $options['min-idp-count'])) {
$minIDPCount = $options['min-idp-count'];
} else {
exit("Exiting: invalid value for --min-idp-count parameter\n");
} }
} else { } else {
$minIDPCount = 0; $minIDPCount = 0;
......
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