Skip to content

Commit 9ed33c9

Browse files
committed
refactor(cli): move --(no)-diagnostic switch to the discover command
1 parent 5f5eae7 commit 9ed33c9

File tree

5 files changed

+32
-37
lines changed

5 files changed

+32
-37
lines changed

packages/plugin/src/robotcode/plugin/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,23 @@ class CommonConfig:
5959
launcher_script: Optional[str] = None
6060
output_format: Optional[OutputFormat] = None
6161
pager: Optional[bool] = None
62+
log_enabled: bool = False
63+
log_level: Optional[str] = None
64+
log_calls: bool = False
6265

6366

6467
class Application:
6568
def __init__(self) -> None:
6669
self.config = CommonConfig()
70+
self._show_diagnostics = True
71+
72+
@property
73+
def show_diagnostics(self) -> bool:
74+
return self._show_diagnostics
75+
76+
@show_diagnostics.setter
77+
def show_diagnostics(self, value: bool) -> None:
78+
self._show_diagnostics = value
6779

6880
@property
6981
def colored(self) -> bool:

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

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -338,14 +338,21 @@ def visit_test(self, test: TestCase) -> None:
338338

339339

340340
@click.group(invoke_without_command=False)
341+
@click.option(
342+
"--diagnostics / --no-diagnostics",
343+
"show_diagnostics",
344+
default=True,
345+
show_default=True,
346+
help="Display `robot` parsing errors and warning that occur during discovering.",
347+
)
341348
@click.option(
342349
"--read-from-stdin",
343350
is_flag=True,
344351
help="Read file contents from stdin. This is an internal option.",
345352
hidden=show_hidden_arguments(),
346353
)
347354
@pass_application
348-
def discover(app: Application, read_from_stdin: bool) -> None:
355+
def discover(app: Application, show_diagnostics: bool, read_from_stdin: bool) -> None:
349356
"""\
350357
Commands to discover informations about the current project.
351358
@@ -356,6 +363,7 @@ def discover(app: Application, read_from_stdin: bool) -> None:
356363
robotcode --profile regression discover tests
357364
```
358365
"""
366+
app.show_diagnostics = show_diagnostics or app.config.log_enabled
359367
if read_from_stdin:
360368
global _stdin_data
361369
_stdin_data = from_json(sys.stdin.buffer.read(), Dict[str, str], strict=True)
@@ -422,7 +430,6 @@ def add_diagnostic(
422430

423431
def handle_options(
424432
app: Application,
425-
diagnostics: bool,
426433
by_longname: Tuple[str, ...],
427434
exclude_by_longname: Tuple[str, ...],
428435
robot_options_and_args: Tuple[str, ...],
@@ -447,7 +454,7 @@ def handle_options(
447454

448455
settings = RobotSettings(options)
449456

450-
if diagnostics:
457+
if app.show_diagnostics:
451458
LOGGER.register_console_logger(**settings.console_output_config)
452459
else:
453460
LOGGER.unregister_console_logger()
@@ -505,17 +512,6 @@ def handle_options(
505512
raise UnknownError("Unexpected error happened.")
506513

507514

508-
DIAGOSTICS_OPTIONS = {
509-
click.option(
510-
"--diagnostics / --no-diagnostics",
511-
"show_diagnostics",
512-
default=True,
513-
show_default=True,
514-
help="Display `robot` parsing errors and warning that occur during discovering.",
515-
)
516-
}
517-
518-
519515
@discover.command(
520516
context_settings={
521517
"allow_extra_args": True,
@@ -524,12 +520,10 @@ def handle_options(
524520
add_help_option=True,
525521
epilog='Use "-- --help" to see `robot` help.',
526522
)
527-
@add_options(*DIAGOSTICS_OPTIONS)
528523
@add_options(*ROBOT_OPTIONS)
529524
@pass_application
530525
def all(
531526
app: Application,
532-
show_diagnostics: bool,
533527
by_longname: Tuple[str, ...],
534528
exclude_by_longname: Tuple[str, ...],
535529
robot_options_and_args: Tuple[str, ...],
@@ -549,9 +543,7 @@ def all(
549543
```
550544
"""
551545

552-
suite, collector, diagnostics = handle_options(
553-
app, show_diagnostics, by_longname, exclude_by_longname, robot_options_and_args
554-
)
546+
suite, collector, diagnostics = handle_options(app, by_longname, exclude_by_longname, robot_options_and_args)
555547

556548
if collector.all.children:
557549
if app.config.output_format is None or app.config.output_format == OutputFormat.TEXT:
@@ -614,12 +606,10 @@ def print(item: TestItem, indent: int = 0) -> Iterable[str]:
614606
show_default=True,
615607
help="Show full paths instead of releative.",
616608
)
617-
@add_options(*DIAGOSTICS_OPTIONS)
618609
@add_options(*ROBOT_OPTIONS)
619610
@pass_application
620611
def tests(
621612
app: Application,
622-
show_diagnostics: bool,
623613
full_paths: bool,
624614
show_tags: bool,
625615
by_longname: Tuple[str, ...],
@@ -641,9 +631,7 @@ def tests(
641631
```
642632
"""
643633

644-
suite, collector, diagnostics = handle_options(
645-
app, show_diagnostics, by_longname, exclude_by_longname, robot_options_and_args
646-
)
634+
suite, collector, diagnostics = handle_options(app, by_longname, exclude_by_longname, robot_options_and_args)
647635

648636
if collector.all.children:
649637
if app.config.output_format is None or app.config.output_format == OutputFormat.TEXT:
@@ -674,12 +662,10 @@ def print(items: List[TestItem]) -> Iterable[str]:
674662
add_help_option=True,
675663
epilog='Use "-- --help" to see `robot` help.',
676664
)
677-
@add_options(*DIAGOSTICS_OPTIONS)
678665
@add_options(*ROBOT_OPTIONS)
679666
@pass_application
680667
def suites(
681668
app: Application,
682-
show_diagnostics: bool,
683669
by_longname: Tuple[str, ...],
684670
exclude_by_longname: Tuple[str, ...],
685671
robot_options_and_args: Tuple[str, ...],
@@ -699,9 +685,7 @@ def suites(
699685
```
700686
"""
701687

702-
suite, collector, diagnostics = handle_options(
703-
app, show_diagnostics, by_longname, exclude_by_longname, robot_options_and_args
704-
)
688+
suite, collector, diagnostics = handle_options(app, by_longname, exclude_by_longname, robot_options_and_args)
705689

706690
if collector.all.children:
707691
if app.config.output_format is None or app.config.output_format == OutputFormat.TEXT:
@@ -751,12 +735,10 @@ class TagsResult:
751735
show_default=True,
752736
help="Show full paths instead of releative.",
753737
)
754-
@add_options(*DIAGOSTICS_OPTIONS)
755738
@add_options(*ROBOT_OPTIONS)
756739
@pass_application
757740
def tags(
758741
app: Application,
759-
show_diagnostics: bool,
760742
normalized: bool,
761743
show_tests: bool,
762744
full_paths: bool,
@@ -780,9 +762,7 @@ def tags(
780762
```
781763
"""
782764

783-
_suite, collector, _diagnostics = handle_options(
784-
app, show_diagnostics, by_longname, exclude_by_longname, robot_options_and_args
785-
)
765+
_suite, collector, _diagnostics = handle_options(app, by_longname, exclude_by_longname, robot_options_and_args)
786766

787767
if collector.all.children:
788768
if app.config.output_format is None or app.config.output_format == OutputFormat.TEXT:

src/robotcode/cli/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ def robotcode(
178178
app.config.output_format = format
179179
app.config.launcher_script = launcher_script
180180
app.config.default_paths = default_path
181+
app.config.log_enabled = log
182+
app.config.log_level = log_level
183+
app.config.log_calls = log_calls
181184

182185
if log:
183186
if log_calls:

vscode-client/languageclientsmanger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,8 @@ export class LanguageClientsManager {
531531
e.newState === State.Starting
532532
? ClientState.Starting
533533
: e.newState === State.Stopped
534-
? ClientState.Stopped
535-
: ClientState.Running,
534+
? ClientState.Stopped
535+
: ClientState.Running,
536536
});
537537
});
538538

vscode-client/testcontrollermanager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ export class TestControllerManager {
622622

623623
const result = await this.discoverTests(
624624
folder,
625-
["discover", "--read-from-stdin", "all"],
625+
["discover", "--no-diagnostics", "--read-from-stdin", "all"],
626626
[],
627627
JSON.stringify(o),
628628
token,

0 commit comments

Comments
 (0)