def convert_primitive(ast):
import click
mapping = {
'Int': int,
'Str': str,
'Float': float,
'Color': str,
'Bool': bool
}
# TODO: it would be a good idea to refactor this someday, but until then
# just handle the few predicates we know about.
predicate = ast['predicate']
if predicate:
if predicate['name'] == 'Choices' and ast['name'] == 'Str':
return click.Choice(predicate['choices'])
elif predicate['name'] == 'Range' and ast['name'] == 'Int':
start = predicate['start']
end = predicate['end']
# click.IntRange is always inclusive
if start is not None and not predicate['inclusive-start']:
start += 1
if end is not None and not predicate['inclusive-end']:
end -= 1
return click.IntRange(start, end)
elif predicate['name'] == 'Range' and ast['name'] == 'Float':
# click.FloatRange will be in click 7.0, so for now the
# range handling will just fallback to qiime2.
return mapping['Float']
else:
raise NotImplementedError()
else:
return mapping[ast['name']]
评论列表
文章目录