Skip to content

Commit 9b782cc

Browse files
committed
feat(runner): add run alias for robot command in cli
1 parent 25cc880 commit 9b782cc

File tree

11 files changed

+73
-13
lines changed

11 files changed

+73
-13
lines changed

.vscode/launch.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,15 @@
5151
"CMD_VAR_LONG": "long",
5252
},
5353
"args": [
54-
"--verbose",
54+
// "--verbose",
5555
// "robot"
5656
// "debug-launch",
5757
// "--pipe-server",
5858
// "\\\\.\\pipe\\926ab05cd224ef08dc3aec29eda1ba61"
59-
"debug",
60-
"--",
61-
"--help"
59+
// "debug",
60+
// "--",
61+
// "--help"
62+
"run"
6263
]
6364
},
6465
{

packages/debugger/src/robotcode/debugger/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
import click
55
from robotcode.core.types import ServerMode
66
from robotcode.plugin import Application, UnknownError, pass_application
7-
from robotcode.plugin.click_helper.helper import (
7+
from robotcode.plugin.click_helper.server_options import resolve_server_options, server_options
8+
from robotcode.plugin.click_helper.types import (
89
AddressesPort,
910
add_options,
1011
)
11-
from robotcode.plugin.click_helper.server_options import resolve_server_options, server_options
1212

1313
from .__version__ import __version__
1414
from .run import run_debugger

packages/debugger/src/robotcode/debugger/launcher/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import click
44
from robotcode.core.types import ServerMode
55
from robotcode.plugin import Application, UnknownError, pass_application
6-
from robotcode.plugin.click_helper.helper import (
6+
from robotcode.plugin.click_helper.server_options import resolve_server_options, server_options
7+
from robotcode.plugin.click_helper.types import (
78
AddressesPort,
89
add_options,
910
)
10-
from robotcode.plugin.click_helper.server_options import resolve_server_options, server_options
1111

1212
from ..__version__ import __version__
1313
from .run import run_launcher
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from typing import Any, Optional, Sequence
2+
3+
import click
4+
5+
6+
class AliasedCommand(click.Command):
7+
def __init__(self, *args: Any, aliases: Sequence[str] = [], **kwargs: Any) -> None:
8+
super().__init__(*args, **kwargs)
9+
self.aliases = aliases
10+
11+
12+
class AliasedGroup(click.Group):
13+
def get_command(self, ctx: click.Context, cmd_name: str) -> Optional[click.Command]:
14+
rv = super().get_command(ctx, cmd_name)
15+
if rv is not None:
16+
return rv
17+
18+
for name, cmd in self.commands.items():
19+
if isinstance(cmd, AliasedCommand) and cmd_name in cmd.aliases:
20+
return cmd
21+
22+
return None
23+
24+
def format_commands(self, ctx: click.Context, formatter: click.HelpFormatter) -> None:
25+
super().format_commands(ctx, formatter)
26+
27+
commands = []
28+
for subcommand in self.list_commands(ctx):
29+
cmd = self.get_command(ctx, subcommand)
30+
if cmd is None:
31+
continue
32+
if cmd.hidden:
33+
continue
34+
35+
if isinstance(cmd, AliasedCommand) and cmd.aliases:
36+
subcommand = f"{', '.join(cmd.aliases)}"
37+
commands.append((subcommand, cmd))
38+
39+
if len(commands):
40+
limit = formatter.width - 6 - max(len(cmd[0]) for cmd in commands)
41+
42+
rows = []
43+
for subcommand, cmd in commands:
44+
help = cmd.get_short_help_str(limit)
45+
rows.append((subcommand, help))
46+
rows.append(("", f"(Alias for `{cmd.name}` command)"))
47+
if rows:
48+
with formatter.section("Aliases"):
49+
formatter.write_dl(rows)

packages/plugin/src/robotcode/plugin/click_helper/server_options.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import click
44
from robotcode.core.types import ServerMode
55
from robotcode.plugin import Application
6-
from robotcode.plugin.click_helper.helper import (
6+
from robotcode.plugin.click_helper.types import (
77
AddressesPort,
88
AddressParamType,
99
AddressPortParamType,
@@ -13,7 +13,7 @@
1313
PortParamType,
1414
)
1515

16-
from .helper import FC
16+
from .types import FC
1717

1818

1919
def server_options(

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from robot.run import USAGE, RobotFramework
88
from robot.version import get_full_version
99
from robotcode.plugin import Application, pass_application
10+
from robotcode.plugin.click_helper.aliases import AliasedCommand
1011
from robotcode.robot.config.loader import load_config_from_path
1112
from robotcode.robot.config.utils import get_config_files
1213

@@ -54,6 +55,8 @@ def main(self, arguments: Any, **options: Any) -> Any:
5455

5556

5657
@click.command(
58+
cls=AliasedCommand,
59+
aliases=["run"],
5760
context_settings={
5861
"allow_extra_args": True,
5962
"ignore_unknown_options": True,
@@ -85,6 +88,11 @@ def robot(
8588
"""Runs `robot` with the selected configuration, profiles, options and arguments.
8689
8790
The options and arguments are passed to `robot` as is.
91+
92+
Examples:
93+
```
94+
robotcode run
95+
```
8896
"""
8997

9098
robot_arguments: Optional[List[Union[str, Path]]] = None

src/robotcode/cli/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
import click
66
from robotcode.core.logging import LoggingDescriptor
77
from robotcode.plugin import Application, ColoredOutput, pass_application
8+
from robotcode.plugin.click_helper.aliases import AliasedGroup
89
from robotcode.plugin.manager import PluginManager
910

1011
from .__version__ import __version__
1112
from .commands import config, profiles
1213

1314

1415
@click.group(
16+
cls=AliasedGroup,
1517
context_settings={"auto_envvar_prefix": "ROBOTCODE"},
1618
invoke_without_command=False,
1719
)

src/robotcode/cli/commands/_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import click
22
from robotcode.plugin import OutputFormat
3-
from robotcode.plugin.click_helper.helper import EnumChoice
3+
from robotcode.plugin.click_helper.types import EnumChoice
44

55
format_option = click.option(
66
"-f",

src/robotcode/cli/commands/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import click
77
from robotcode.core.dataclasses import as_dict, encode_case
88
from robotcode.plugin import Application, OutputFormat, UnknownError, pass_application
9-
from robotcode.plugin.click_helper.helper import add_options
9+
from robotcode.plugin.click_helper.types import add_options
1010
from robotcode.robot.config.loader import (
1111
find_project_root,
1212
load_config_from_path,

0 commit comments

Comments
 (0)