Skip to content

Commit

Permalink
Prompting when Provider raise RunningEntry exception
Browse files Browse the repository at this point in the history
  • Loading branch information
AuHau committed Jan 21, 2019
1 parent 0129b98 commit 78703bf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ as common configuration for the team working in the repo.

> binary internal storage
Pickled giTrack's state with some level of configuration and
Pickled giTrack's state with some level of configuration and some other data about repos.

## Global configuration

Expand Down
10 changes: 9 additions & 1 deletion gitrack/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import click
import click_completion
import git
import inquirer

from gitrack import helpers, prompt, config as config_module, __version__, exceptions

Expand Down Expand Up @@ -148,7 +149,14 @@ def start(ctx, force):
logger.debug("What does Store things about this repo? Is it currently running?: {}"
.format(ctx.obj['config'].store['running']))
if not ctx.obj['config'].store['running']:
ctx.obj['provider'].start(force)
try:
ctx.obj['provider'].start(force)
except exceptions.RunningEntry:
overwrite = inquirer.shortcuts.confirm('There is currently running time entry that '
'will be overwritten, do you want to continue?', default=False)

if overwrite:
ctx.obj['provider'].start(force=True)


@cli.command(short_help='Stops time tracking')
Expand Down
4 changes: 4 additions & 0 deletions gitrack/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ def __init__(self, provider_name, message, *args, **kwargs):

def __str__(self):
return 'Provider \'{}\': {}'.format(self.provider_name, self.message)


class RunningEntry(ProviderException):
pass
4 changes: 2 additions & 2 deletions gitrack/providers/toggl.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def start(self, force=False):
if current:
logger.info("Currently running entry: " + getattr(current, 'description', ''))
if not force:
raise exceptions.ProviderException(self.NAME, 'There is currently running another '
'time entry which would be overridden!')
raise exceptions.RunningEntry(self.NAME, 'There is currently running another '
'time entry which would be overridden!')

super().start()
api.TimeEntry.start_and_save(created_with='gitrack', config=self.toggl_config,
Expand Down

0 comments on commit 78703bf

Please sign in to comment.