Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with click
#5
Thanks for your reply. But I still don't quite understand the tutorial you referenced. Can you walk me through the example in the following?
#test.py
import click 
def print_version(ctx, param, value):
   if not value or ctx.resilient_parsing:
       return
   click.echo('Version 1.0')
   ctx.exit()

@click.command()
@click.option('--version', is_flag=True, callback=print_version, expose_value=False, is_eager=True)
def main():
   click.echo('Hello world')

if __name__ == '__main__':
   main()
In my example, what will be passed to param and value separately in the callback function print_version?

snippsat
(Oct-09-2016, 08:57 AM)dullboy Wrote: Thanks for your reply. But how are param and value passed to the callback function print_version?
It's explained here.
Quote:Not familiar with click, but as it says, try adding param to the callback signature.
It's pretty impressive,it blows other command line parser out the window :whistle:
Just the fact that click.echo(''),
has full Unicode support and you will get correct output in all OS(also in Windows cmd where Unicode always has been wrong).[/quote]
Reply


Messages In This Thread
Help with click - by dullboy - Oct-09-2016, 07:54 AM
RE: Help with click - by Mekire - Oct-09-2016, 08:11 AM
RE: Help with click - by dullboy - Oct-09-2016, 08:57 AM
RE: Help with click - by snippsat - Oct-09-2016, 03:31 PM
RE: Help with click - by dullboy - Oct-10-2016, 12:32 AM
RE: Help with click - by snippsat - Oct-10-2016, 02:57 PM
RE: Help with click - by dullboy - Oct-10-2016, 04:16 PM
RE: Help with click - by snippsat - Oct-10-2016, 04:45 PM
RE: Help with click - by dullboy - Oct-10-2016, 04:53 PM
RE: Help with click - by Mekire - Oct-10-2016, 06:34 PM
RE: Help with click - by dullboy - Oct-11-2016, 12:30 PM
RE: Help with click - by metulburr - Oct-11-2016, 12:36 PM
RE: Help with click - by dullboy - Oct-11-2016, 12:47 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020