Search code examples
pythonpython-click

Unexpected indent on main method


I can't see anywhere where there is extra whitespace or unnecessary indenting in this. This is beyond frusterating. Can someone please tell me what I'm doing wrong:

def main():
    """ This is a simple EC2 Command line tool"""
    @click.group()
    @click.option('--ami', default='ami-0de7daa7385332688', help='What AWS AMI are you using?')
    @click.option('--instancetype', default='t2.micro', help='AWS EC2 instance type')
    @click.option('--vpc', help='VPC ID')
    @click.option('--isweb',default=True,help='Is this a web server')


if __name__ == "__main__":
    main()

Solution

  • Decorators are specified before the class/method/function definition, see the documentation.

    So in your case:

    @click.group()
    @click.option('--ami', default='ami-0de7daa7385332688', help='What AWS AMI are you using?')
    @click.option('--instancetype', default='t2.micro', help='AWS EC2 instance type')
    @click.option('--vpc', help='VPC ID')
    @click.option('--isweb',default=True,help='Is this a web server')
    def main():
    """ This is a simple EC2 Command line tool"""
        pass
    
    
    if __name__ == "__main__":
        main()