diff options
author | Joel Ostblom <joel.ostblom@gmail.com> | 2021-06-05 20:16:19 -0700 |
---|---|---|
committer | Julien Maupetit <jmaupetit@users.noreply.github.com> | 2021-06-09 17:55:32 +0200 |
commit | ca6b6139ea046519c06258d6d107fdc666ed0f83 (patch) | |
tree | 6677c9d5df062c90fbdb7839ca5e169730aad7dc | |
parent | cca74ecc7f825eb3d869b4eb836d4830f06abd53 (diff) |
Add gap/no-gap support for restart command
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | docs/user-guide/commands.md | 4 | ||||
-rw-r--r-- | watson/cli.py | 23 |
3 files changed, 29 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a0cca5..06cec57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- The restart command now accepts the `--gap/--no-gap` options. + ## [2.0.1] - 2021-05-10 ### Fixed diff --git a/docs/user-guide/commands.md b/docs/user-guide/commands.md index 3392b54..35d09a9 100644 --- a/docs/user-guide/commands.md +++ b/docs/user-guide/commands.md @@ -608,12 +608,16 @@ Example: Stopping project apollo11, started a minute ago. (id: e7ccd52) $ watson restart Starting project apollo11 [module, brakes] at 16:36 + +If the `--no-gap` flag is given, the start time of the new project is set +to the stop time of the most recently stopped project. ### Options Flag | Help -----|----- `--at DATETIME` | Start frame at this time. Must be in (YYYY-MM-DDT)?HH:MM(:SS)? format. +`-g, --gap / -G, --no-gap` | (Don't) leave gap between end time of previous project and start time of the current. `-s, --stop / -S, --no-stop` | (Don't) Stop an already running project. `--help` | Show this message and exit. diff --git a/watson/cli.py b/watson/cli.py index 305d1af..5e17552 100644 --- a/watson/cli.py +++ b/watson/cli.py @@ -312,15 +312,20 @@ def stop(watson, at_): @cli.command(context_settings={'ignore_unknown_options': True}) @click.option('--at', 'at_', type=DateTime, default=None, + cls=MutuallyExclusiveOption, mutually_exclusive=['gap_'], help=('Start frame at this time. Must be in ' '(YYYY-MM-DDT)?HH:MM(:SS)? format.')) +@click.option('-g/-G', '--gap/--no-gap', 'gap_', is_flag=True, default=True, + cls=MutuallyExclusiveOption, mutually_exclusive=['at_'], + help=("(Don't) leave gap between end time of previous project " + "and start time of the current.")) @click.option('-s/-S', '--stop/--no-stop', 'stop_', default=None, help="(Don't) Stop an already running project.") @click.argument('frame', default='-1', autocompletion=get_frames) @click.pass_obj @click.pass_context @catch_watson_error -def restart(ctx, watson, frame, stop_, at_): +def restart(ctx, watson, frame, stop_, at_, gap_=True): """ Restart monitoring time for a previously stopped project. @@ -348,12 +353,25 @@ def restart(ctx, watson, frame, stop_, at_): Stopping project apollo11, started a minute ago. (id: e7ccd52) $ watson restart Starting project apollo11 [module, brakes] at 16:36 + + If the `--no-gap` flag is given, the start time of the new project is set + to the stop time of the most recently stopped project. """ if not watson.frames and not watson.is_started: raise click.ClickException( style('error', "No frames recorded yet. It's time to create your " "first one!")) + if watson.is_started and not gap_: + current = watson.current + errmsg = ("Project '{}' is already started and '--no-gap' is passed. " + "Please stop manually.") + raise click.ClickException( + style( + 'error', errmsg.format(current['project']) + ) + ) + if watson.is_started: if stop_ or (stop_ is None and watson.config.getboolean('options', 'stop_on_restart')): @@ -368,7 +386,8 @@ def restart(ctx, watson, frame, stop_, at_): frame = get_frame_from_argument(watson, frame) - _start(watson, frame.project, frame.tags, restart=True, start_at=at_) + _start(watson, frame.project, frame.tags, restart=True, start_at=at_, + gap=gap_) @cli.command() |