Skip to content

Commit

Permalink
refactor: cleaned up subcommand messages
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalinDe committed Mar 14, 2024
1 parent 5edfd03 commit 3ba0d53
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
15 changes: 8 additions & 7 deletions pusteblume/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
20 changes: 8 additions & 12 deletions pusteblume/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)
)
Expand All @@ -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,
),
)
Expand All @@ -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)

0 comments on commit 3ba0d53

Please sign in to comment.