1

I'm trying to learn using the module click to create CLI arguments parsing, and wanted to try something different from Argparse.

However, I tried to follow the official documentation, youtube examples and so forth and click just ignores anything I throw at it.

I've tried on Ubuntu 16.04 and Mac OSX, using:

[Python Version]
Python 2.7.13 :: Anaconda custom (x86_64)
[Click Version]
Version: 6.7

This is the code (copied from a tutorial):

import click

@click.command()
@click.option('--verbose', is_flag=True, help="Will print verbose messages.")
def cli(verbose):
    if verbose:
        click.echo("We are in the verbose mode.")
    click.echo("Hello World")

When I run it... nothing happens. No error. Just nothing. What can be wrong? I installed click using "pip install click", and tried on two OS'es.

screen

Community
  • 1
  • 1
Raker
  • 344
  • 2
  • 6
  • 15

1 Answers1

3

Add

if __name__ == '__main__':
    cli()

Otherwise all you've done is defined a function and then done nothing with it. Your answer is right there in the first example in the documentation :)

Iguananaut
  • 21,810
  • 5
  • 50
  • 63
  • 1
    Wow, thanks! That was fast and basic. I will accept this as the answer, as soon as stack allows me (10mins wait). :) – Raker Oct 21 '17 at 13:11
  • Since it seems you're new to Python you'll probably also want to see the answers to this question: https://stackoverflow.com/questions/419163/what-does-if-name-main-do – Iguananaut Oct 21 '17 at 13:14