diff options
-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); } |