diff --git a/planemo/commands/cmd_lint.py b/planemo/commands/cmd_lint.py index 71ae9564d..d643ec936 100644 --- a/planemo/commands/cmd_lint.py +++ b/planemo/commands/cmd_lint.py @@ -10,21 +10,21 @@ @click.command('lint') -@options.optional_tools_arg() +@options.optional_tools_arg(-1) @options.report_level_option() @options.fail_level_option() @options.skip_option() @options.lint_xsd_option() @options.recursive_option() @pass_context -def cli(ctx, path, **kwds): +def cli(ctx, paths, **kwds): """Check specified tool(s) for common errors and adherence to best practices. """ lint_args = build_lint_args(ctx, **kwds) exit = lint_tools_on_path( ctx, - path, + paths, lint_args, recursive=kwds["recursive"] ) diff --git a/planemo/options.py b/planemo/options.py index 3f50c0159..d6dec3b30 100644 --- a/planemo/options.py +++ b/planemo/options.py @@ -133,7 +133,7 @@ def required_tool_arg(): return click.argument('path', metavar="TOOL_PATH", type=arg_type) -def optional_tools_arg(): +def optional_tools_arg(multiple=False): """ Decorate click method as optionally taking in the path to a tool or directory of tools. If no such argument is given the current working directory will be treated as a directory of tools. @@ -145,11 +145,14 @@ def optional_tools_arg(): readable=True, resolve_path=True, ) + name = 'paths' if multiple else 'path' + nargs = -1 if multiple else 1 return click.argument( - 'path', + name, metavar="TOOL_PATH", default=".", - type=arg_type + type=arg_type, + nargs=nargs, ) diff --git a/planemo/tool_lint.py b/planemo/tool_lint.py index 385fe634b..0443ccdff 100644 --- a/planemo/tool_lint.py +++ b/planemo/tool_lint.py @@ -13,18 +13,19 @@ SHED_FILES = ["tool_dependencies.xml", "repository_dependencies.xml"] -def lint_tools_on_path(ctx, path, lint_args, **kwds): +def lint_tools_on_path(ctx, paths, lint_args, **kwds): assert_tools = kwds.get("assert_tools", True) recursive = kwds.get("recursive", False) exit = 0 valid_tools = 0 - for (tool_path, tool_xml) in yield_tool_xmls(ctx, path, recursive): - info("Linting tool %s" % tool_path) - if not lint_xml(tool_xml, **lint_args): - error("Failed linting") - exit = 1 - else: - valid_tools += 1 + for path in paths: + for (tool_path, tool_xml) in yield_tool_xmls(ctx, path, recursive): + info("Linting tool %s" % tool_path) + if not lint_xml(tool_xml, **lint_args): + error("Failed linting") + exit = 1 + else: + valid_tools += 1 if exit == 0 and valid_tools == 0 and assert_tools: exit = 2 return exit diff --git a/tests/test_lint.py b/tests/test_lint.py index 1f45bea9e..af8d26a92 100644 --- a/tests/test_lint.py +++ b/tests/test_lint.py @@ -22,6 +22,15 @@ def test_fail_tools(self): lint_cmd = ["lint", fail_tool] self._check_exit_code(lint_cmd, exit_code=1) + def test_lint_multiple(self): + names = ["fail_citation.xml", "fail_order.xml"] + paths = list(map(lambda p: os.path.join(TEST_TOOLS_DIR, p), names)) + self._check_exit_code(["lint"] + paths, exit_code=1) + self._check_exit_code( + ["lint", "--skip", "citations,xml_order"] + paths, + exit_code=0 + ) + def test_skips(self): fail_citation = os.path.join(TEST_TOOLS_DIR, "fail_citation.xml") lint_cmd = ["lint", fail_citation]