Article 4QPDT cliff python

cliff python

by
Suraj Patil
from LinuxQuestions.org on (#4QPDT)
hello folk i need help on this

I have to do this task using python cliff module only

I have the following code

Code:import cliff
import logging
from cliff.command import Command

class Name(Command):

def get_parser(self, parsed_args):
parser = super(Name, self).get_parser(parsed_args)
group = parser.add_mutually_exclusive_group()

group.add_argument(
'--firstname',
help = 'print first name',
)

group.add_argument(
'--lastname',
help = 'print last name',
)

group.add_argument(
'--fullname',
help = 'print name',
)

return parser

def take_action(self, parsed_args):

if parsed_args.firstname:
self.app.stdout.write(sys.argv[3].split()[0])

elif parsed_args.lastname:
if ' ' in sys.argv[3]:
last_name = sys.argv[3]
print(last_name.split()[1])
else:
self.app.stdout.write(sys.argv[3].split()[0])
elif parsed_args.fullname:
self.app.stdout.write(sys.argv[3])==============================
expected output

python myapp.py name test user >> print test user

python myapp.py name test user --firstname >> print test

python myapp.py name test user --lastname >> print user

python myapp.py name test user --firstname --lastname >> print error use only firstname or lastname
==============================
till now i have write the code using cliff but it not work as followed

when i execute a code give me blank promptlatest?d=yIl2AUoC8zA latest?i=NQdw5t--C-c:WC7bLUl0VYQ:F7zBnMy latest?i=NQdw5t--C-c:WC7bLUl0VYQ:V_sGLiP latest?d=qj6IDK7rITs latest?i=NQdw5t--C-c:WC7bLUl0VYQ:gIN9vFwNQdw5t--C-c
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