cli.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:fanpy 作者: mookrs 项目源码 文件源码
def parse_args(args):
    options = {}

    short_opts = 'rR:f:l:tdc:h'
    long_opts = ['refresh', 'refresh-rate=',
                 'format=', 'length=', 'timestamp', 'datestamp',
                 'config=', 'oauth=', 'help', 'invert-split', 'force-ansi']
    opts, extra_args = gnu_getopt(args, short_opts, long_opts)
    # decode Non-ASCII args for Python 2
    if extra_args and hasattr(extra_args[0], 'decode'):
        extra_args = [arg.decode(locale.getpreferredencoding()) for arg in extra_args]

    for opt, arg in opts:
        if opt in ('-r', '--refresh'):
            options['refresh'] = True
        elif opt in ('-R', '--refresh-rate'):
            options['refresh-rate'] = int(arg)
        elif opt in ('-f', '--format'):
            options['format'] = arg
        elif opt in ('-l', '--length'):
            options['length'] = int(arg)
        elif opt in ('-t', '--timestamp'):
            options['timestamp'] = True
        elif opt in ('-d', '--datestamp'):
            options['datestamp'] = True
        elif opt in ('-c', '--config'):
            options['config-filename'] = arg
        elif opt == '--oauth':
            options['oauth-filename'] = arg
        elif opt in ('-h', '--help'):
            options['action'] = 'help'
        elif opt == '--invert-split':
            options['invert-split'] = True
        elif opt == '--force-ansi':
            options['force-ansi'] = True

    if extra_args and 'action' not in options:
        options['action'] = extra_args[0]
    options['extra-args'] = extra_args[1:]

    return options
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号