summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2011-08-08 18:41:23 +0200
committercos <cos>2011-08-08 18:41:23 +0200
commit57817436298c107fb7727dd292185ebff21d8d66 (patch)
tree84896e70c1e3aebcfa5232c012fff6f063c13c73
parentc2ed5b9cd216c036e182bac00344faf100db9c47 (diff)
downloadmat-57817436298c107fb7727dd292185ebff21d8d66.zip
Added randmeal command.
-rwxr-xr-xmat21
1 files changed, 15 insertions, 6 deletions
diff --git a/mat b/mat
index 392d93b..2a60aa8 100755
--- a/mat
+++ b/mat
@@ -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;