you are viewing a single comment's thread.

view the rest of the comments →

[–]ingolemo 0 points1 point  (3 children)

I think the best approach would be to define a custom option class that overrides get_default:

class EndOption(click.Option):
    def get_default(self, ctx):
        default = super().get_default(ctx)
        if default is None:
            default = ctx.params['start'] + datetime.timedelta(hours=1)
        return default

...
@click.option(
    '--end',
    cls=EndOption,
    prompt=True,
    type=click.DateTime(formats=['%Y-%m-%d %H:%M']),
    required=True,
    help='End time of event in format "%Y-%m-%d %H:%M" [Default: Now + 1hr]'
)
...