diff --git a/hamster_cli/hamster_cli.py b/hamster_cli/hamster_cli.py index 96284eb6..af8cd875 100755 --- a/hamster_cli/hamster_cli.py +++ b/hamster_cli/hamster_cli.py @@ -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?"