cli.py 文件源码

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

项目:solidfire-cli 作者: solidfire 项目源码 文件源码
def type_cast_value(self, ctx, value):
        """Given a value this runs it properly through the type system.
        This automatically handles things like `nargs` and `multiple` as
        well as composite types.
        """
        if self.type.is_composite:
            if self.nargs <= 1:
                raise TypeError('Attempted to invoke composite type '
                                'but nargs has been set to %s.  This is '
                                'not supported; nargs needs to be set to '
                                'a fixed value > 1.' % self.nargs)
            if self.multiple:
                return tuple(self.type(x or (), self, ctx) for x in value or ())
            return self.type(value or (), self, ctx)

        def _convert(value, level):
            if level == 0:
                if value == "":
                    #if self.required and self.is_sub_parameter:
                    #    raise click.BadParameter(self.name+" is a required member of its parameter group. Please provide it inline after the associated superparameter.")
                    return None
                return self.type(value, self, ctx)
            return tuple(_convert(x, level - 1) for x in value or ())
        v = _convert(value, (self.nargs != 1) + bool(self.multiple))
        return _convert(value, (self.nargs != 1) + bool(self.multiple))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号