feat(food-tracking): add --aliases support to food_items.py and update skill docs
This commit is contained in:
parent
a91cfcd26b
commit
d916c6925b
2 changed files with 21 additions and 1 deletions
|
|
@ -31,6 +31,8 @@ def cmd_add(args):
|
|||
except json.JSONDecodeError:
|
||||
print(f"Error: --nutrition must be valid JSON. Got: {args.nutrition}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
if args.aliases:
|
||||
doc["aliases"] = [a.strip() for a in args.aliases.split(",") if a.strip()]
|
||||
if args.extra:
|
||||
try:
|
||||
extra = json.loads(args.extra)
|
||||
|
|
@ -49,7 +51,10 @@ def cmd_get(args):
|
|||
coll, client = get_collection()
|
||||
query = {}
|
||||
if args.name:
|
||||
query["name"] = {"$regex": args.name, "$options": "i"}
|
||||
query["$or"] = [
|
||||
{"name": {"$regex": args.name, "$options": "i"}},
|
||||
{"aliases": {"$regex": args.name, "$options": "i"}},
|
||||
]
|
||||
if args.type:
|
||||
query["type"] = {"$regex": args.type, "$options": "i"}
|
||||
|
||||
|
|
@ -90,6 +95,8 @@ def cmd_update(args):
|
|||
update_fields["description"] = args.set_description
|
||||
if args.set_max_dosage:
|
||||
update_fields["max_dosage"] = args.set_max_dosage
|
||||
if args.set_aliases:
|
||||
update_fields["aliases"] = [a.strip() for a in args.set_aliases.split(",") if a.strip()]
|
||||
if args.set_nutrition:
|
||||
try:
|
||||
update_fields["nutrition"] = json.loads(args.set_nutrition)
|
||||
|
|
@ -142,6 +149,7 @@ def main():
|
|||
p_add.add_argument("--serving")
|
||||
p_add.add_argument("--description")
|
||||
p_add.add_argument("--max-dosage")
|
||||
p_add.add_argument("--aliases", help="Comma-separated alias names, e.g. \"large bread,large toast\"")
|
||||
p_add.add_argument("--nutrition", help='JSON string, e.g. \'{"calories": 228, "protein_g": 12}\'')
|
||||
p_add.add_argument("--extra", help="JSON string with additional fields to merge into the document")
|
||||
|
||||
|
|
@ -160,6 +168,7 @@ def main():
|
|||
p_upd.add_argument("--set-serving", dest="set_serving")
|
||||
p_upd.add_argument("--set-description", dest="set_description")
|
||||
p_upd.add_argument("--set-max-dosage", dest="set_max_dosage")
|
||||
p_upd.add_argument("--set-aliases", dest="set_aliases", help="Comma-separated alias names (replaces existing)")
|
||||
p_upd.add_argument("--set-nutrition", dest="set_nutrition", help="JSON string to replace nutrition")
|
||||
p_upd.add_argument("--set-extra", dest="set_extra", help="JSON string with additional fields to set")
|
||||
p_upd.add_argument("--unset", nargs="*", help="Field names to remove")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue