Skip to content

Commit a8fbb22

Browse files
committed
feat: new command discover tags
1 parent f25431f commit a8fbb22

File tree

3 files changed

+74
-7
lines changed

3 files changed

+74
-7
lines changed

.vscode/launch.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"request": "launch",
2121
"module": "robotcode.cli",
2222
"justMyCode": false,
23-
"cwd": "${workspaceFolder}/tests/robotcode/language_server/robotframework/parts/data/tests",
24-
//"cwd": "C:\\develop\\robot\\robotframework",
23+
//"cwd": "${workspaceFolder}/tests/robotcode/language_server/robotframework/parts/data/tests",
24+
"cwd": "C:\\develop\\robot\\robotframework",
2525
// "env": {
2626
// "ROBOTCODE_COLOR": "1",
2727
// },
@@ -46,13 +46,15 @@
4646
".",
4747
//"config", "info", "desc",
4848
"discover",
49-
"all",
50-
"--norpa",
49+
// "all",
50+
// "--norpa",
5151
// "--by-longname", "asd:dasd",
52-
"--suite",
53-
"Data.Tests.Versions.Rf61.a suite with a custom Name"
52+
// "--suite",
53+
// "Data.Tests.Versions.Rf61.a suite with a custom Name"
5454
// "Robotframework.Atest.Testdata.Variables",
5555
//"."
56+
"tags",
57+
"."
5658
]
5759
},
5860
{

packages/runner/src/robotcode/runner/cli/discover/discover.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import re
33
import sys
4+
from collections import defaultdict
45
from dataclasses import dataclass
56
from io import IOBase
67
from pathlib import Path
@@ -177,6 +178,7 @@ def __init__(self) -> None:
177178
self._current = self.all
178179
self.suites: List[TestItem] = []
179180
self.tests: List[TestItem] = []
181+
self.tags: Dict[str, List[TestItem]] = defaultdict(list)
180182
self.statistics = Statistics()
181183

182184
def visit_suite(self, suite: TestSuite) -> None:
@@ -228,6 +230,8 @@ def visit_test(self, test: TestCase) -> None:
228230
),
229231
tags=list(test.tags) if test.tags else None,
230232
)
233+
for tag in test.tags:
234+
self.tags[str(tag)].append(item)
231235

232236
self.tests.append(item)
233237
self._current.children.append(item)
@@ -533,3 +537,64 @@ def print(items: List[TestItem]) -> Iterable[str]:
533537

534538
else:
535539
app.print_data(ResultItem(collector.suites, diagnostics), remove_defaults=True)
540+
541+
542+
@dataclass
543+
class TagsResult:
544+
tags: Dict[str, List[TestItem]]
545+
546+
547+
@discover.command(
548+
context_settings={
549+
"allow_extra_args": True,
550+
"ignore_unknown_options": True,
551+
},
552+
add_help_option=True,
553+
epilog='Use "-- --help" to see `robot` help.',
554+
)
555+
@add_options(*ROBOT_OPTIONS)
556+
@pass_application
557+
def tags(
558+
app: Application,
559+
by_longname: Tuple[str, ...],
560+
exclude_by_longname: Tuple[str, ...],
561+
robot_options_and_args: Tuple[str, ...],
562+
) -> None:
563+
"""\
564+
Discover tags with the selected configuration, profiles, options and
565+
arguments.
566+
567+
\b
568+
Examples:
569+
```
570+
robotcode discover tags
571+
robotcode --profile regression discover tags
572+
573+
robotcode --profile regression discover tags -i wip
574+
```
575+
"""
576+
577+
suite, diagnostics = handle_options(app, by_longname, exclude_by_longname, robot_options_and_args)
578+
579+
collector = Collector()
580+
suite.visit(collector)
581+
582+
if collector.all.children:
583+
if app.config.output_format is None or app.config.output_format == OutputFormat.TEXT:
584+
585+
def print(tags: Dict[str, List[TestItem]]) -> Iterable[str]:
586+
for tag, items in tags.items():
587+
yield f"{tag}{os.linesep}"
588+
# for item in items:
589+
# yield f" {item.longname}{os.linesep}"
590+
# if item.uri:
591+
# yield (
592+
# f" ({Uri(item.uri).to_path()}{f':{item.range.start.line+1}' if item.range else ''})"
593+
# f"{os.linesep}"
594+
# )
595+
596+
if collector.suites:
597+
app.echo_via_pager(print(collector.tags))
598+
599+
else:
600+
app.print_data(TagsResult(collector.tags), remove_defaults=True)

src/robotcode/cli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
@click.option(
6363
"--pager / --no-pager",
6464
"pager",
65-
default=True,
65+
default=False,
6666
help="Whether or not use a pager to display long text or data.",
6767
show_envvar=True,
6868
)

0 commit comments

Comments
 (0)