ungana

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs | README

commit 9bdcf152348f975cb5162e42283473a8581d1c1a
parent bababfeb6d8b67592b0824f8ef997e7a20ffd4e9
Author: Carlosokumu <carlosokumu254@gmail.com>
Date:   Thu, 21 Aug 2025 16:08:36 +0300

improve  ArgsParser:
- add _get_user_updates_from_args that extracts and parses editable fields provided to the  edit sub command via arguments.
-  extend handle_edit to check if the user gave any field args: if yes → do non-interactive update If no → go into interactive edit mode.

Diffstat:
Mcalendarapp/cmd/args_parser.py | 58++++++++++++++++++++++++++++++++++------------------------
1 file changed, 34 insertions(+), 24 deletions(-)

diff --git a/calendarapp/cmd/args_parser.py b/calendarapp/cmd/args_parser.py @@ -151,35 +151,25 @@ class ArgsParser: self.parser.error("corrupted or missing ical file") if args.all: - self._edit_multiple_events(cal, ical_file_path) + return self._edit_multiple_events(cal, ical_file_path) + + updates, attachments = self._get_user_updates_from_args(args) + if any([updates, attachments]): + # Non-interactive mode + self.ical_manager.update_event(cal, updates, attachments, args.ical) + logging.info("Calendar updated successfully") else: - self._edit_most_recent_event(cal,args,ical_file_path) + # Interactive mode + self._edit_most_recent_event(cal, args, args.ical) def _edit_most_recent_event(self, cal, args, ical_file_path): - updates = {} - attachments = [] - - if args.start: updates["DTSTART"] = args.start - if args.duration: updates["DURATION"] = args.duration - if args.summary: updates["SUMMARY"] = args.summary - if args.location: updates["LOCATION"] = args.location - if args.description: updates["DESCRIPTION"] = args.description - if args.organizer: updates["ORGANIZER"] = args.organizer - - for ctx_name in ("poster", "long"): - arg_val = getattr(args, ctx_name, None) - if arg_val: - try: - prop, value, params = self.attachment_manager.create_attachment(arg_val, ctx=ctx_name) - attachments.append((prop, value, params)) - except Exception as e: - self.parser.error(f"Unexpected error: {e}") - event = self.ical_manager.get_first_event(cal) - updates.update(self._get_user_event_updates(event)) - if updates or attachments: - self.ical_manager.update_event(cal, updates, attachments, ical_file_path) + # only interactive prompts + updates = self._get_user_event_updates(event) + + if updates: + self.ical_manager.update_event(cal, updates, [], ical_file_path) logging.info("Calendar updated successfully") else: logging.info("No changes made to calendar file") @@ -267,8 +257,28 @@ class ArgsParser: updates[field] = new_value return updates + + def _get_user_updates_from_args(self, args): + updates = {} + attachments = [] + + if args.start: updates["DTSTART"] = args.start + if args.duration: updates["DURATION"] = args.duration + if args.summary: updates["SUMMARY"] = args.summary + if args.location: updates["LOCATION"] = args.location + if args.description: updates["DESCRIPTION"] = args.description + if args.organizer: updates["ORGANIZER"] = args.organizer + for ctx_name in ("poster", "long"): + arg_val = getattr(args, ctx_name, None) + if arg_val: + try: + prop, value, params = self.attachment_manager.create_attachment(arg_val, ctx=ctx_name) + attachments.append((prop, value, params)) + except Exception as e: + self.parser.error(f"Unexpected error: {e}") + return updates, attachments def run(self):