diff options
author | cos <cos> | 2011-08-08 18:41:23 +0200 |
---|---|---|
committer | cos <cos> | 2011-08-08 18:41:23 +0200 |
commit | 57817436298c107fb7727dd292185ebff21d8d66 (patch) | |
tree | 84896e70c1e3aebcfa5232c012fff6f063c13c73 | |
parent | c2ed5b9cd216c036e182bac00344faf100db9c47 (diff) | |
download | mat-57817436298c107fb7727dd292185ebff21d8d66.zip |
Added randmeal command.
-rwxr-xr-x | mat | 21 |
1 files changed, 15 insertions, 6 deletions
@@ -85,8 +85,7 @@ my @schedule = ( ); sub cmd_setmeal { - my $date = $ARGV[1]; - my $recipe_id = $ARGV[2]; + my ( $date, $recipe_id ) = @_; my $mealtype = "lunch"; if ($date =~ /^Mon|Tue|Wed|Thu|Fri|Sat|Sun/) { @@ -125,12 +124,19 @@ sub cmd_setmeal { return 0; } +sub cmd_randmeal { + my ( $date ) = @_; + my $recipe_id = get_random_recipe(); + + return cmd_setmeal($date, $recipe_id); +} + sub cmd_showplan { + my ( $date ) = @_; my $mealtype = "lunch"; my $dt; - if($ARGV[1]) { - my $date = $ARGV[1]; + if($date) { return -1 unless $date =~ "^[0-9]{4}-[0-9]{2}-[0-9]{2}\$"; $dt = DateTime::Format::ISO8601->parse_datetime( $date ); } else { @@ -171,10 +177,13 @@ read_recipe_db; if ($ARGV[0]) { if ( $ARGV[0] eq "setmeal") { - print "Command failed!\n" unless (cmd_setmeal >= 0); + print "Command failed!\n" unless (cmd_setmeal($ARGV[1], $ARGV[2]) >= 0); + } + if ( $ARGV[0] eq "randmeal") { + print "Command failed!\n" unless (cmd_randmeal($ARGV[1]) >= 0); } if ( $ARGV[0] eq "showplan") { - print "Command failed!\n" unless (cmd_showplan >= 0); + print "Command failed!\n" unless (cmd_showplan($ARGV[1]) >= 0); } } else { cmd_showplan; |