From 00bb7c2f3ddd75b2b16d1c0ec73cbcb470df7800 Mon Sep 17 00:00:00 2001 From: elbenfreund Date: Mon, 25 Apr 2016 20:03:34 +0200 Subject: [PATCH 1/2] Add '--end' option to 'start' command So far we have implement the client code. Now we have to wait for hamsterlib to implement the backend functionality. Closes #145 --- hamster_cli/hamster_cli.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/hamster_cli/hamster_cli.py b/hamster_cli/hamster_cli.py index 96284eb6..31a608df 100755 --- a/hamster_cli/hamster_cli.py +++ b/hamster_cli/hamster_cli.py @@ -297,22 +297,32 @@ 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 date other than *now* ('%Y-%m-%d')")) @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, '%Y-%m-%d').time + end = datetime.datetime.combine(datetime.date.today(), end_time) + try: fact = controler.facts.stop_tmp_fact() except ValueError: From cd4b024c481cf4a5b7a4bed1baf5f317f10643a4 Mon Sep 17 00:00:00 2001 From: elbenfreund Date: Thu, 8 Dec 2016 09:59:05 +0100 Subject: [PATCH 2/2] Integrate with hamster-lib, fix hint format --- hamster_cli/hamster_cli.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hamster_cli/hamster_cli.py b/hamster_cli/hamster_cli.py index 31a608df..af8cd875 100755 --- a/hamster_cli/hamster_cli.py +++ b/hamster_cli/hamster_cli.py @@ -298,7 +298,7 @@ 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 date other than *now* ('%Y-%m-%d')")) + "Specify an end time other than *now* ('H:M)")) @pass_controler def stop(controler, end): """Stop tracking current fact. Saving the result.""" @@ -320,11 +320,13 @@ def _stop(controler, end=None): ValueError: If ``--end`` was passed but can not be recognized. """ if end: - end_time = datetime.datetime.strptime(end, '%Y-%m-%d').time + 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?"