title: missing 1 required positional argument in click CLI
body: <p>I've written a CLI with click originally as a module and it worked fine. But since my project got bigger I now need to have attributes the CLI can work with, so I tried to turn it into a class, but I'm running into an error doing it. My code is like the following:</p>
  
  <pre><code>import click
  import click_repl
  import os
  from prompt_toolkit.history import FileHistory
  
  class CLI:
      def __init__(self):
          pass
  
      @click.group(invoke_without_command=True)
      @click.pass_context
      def cli(self, ctx):
          if ctx.invoked_subcommand is None:
              ctx.invoke(self.repl)
  
      @cli.command()
      def foo(self):
          print("foo")
  
      @cli.command()
      def repl(self):
          prompt_kwargs = {
              'history': FileHistory(os.path.expanduser('~/.repl_history'))
          }
          click_repl.repl(click.get_current_context(), prompt_kwargs)
  
      def main(self):
          while True:
              try:
                  self.cli(obj={})
              except SystemExit:
                  pass
  
  
  if __name__ == "__main__":
      foo = CLI()
      foo.main()
  </code></pre>
  
  <p>Without all the <code>self</code>s and the <code>class CLI:</code> the CLI is working as expected, but as a class it runs into an error: <code>TypeError: cli() missing 1 required positional argument: 'ctx'</code> I don't understand why this happens. As far as I know calling <code>self.cli()</code> should pass <code>self</code> automatically, thus <code>obj={}</code> should be passed as ctx.obj, so it shouldn't make any difference to <code>cli</code> if it's wrapped in a class or not.</p>
  
  <p>Can someone explain to me, why this happens and more important, how I can fix it?</p>
  
  <p>In case it's relevant here is the complete error stack trace:</p>
  
  <pre><code>Traceback (most recent call last):
      File "C:/Users/user/.PyCharmCE2018.2/config/scratches/exec.py", line 
       37, in &lt;module&gt;
        foo.main()
      File "C:/Users/user/.PyCharmCE2018.2/config/scratches/exec.py", line 
       30, in main
        self.cli(obj={})
      File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site- packages\click\core.py", line 764, in __call__
        return self.main(*args, **kwargs)
      File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\click\core.py", line 717, in main
        rv = self.invoke(ctx)
      File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\click\core.py", line 1114, in invoke
        return Command.invoke(self, ctx)
      File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\click\core.py", line 956, in invoke
        return ctx.invoke(self.callback, **ctx.params)
      File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\click\core.py", line 555, in invoke
        return callback(*args, **kwargs)
      File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\click\decorators.py", line 17, in new_func
        return f(get_current_context(), *args, **kwargs)
  TypeError: cli() missing 1 required positional argument: 'ctx'
  </code></pre>
  
  <p>EDIT: The problem seems to be the <code>pass_context</code> call. Usually <code>pass_context</code> would provide the current context as <strong>first parameter</strong> to the function, so that <code>obj={}</code> would be passed to the context instance. But since I wrapped the click-group into a class, the first spot is taken by the <code>self</code>-reference, so that the current context can't be passed to the function. Any ideas of how to work around that?</p>
  
  <p>I tried changing <code>def cli()</code> the following way:</p>
  
  <pre><code>@click.group(invoke_without_command=True)
  def cli(self):
      ctx = click.get_current_context()
      ctx.obj = {}
      if ctx.invoked_subcommand is None:
          ctx.invoke(self.repl)
  </code></pre>
  
  <p>So I don't pass the context by call avoiding a conflict with <code>self</code>, but if I try to run this with <code>self.cli()</code> error <code>TypeError: cli() missing 1 required positional argument: 'self'</code> happens.
  Calling it with <code>self.cli(self)</code> runs into <code>TypeError: 'CLI' object is not iterable</code></p>