Article 4Q8QV click python example

click python example

by
Suraj Patil
from LinuxQuestions.org on (#4Q8QV)
Hello folk need help
using python click module only
=========================================
[python]
import click

@click.group(chain=True)
def cli():
pass

@cli.command('name')
@click.argument('name1', nargs=-1)
@click.option('--firstname', is_flag=True)
@click.option('--lastname', is_flag=True)
def name(name1, firstname, lastname):

# import pdb; pdb.set_trace()
first, last = name1.split()
if firstname:
click.echo(first)
elif lastname:
click.echo(last)

if __name__ == '__main__':
cli()

[\python]
==========================
expected output like
python foo.py name firstname lastname >> print firstname + lastname

python foo.py name firstname lastname --firstname >> it will print firstname

same for the lastnamelatest?d=yIl2AUoC8zA latest?i=pZ_IAzTnAYo:vUOCi0N5v3s:F7zBnMy latest?i=pZ_IAzTnAYo:vUOCi0N5v3s:V_sGLiP latest?d=qj6IDK7rITs latest?i=pZ_IAzTnAYo:vUOCi0N5v3s:gIN9vFwpZ_IAzTnAYo
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments