diff options
author | cos <cos> | 2012-05-25 08:33:54 +0200 |
---|---|---|
committer | cos <cos> | 2012-12-17 21:12:07 +0100 |
commit | f3814534aa5a6216457353d7388f93d38798ca1e (patch) | |
tree | 85511c4fe42b209b5d46fdc8f5f3d91735558814 | |
parent | ce997e6136f96c52dd869cedce63ca412eaa2367 (diff) | |
download | mat-f3814534aa5a6216457353d7388f93d38798ca1e.zip |
Add inital version of cmd_showrecipe().
-rwxr-xr-x | mat | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -276,6 +276,7 @@ sub cmd_help() { print "help\n"; print "addrecipe\n"; print "editrecipe <recipe_id>\n"; + print "showrecipe <recipe_id>\n"; print "movemeal <source_date> <destination_date>\n"; print "setmeal <date> <meal_id>\n"; print "setstate <date> <idea|sourced|frozen|ready>\n"; @@ -397,6 +398,38 @@ sub cmd_addrecipe { return interactive_edit_recipe_ingredients($recipe_id[0]); } +sub cmd_showrecipe { + # Argument is recipe_id + + my ( $recipe_id ) = @_; + + my $recipe_row = $db->selectrow_arrayref("SELECT name, uri, servings FROM recipes WHERE id=".$recipe_id.";"); + my $servings; + + print @$recipe_row[0]; + if(defined(@$recipe_row[1])) { + printf ", %s\n", @$recipe_row[1]; + } else { + print "\n"; + } + if(defined(@$recipe_row[2])) { + $servings = @$recipe_row[2]; + print "Serves: $servings\n\n" + } else { + $servings = 1; + print "WARNING servings is not set for recipe $recipe_id!\n\n"; + } + + my $contents = $db->selectall_hashref("SELECT * FROM contents WHERE recipe_id=".$recipe_id.";", 'ingredient_id'); + for my $content ( keys(%$contents)) { + my $ingredientcol = $db->selectcol_arrayref("SELECT name FROM ingredients WHERE id=".$content.";"); + printf "%4s %-8s %s\n", $$contents{$content}{quantity}, + $$contents{$content}{unit}, @$ingredientcol[0]; + } + + return 1; +} + sub cmd_shoppinglist { # Argument is number of days to shop for @@ -488,6 +521,9 @@ if ($ARGV[0]) { if ( $ARGV[0] eq "editrecipe") { print "Command failed!\n" unless (cmd_editrecipe($ARGV[1]) >= 0); } + if ( $ARGV[0] eq "showrecipe") { + print "Command failed!\n" unless (cmd_showrecipe($ARGV[1]) >= 0); + } if ( $ARGV[0] eq "movemeal") { print "Command failed!\n" unless (cmd_movemeal($ARGV[1], $ARGV[2]) >= 0); } |