Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions hamster_cli/hamster_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,24 +297,36 @@ def _start(controler, raw_fact, start, end):


@run.command(help=help_strings.STOP_HELP)
@click.option('--end', nargs=1, default=None, help=_(
"Specify an end time other than *now* ('H:M)"))
@pass_controler
def stop(controler):
def stop(controler, end):
"""Stop tracking current fact. Saving the result."""
_stop(controler)
_stop(controler, end)


def _stop(controler):
def _stop(controler, end=None):
"""
Stop cucrrent 'ongoing fact' and save it to the backend.

Args:
end (str, optional): Adjusted end time of the fact. Defaults to ``now``.

Returns:
None: If successful.

Raises:
ValueError: If no *ongoing fact* can be found.
ValueError: If ``--end`` was passed but can not be recognized.
"""
if end:
end_time = datetime.datetime.strptime(end, '%H:%M').time()
end = datetime.datetime.combine(datetime.date.today(), end_time)
else:
end = None

try:
fact = controler.facts.stop_tmp_fact()
fact = controler.facts.stop_tmp_fact(end_hint=end)
except ValueError:
message = _(
"Unable to continue temporary fact. Are you sure there is one?"
Expand Down