#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
usage: acli [--version] [--help]
            <command> [<args>...]

options:
   -h, --help  help

The most common commands are:
   account      Get account info
   ec2          Manage ec2 instances
   elb          Manage elb instances
   ami          Manage amis
   asg          Manage auto-scaling groups
   lc           Manage launch configurations
   eip          Manage elastic ips
   secgroup     Manage security groups

See 'acli help <command>'
"""

from __future__ import (absolute_import, print_function)
from docopt import docopt
from colorama import init
from acli.services import (ec2, elb, account, cloudwatch, asg)
from acli.config import Config
from acli import utils
init(autoreset=True)


def real_main():
    args = docopt(__doc__,
                  version='0.0.1',
                  options_first=True)
    aws_config = Config(args)
    argv = [args['<command>']] + args['<args>']

    if args['<command>'] == 'account':
        from acli.commands import account as command_account
        # acc_res = docopt(command_account.__doc__, argv=argv)
        account.account_info(aws_config)
    if args['<command>'] == 'ec2':
        from acli.commands import ec2 as command_ec2
        ec2_res = docopt(command_ec2.__doc__, argv=argv)
        if ec2_res.get('list'):
            ec2.ec2_list(aws_config)
        elif ec2_res.get('info'):
            ec2.ec2_info(aws_config, instance_id=ec2_res.get('<instance_id>'))
        elif ec2_res.get('stats'):
            cloudwatch.ec2_stats(aws_config=aws_config, instance_id=ec2_res.get('<instance_id>'))
    if args['<command>'] == 'elb':
        from acli.commands import elb as command_elb
        elb_res = docopt(command_elb.__doc__, argv=argv)
        if elb_res.get('list'):
            elb.elb_list(aws_config)
        elif elb_res.get('info'):
            elb.elb_info(aws_config, elb_name=elb_res.get('<elb_name>'))
    if args['<command>'] == 'elb':
        from acli.commands import elb as command_elb
        elb_res = docopt(command_elb.__doc__, argv=argv)
        if elb_res.get('list'):
            elb.elb_list(aws_config)
        elif elb_res.get('info'):
            elb.elb_info(aws_config, elb_name=elb_res.get('<elb_name>'))
    if args['<command>'] == 'asg':
        from acli.commands import asg as command_asg
        asg_res = docopt(command_asg.__doc__, argv=argv)
        if asg_res.get('list'):
            asg.asg_list(aws_config)
        elif asg_res.get('info'):
            asg.asg_info(aws_config, asg_name=asg_res.get('<asg_name>'))
    elif args['<command>'] in ['help', None] and args['<args>']:
        if args['<args>'][0] == 'ec2':
            from acli.commands import ec2 as command_ec2
            print(docopt(command_ec2.__doc__, argv=argv))
    elif args['<command>'] in ['help', None] and not args['<args>']:
        print("usage: acli help <command>")
    else:
        exit("%r is not an acli command. See 'acli --help'." % args['<command>'])

@@ -1951,35 +1951,35 @@
 %3Ccommand%3E'%5D == '
-elb
+asg
 ':%0A        from 
@@ -1991,35 +1991,35 @@
 commands import 
-elb
+asg
  as command_elb%0A
@@ -2006,35 +2006,35 @@
  asg as command_
-elb
+asg
 %0A        elb_res
@@ -2018,35 +2018,35 @@
 and_asg%0A        
-elb
+asg
 _res = docopt(co
@@ -2043,35 +2043,35 @@
  docopt(command_
-elb
+asg
 .__doc__, argv=a
@@ -2078,35 +2078,35 @@
 rgv)%0A        if 
-elb
+asg
 _res.get('list')
@@ -2111,39 +2111,39 @@
 '):%0A            
-elb.elb
+asg.asg
 _list(aws_config
@@ -2149,35 +2149,35 @@
 g)%0A        elif 
-elb
+asg
 _res.get('info')
@@ -2182,39 +2182,39 @@
 '):%0A            
-elb.elb
+asg.asg
 _info(aws_config
@@ -2211,36 +2211,36 @@
 aws_config, 
-elb
+asg
 _name=
-elb
+asg
 _res.get('%3Ce
@@ -2230,35 +2230,35 @@
 e=asg_res.get('%3C
-elb
+asg
 _name%3E'))%0A    if
@@ -2273,34 +2273,34 @@
 command%3E'%5D == 'a
-sg
+mi
 ':%0A        from 
@@ -2313,34 +2313,34 @@
 ommands import a
-sg
+mi
  as command_asg%0A
@@ -2328,34 +2328,34 @@
 ami as command_a
-sg
+mi
 %0A        asg_res
@@ -2340,34 +2340,34 @@
 nd_ami%0A        a
-sg
+mi
 _res = docopt(co
@@ -2365,34 +2365,34 @@
 docopt(command_a
-sg
+mi
 .__doc__, argv=a
@@ -2400,34 +2400,34 @@
 gv)%0A        if a
-sg
+mi
 _res.get('list')
@@ -2432,39 +2432,39 @@
 '):%0A            
-asg.asg
+ec2.ami
 _list(aws_config
@@ -2471,34 +2471,34 @@
 )%0A        elif a
-sg
+mi
 _res.get('info')
@@ -2503,39 +2503,39 @@
 '):%0A            
-asg.asg
+ec2.ami
 _info(aws_config
@@ -2533,35 +2533,33 @@
 ws_config, a
-sg_name=asg
+mi_id=ami
 _res.get('%3Ca
@@ -2550,39 +2550,37 @@
 =ami_res.get('%3Ca
-sg_name
+mi_id
 %3E'))%0A    elif ar

remove duplicate elb section.