Skip to content

Commit

Permalink
Add '--end' option to 'start' command
Browse files Browse the repository at this point in the history
So far we have implement the client code. Now we have to wait for
hamsterlib to implement the backend functionality.

Closes #145
  • Loading branch information
elbenfreund committed Apr 25, 2016
1 parent be0ca37 commit 3a00977
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions hamster_cli/hamster_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,22 +287,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:
Expand Down

0 comments on commit 3a00977

Please sign in to comment.