moved ad-hoc to use display

This commit is contained in:
Brian Coca 2015-04-04 15:21:42 -04:00
commit 5531b84360

View file

@ -40,8 +40,12 @@ from ansible.vars import VariableManager
class Cli(object): class Cli(object):
''' code behind bin/ansible ''' ''' code behind bin/ansible '''
def __init__(self): def __init__(self, display=None):
pass
if display is None:
self.display = Display()
else:
self.display = display
def parse(self): def parse(self):
''' create an options parser for bin/ansible ''' ''' create an options parser for bin/ansible '''
@ -105,7 +109,7 @@ class Cli(object):
if options.listhosts: if options.listhosts:
for host in hosts: for host in hosts:
print(' %s' % host.name) self.display(' %s' % host.name)
sys.exit(0) sys.exit(0)
if ((options.module_name == 'command' or options.module_name == 'shell') and not options.module_args): if ((options.module_name == 'command' or options.module_name == 'shell') and not options.module_args):
@ -157,22 +161,17 @@ class Cli(object):
######################################################## ########################################################
if __name__ == '__main__': if __name__ == '__main__':
#callbacks.display("", log_only=True)
#callbacks.display(" ".join(sys.argv), log_only=True) display = Display()
#callbacks.display("", log_only=True) #display.display(" ".join(sys.argv), log_only=True)
try: try:
cli = Cli() cli = Cli(display=display)
(options, args) = cli.parse() (options, args) = cli.parse()
result = cli.run(options, args) sys.exit(cli.run(options, args))
except AnsibleError as e:
except AnsibleError, e: display.display("[ERROR]: %s" % e, color='red', stderr=True)
print(e)
sys.exit(1) sys.exit(1)
except KeyboardInterrupt:
except Exception, e: display.display("[ERROR]: interrupted", color='red', stderr=True)
# Generic handler for errors
print("ERROR: %s" % str(e))
sys.exit(1) sys.exit(1)
sys.exit(result)