From 3ba0d53d62e66c254155b9749807075ea0b4969f Mon Sep 17 00:00:00 2001 From: Carine Dengler Date: Thu, 14 Mar 2024 20:18:23 +0100 Subject: [PATCH] refactor: cleaned up subcommand messages --- pusteblume/messages.py | 15 ++++++++------- pusteblume/tasks.py | 20 ++++++++------------ 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/pusteblume/messages.py b/pusteblume/messages.py index 9f05cda..2c09431 100644 --- a/pusteblume/messages.py +++ b/pusteblume/messages.py @@ -28,14 +28,15 @@ PROMPT = "> " MESSAGES = { "tasks": { - "no_running_task": "no running task", + "stop": { + "no_task": "no running task", + }, "edit": { - "task": "Editing task '{task}'...", - "tasks": "Which task do you want to edit?", - "no_task": "'{task}' does not exist", - "attribute": "Which attribute do you want to edit?", - "new_attr": "What is the new value of {attribute}?", - "new_value": "The new value of {attribute} is {value}", + "single_matching_task": "editing '{task}' …", + "multiple_matching_tasks": "choose task to edit: …", + "no_matching_task": "no task '{task}'", + "attribute": "choose attribute to edit: …", + "value": "new value of {attribute}: …", }, }, "config": { diff --git a/pusteblume/tasks.py b/pusteblume/tasks.py index 9e5cab8..e58f4b2 100644 --- a/pusteblume/tasks.py +++ b/pusteblume/tasks.py @@ -340,7 +340,7 @@ def stop(config): """ rows = _get_currently_running_task(config) if not rows: - return pusteblume.messages.MESSAGES["tasks"]["no_running_task"] + return pusteblume.messages.MESSAGES["tasks"]["stop"]["no_task"] end_time = datetime.datetime.now() _execute(config, "UPDATE task SET end_time = ? WHERE end_time IS NULL", (end_time,)) return os.linesep.join( @@ -391,7 +391,7 @@ def status(config): """ rows = _get_currently_running_task(config) if not rows: - return pusteblume.messages.MESSAGES["tasks"]["no_running_task"] + return pusteblume.messages.MESSAGES["tasks"]["stop"]["no_task"] (task_id, name, start_time) = rows[0] return Task( name, @@ -439,21 +439,21 @@ def edit(config, name=None, tags=tuple()): """ tasks = list(_get_task(config, name, tags)) if not tasks: - return pusteblume.messages.MESSAGES["tasks"]["edit"]["no_task"].format( + return pusteblume.messages.MESSAGES["tasks"]["edit"]["no_matching_task"].format( task=Task(name, tags, (None, None)).pprinted_short, ) if len(tasks) > 1: task_id, task = tasks[ _select( config, - pusteblume.messages.MESSAGES["tasks"]["edit"]["tasks"], + pusteblume.messages.MESSAGES["tasks"]["edit"]["multiple_matching_tasks"], (task.pprinted_medium for _, task in tasks), ) - 1 ] else: task_id, task = tasks[0] print( - pusteblume.messages.MESSAGES["tasks"]["edit"]["task"].format( + pusteblume.messages.MESSAGES["tasks"]["edit"]["single_matching_task"].format( task=task.pprinted_medium, ) ) @@ -471,7 +471,7 @@ def edit(config, name=None, tags=tuple()): ) - 1 ] new_value = _input( - pusteblume.messages.MESSAGES["tasks"]["edit"]["new_attr"].format( + pusteblume.messages.MESSAGES["tasks"]["edit"]["value"].format( attribute=attr, ), ) @@ -482,12 +482,8 @@ def edit(config, name=None, tags=tuple()): f"UPDATE task SET {attr} = ? WHERE id = ?", (parsed_input.name, task_id), ) + print(Task(parsed_input.name, tags, (None, None)).pprinted_short) if attr == "tag": for tag in parsed_input.tag: _insert_tag(config, tag, task_id) - print( - pusteblume.messages.MESSAGES["tasks"]["edit"]["new_value"].format( - attribute=attr, - value=new_value, - ), - ) + print(Task(name, parsed_input.tag, (None, None)).pprinted_short)