]> git.rocketbowman.com Git - nom.git/commitdiff
add --dry-run for entry updates
authorKyle Bowman <kyle+github@rocketbowman.com>
Mon, 27 Jan 2025 00:33:46 +0000 (19:33 -0500)
committerKyle Bowman <kyle+github@rocketbowman.com>
Mon, 27 Jan 2025 00:33:46 +0000 (19:33 -0500)
src/nom/main.py

index bad89e6d155cbdd3e968f3322801ac5e2f22dbf8..1fa4dc6b4b5fcd7c745202f98b9c8ff81a9806ef 100644 (file)
@@ -31,10 +31,10 @@ def cli():
     entry_show_parser = entry_subparsers.add_parser('show', parents=[label_parser,filter_parser], help='Show entries.')
     entry_show_parser.set_defaults(func=handle_entry_show) 
     entry_show_parser.add_argument('--full', action='store_true', help="when specified, show the full entry data, not just the URLs.")
-    entry_update_parser = entry_subparsers.add_parser('update', parents=[label_parser], help='update entry data.')
+    entry_update_parser = entry_subparsers.add_parser('update', parents=[label_parser,filter_parser], help='update entry data.')
     entry_update_parser.set_defaults(func=handle_entry_update)
     entry_update_parser.add_argument('--update', dest="updates", nargs="*", help="Update values as key=value pairs")
-
+    entry_update_parser.add_argument('--dry-run', action="store_true", help="when specified, show changes but don't act")
 
     # Feed subcommand
     feed_parser = subparsers.add_parser('feed', help='Dispatches commands that operate on a table of feeds.')
@@ -66,18 +66,24 @@ def handle_entry_update(args):
         elist=EntryList()
     else:
         elist = EntryList.from_csv(ENTRY_LIST)
+
+    if args.dry_run:
+        print("Dry run: No changes taking place")
+
     if args.updates:
         sublist = elist.select(lambda e: e.label in args.label)
         for u in args.updates:
             key, val = u.split('=')
             for e in elist:
                 if e in sublist:
-                    e.update(key,val)
+                    if not args.dry_run:
+                        e.update(key,val)
+                    print(f"For {e.label}, updating {key} from {e.__dict__[key]} to {val}")
     else:
         feedlist=FeedList.from_csv(FEED_LIST)
         for flitem in feedlist:
-            elist += flitem.to_feed().to_entrylist()
+            if not args.dry_run:
+                elist += flitem.to_feed().to_entrylist()
             print(f"Updating from [{str(flitem)}]")
     elist.to_csv(ENTRY_LIST)