title: How can I create a continuous / infinite CLI with Click?
body: <p>I'm trying to use <a href="https://click.palletsprojects.com/en/7.x/python3/" rel="nofollow noreferrer">Click</a> to create a CLI for my Python 3 app. Basically I need the app to run continuously, waiting for user commands and executing them, and quitting if a specific command (say, "q") is entered. Couldn't find an example in Click docs or elsewhere.</p>
  
  <p>An example of interactive shell would be like this:</p>
  
  <pre><code>myapp.py
  &gt; PLEASE ENTER LOGIN: 
  mylogin
  &gt; PLEASE ENTER PASSWORD:
  mypwd
  &gt; ENTER COMMAND: 
  a
  &gt; Wrong command! 
  &gt; USAGE: COMMAND [q|s|t|w|f] OPTIONS ARGUMENTS
  &gt; ENTER COMMAND:
  f
  &gt; (output of "f" command...)
  &gt; ENTER COMMAND:
  q
  &gt; QUITTING APP...
  </code></pre>
  
  <p>I've tried like so:</p>
  
  <pre class="lang-py prettyprint-override"><code>import click
  
  quitapp = False # global flag
  
  @click.group()
  def cli():
      pass
  
  @cli.command(name='c')
  @click.argument('username')
  def command1(uname):
      pass # do smth
  
  # other commands...
  
  @cli.command(name='q')
  def quitapp():
      global quitapp
      quitapp = True
  
  def main():    
      while not quitapp:
          cli()
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>But the console just runs the app once all the same.</p>