Add info command.

This commit is contained in:
2024-10-11 12:01:22 +02:00
parent c0c6959774
commit 1a590b477e
6 changed files with 86 additions and 0 deletions

View File

@@ -137,3 +137,42 @@ int command_delete(int argc, char *argv[]) {
return ret;
}
int command_info(const int id) {
struct recipe recipe;
std::vector<std::string> ingredients, tags;
int ret = EXIT_SUCCESS;
if(not db_open()) {
std::cerr << "Failed to open database. Cannot add new entry." << std::endl;
return EXIT_FAILURE;
}
if(not db_recipe_exists(id)) {
std::cerr << "No recipe with ID '" << id << "'";
return EXIT_FAILURE;
}
recipe = db_get_recipe(id);
ingredients = db_get_recipe_ingredients(id);
tags = db_get_recipe_tags(id);
db_close();
std::cout << "Name: " << recipe.name << "\n"
<< "Description: " << recipe.description << "\n"
<< "ID: " << recipe.id << "\n"
<< std::endl;
std::cout << "Ingredients:" << std::endl;
for(auto &ingredient : ingredients)
std::cout << "\t- " << ingredient << std::endl;
std::cout << std::endl;
std::cout << "Tags:" << std::endl;
for(auto &tag : tags)
std::cout << "\t- " << tag << std::endl;
std::cout << std::endl;
return ret;
}