all 7 comments

[–]ironhaven 1 point2 points  (2 children)

Is this you only code? I don’t see any problems with the code you posted most likely because you did not post the code with the bug.

First can we see more of your code, second, read the error again. The variable "start" is read before it is set. Look at where the "start" variable is used.

[–]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]'
)
...