Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion q2cli/core/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,21 @@ def _special_option_flags(type):
metadata = 'file'
elif expr.name == 'MetadataColumn':
metadata = 'column'
elif expr.name == 'Bool':
elif _is_bool_ast(type.to_ast()):
is_bool_flag = True

return multiple, is_bool_flag, metadata


def _is_bool_ast(ast):
Comment thread
colinvwood marked this conversation as resolved.
Outdated
if ast['type'] == 'expression':
return ast['name'] == 'Bool'
if ast['type'] == 'variable':
Comment thread
colinvwood marked this conversation as resolved.
Outdated
index = ast['index']
return all(_is_bool_ast(row[index]) for row in ast['mapping'])
Comment thread
colinvwood marked this conversation as resolved.
Outdated
return False


def _get_type_repr(type):
import qiime2.sdk.util

Expand Down Expand Up @@ -157,6 +166,8 @@ def _get_metavar(type):
metavar = 'METADATA'
elif style.style is not None and style.style != 'simple':
metavar = 'VALUE'
elif _is_bool_ast(type.to_ast()):
metavar = ''
elif qiime2.sdk.util.is_union(type):
metavar = 'VALUE'
else:
Expand Down
37 changes: 37 additions & 0 deletions q2cli/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,43 @@ def test_action_parameter_types(self):
'10', '--output-dir', output_dir, '--verbose'])
self.assertEqual(result.exit_code, 0)

def test_bool_typemap_parameter_is_flag(self):
qiime_cli = RootCommand()
command = qiime_cli.get_command(ctx=None, name='dummy-plugin')

results = self.runner.invoke(
command, ['bool-flag-swaps-output-method', '--help'])
self.assertEqual(results.exit_code, 0)
self.assertIn('--p-b / --p-no-b', results.output)

input_path = Artifact.import_data(
'Bar', 'element', view_type=str).save(
os.path.join(self.tempdir, 'bar.qza'))
true_output_path = os.path.join(self.tempdir, 'true-output.qza')
false_output_path = os.path.join(self.tempdir, 'false-output.qza')

result = self.runner.invoke(
command, [
'bool-flag-swaps-output-method',
'--i-a', input_path,
'--p-b',
'--o-x', true_output_path,
'--verbose'
])
self.assertEqual(result.exit_code, 0)
self.assertEqual(repr(Artifact.load(true_output_path).type), 'C1[Foo]')

result = self.runner.invoke(
command, [
'bool-flag-swaps-output-method',
'--i-a', input_path,
'--p-no-b',
'--o-x', false_output_path,
'--verbose'
])
self.assertEqual(result.exit_code, 0)
self.assertEqual(repr(Artifact.load(false_output_path).type), 'Foo')

def test_execute_hidden_action(self):
int_path = os.path.join(self.tempdir, 'int.qza')
qiime_cli = RootCommand()
Expand Down
Loading