Skip to content

Commit 3a00977

Browse files
committed
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
1 parent be0ca37 commit 3a00977

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

hamster_cli/hamster_cli.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,22 +287,32 @@ def _start(controler, raw_fact, start, end):
287287

288288

289289
@run.command(help=help_strings.STOP_HELP)
290+
@click.option('--end', nargs=1, default=None, help=_(
291+
"Specify an end date other than *now* ('%Y-%m-%d')"))
290292
@pass_controler
291-
def stop(controler):
293+
def stop(controler, end):
292294
"""Stop tracking current fact. Saving the result."""
293-
_stop(controler)
295+
_stop(controler, end)
294296

295297

296-
def _stop(controler):
298+
def _stop(controler, end=None):
297299
"""
298300
Stop cucrrent 'ongoing fact' and save it to the backend.
299301
302+
Args:
303+
end (str, optional): Adjusted end time of the fact. Defaults to ``now``.
304+
300305
Returns:
301306
None: If successful.
302307
303308
Raises:
304309
ValueError: If no *ongoing fact* can be found.
310+
ValueError: If ``--end`` was passed but can not be recognized.
305311
"""
312+
if end:
313+
end_time = datetime.datetime.strptime(end, '%Y-%m-%d').time
314+
end = datetime.datetime.combine(datetime.date.today(), end_time)
315+
306316
try:
307317
fact = controler.facts.stop_tmp_fact()
308318
except ValueError:

0 commit comments

Comments
 (0)