Setuptools not passing arguments for entry_points

天大地大妈咪最大 提交于 2019-12-04 05:20:27
Jeffrey Harris

The setuptools console_scripts entry point wants a function of no arguments.

Happily, optparse (Parser for command line options) doesn't need to be passed any arguments, it will read in sys.argv[1:] and use that as it's input.

Just to give a full picture of what megazord.py would look like, using @Jeffrey Harris suggestion to use a nice library for parsing the inputs.

import argparse

def main():
    ''' Example of taking inputs for megazord bin'''
    parser = argparse.ArgumentParser(prog='my_megazord_program')
    parser.add_argument('-i', nargs='?', help='help for -i blah')
    parser.add_argument('-d', nargs='?', help='help for -d blah')
    parser.add_argument('-v', nargs='?', help='help for -v blah')
    parser.add_argument('-w', nargs='?', help='help for -w blah')

    args = parser.parse_args()

    collected_inputs = {'i': args.i,
                    'd': args.d,
                    'v': args.v,
                    'w': args.w}
    print 'got input: ', collected_inputs 

And with using it like in the above, one would get

$ megazord -i input -d database -v xx-xx -w yy-yy
got input: {'i': 'input', 'd': 'database', 'w': 'yy-yy', 'v': 'xx-xx'}

And since they are all optional arguments,

$ megazord
got input: {'i': None, 'd': None, 'w': None, 'v': None}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!