diff options
author | cos <cos> | 2012-08-13 21:55:33 +0200 |
---|---|---|
committer | cos <cos> | 2012-12-17 21:12:07 +0100 |
commit | 16ebab0769ba766fc80481388724cc2f9df75902 (patch) | |
tree | 10157ba702eff915a6e2b46c087b758168bc7db7 | |
parent | 5ea0c3dfdaa1417ec70e3621fa16f8b85b1cb583 (diff) | |
download | mat-16ebab0769ba766fc80481388724cc2f9df75902.zip |
Added initial version of searchrecipes command.
-rwxr-xr-x | mat | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -296,6 +296,7 @@ sub cmd_randweek { sub cmd_help() { print "help\n"; print "addrecipe\n"; + print "searchrecipes <search_string>\n"; print "editrecipe <recipe_id>\n"; print "showrecipe <recipe_id>\n"; print "movemeal <source_date> <destination_date>\n"; @@ -451,6 +452,21 @@ sub cmd_showrecipe { return 1; } +sub cmd_searchrecipes { + # Argument is search regexp + + my ( $regex ) = @_; + + while (my ($i, $recipe) = each @recipes) { + next if not defined($recipe); + if(grep(/$regex/i, $recipe->{'name'})) { + printf "%4d| %-50s\n", $i, $recipe->{'name'}; + } + } + + return 1; +} + sub cmd_shoppinglist { # Argument is number of days to shop for @@ -537,6 +553,8 @@ if ($ARGV[0]) { print "Command failed!\n" unless (cmd_help >= 0); } elsif ( $ARGV[0] eq "addrecipe") { print "Command failed!\n" unless (cmd_addrecipe() >= 0); + } elsif ( $ARGV[0] eq "searchrecipes") { + print "Command failed!\n" unless (cmd_searchrecipes($ARGV[1]) >= 0); } elsif ( $ARGV[0] eq "editrecipe") { print "Command failed!\n" unless (cmd_editrecipe($ARGV[1]) >= 0); } elsif ( $ARGV[0] eq "showrecipe") { |