2.8. Saving new foods with --add and --edit; deleting with the --delete option

You'll probably want to store the new foods you make. You'll usually do this using the --add or -a option. This option takes a single FILENAME argument. FILENAME can be almost any name you want. For now, though, it should not end in .xml, .zip, or .txt--we'll learn about what these extensions do later. If FILENAME does not already exist, pantry will create it for you; if the file already exists, the foods returned from your search will be added to the file.

Two identical foods cannot exist in a single file. Two foods are identical if all their traits are identical. When you add a food to a file and there is already an identical food in the file, Pantry will alter the comment trait of the food you are adding by appending (Copy 1), (Copy 2), etc.

Example 2.23. Using the --add option

$ pantry --name "Bananas, raw" --add newfile --print traits \
> master
Bananas, raw
Group: Fruits and Fruit Juices
Refuse: 36 percent Skin
100 g (100g)
$ pantry --print traits newfile
Bananas, raw
Group: Fruits and Fruit Juices
Refuse: 36 percent Skin
100 g (100g)

Another way to store the changes you make is by using the --edit option. --edit searches for foods and makes changes that you specify. Unlike --add, --edit does not add the changed foods to a new file; instead, it changes already existing foods, in the same file.

Example 2.24. Using the --edit option

$ pantry --name "Bananas, raw" --c-name "Bananas, big \
> yellow" --edit --print traits master
Bananas, big yellow
Group: Fruits and Fruit Juices
Refuse: 36 percent Skin
100 g (100g)
$ pantry --name Bananas --print traits-blank master
Cereals ready-to-eat, KELLOGG'S, CORN FLAKES With Real Bananas
Group: Breakfast Cereals
100 g (100g)

Bananas, dehydrated, or banana powder
Group: Fruits and Fruit Juices
100 g (100g)

Bananas, big yellow
Group: Fruits and Fruit Juices
Refuse: 36 percent Skin
100 g (100g)


Finally, you may delete foods from the original files with the --delete option.

Example 2.25. Using the --delete option

$ pantry --name "Bananas, big yellow" --print traits --delete \
> master
Bananas, big yellow
Group: Fruits and Fruit Juices
Refuse: 36 percent Skin
100 g (100g)
$ pantry --name "Bananas, big yellow" --print traits master