def ensure_obj(f):
    """A decorator that ensures context.obj exists. If it doesn't,
    a new dict() is created and stored as obj.
    """
    @click.pass_context
    def new_func(ctx, *args, **kwargs):
        if ctx.obj is None:
            ctx.obj = {}
        return ctx.invoke(f, *args, **kwargs)
    return update_wrapper(new_func, f)
def ensure_obj ( f ) : @ click . pass_context def new_func ( ctx , * args , ** kwargs ) : if ctx . obj is None : ctx . obj = { } return ctx . invoke ( f , * args , ** kwargs ) return update_wrapper ( new_func , f )
A decorator that ensures context.obj exists. If it doesn't,
    a new dict() is created and stored as obj.