Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#145] Add '--end' option to 'start' command #162

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
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