From: Kyle Bowman Date: Mon, 27 Jan 2025 00:33:46 +0000 (-0500) Subject: add --dry-run for entry updates X-Git-Url: https://git.rocketbowman.com/?a=commitdiff_plain;h=a7404bd263477ea9244d01f97787bf2cf2d208b4;p=nom.git add --dry-run for entry updates --- diff --git a/src/nom/main.py b/src/nom/main.py index bad89e6..1fa4dc6 100644 --- a/src/nom/main.py +++ b/src/nom/main.py @@ -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)