Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
frdmn committed Mar 22, 2016
1 parent bc81bed commit 54741ab
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ function render_results($input_array){
print $w->toXML($results);
}

// Store argument in variable
$input = strtolower($argv[1]);

// Find out which cache file should be used
if (file_exists($_SERVER['HOME']."/.alfred-dongers.cache")) {
$donger_cache = $_SERVER['HOME']."/.alfred-dongers.cache";
Expand All @@ -46,7 +43,9 @@ function render_results($input_array){
$dongers = array();

// Check for arguments (show only specified category or list categories)
if (isset($input)) {
if (isset($argv[1])) {
// Store argument in variable
$input = strtolower($argv[1]);
// If argument is "list" => list categories
if ($input == "list") {
foreach (array_keys(get_object_vars($donger_raw)) as $category) {
Expand All @@ -55,10 +54,15 @@ function render_results($input_array){
render_results(array_unique($catgories));
// If argument is "category" => show dongers of specific category
} else {
foreach ($donger_raw->$input as $donger) {
$dongers[] = $donger;
if (isset($donger_raw->$input)) {
foreach ($donger_raw->$input as $donger) {
$dongers[] = $donger;
}
render_results($dongers);
} else {
$errors[] = 'Warning: Couldn\'t find category "'.$input.'"!';
render_results($errors);
}
render_results($dongers);
}
} else {
// No arguments => show all dongers
Expand Down

0 comments on commit 54741ab

Please sign in to comment.