88from robot .run import USAGE , RobotFramework
99from robot .version import get_full_version
1010
11+ import robotcode .modifiers
1112from robotcode .plugin import Application , pass_application
1213from robotcode .plugin .click_helper .aliases import AliasedCommand
1314from robotcode .plugin .click_helper .types import add_options
@@ -25,13 +26,17 @@ def __init__(
2526 paths : List [str ],
2627 dry : bool ,
2728 root_folder : Optional [Path ],
29+ by_longname : Tuple [str , ...] = (),
30+ exclude_by_longname : Tuple [str , ...] = (),
2831 ) -> None :
2932 super ().__init__ ()
3033 self .app = app
3134 self .paths = paths
3235 self .dry = dry
3336 self .root_folder = root_folder
3437 self ._orig_cwd = Path .cwd ()
38+ self .by_longname = by_longname
39+ self .exclude_by_longname = exclude_by_longname
3540
3641 def parse_arguments (self , cli_args : Any ) -> Any :
3742 if self .root_folder is not None and Path .cwd () != self .root_folder :
@@ -61,6 +66,18 @@ def parse_arguments(self, cli_args: Any) -> Any:
6166 f'{ line_end .join ((* (f"{ k } = { v !r} " for k , v in options .items ()), * arguments ))} '
6267 )
6368
69+ modifiers = []
70+ root_name = options .get ("name" , None )
71+
72+ if self .by_longname :
73+ modifiers .append (robotcode .modifiers .ByLongName (* self .by_longname , root_name = root_name ))
74+
75+ if self .exclude_by_longname :
76+ modifiers .append (robotcode .modifiers .ExcludedByLongName (* self .exclude_by_longname , root_name = root_name ))
77+
78+ if modifiers :
79+ options ["prerunmodifier" ] = options .get ("prerunmodifier" , []) + modifiers
80+
6481 return options , arguments
6582
6683
@@ -90,10 +107,7 @@ def parse_arguments(self, cli_args: Any) -> Any:
90107
91108
92109def handle_robot_options (
93- app : Application ,
94- by_longname : Tuple [str , ...],
95- exclude_by_longname : Tuple [str , ...],
96- robot_options_and_args : Tuple [str , ...],
110+ app : Application , robot_options_and_args : Tuple [str , ...]
97111) -> Tuple [Optional [Path ], RobotBaseProfile , List [str ]]:
98112 robot_arguments : Optional [List [Union [str , Path ]]] = None
99113 old_sys_path = sys .path .copy ()
@@ -118,20 +132,6 @@ def handle_robot_options(
118132
119133 cmd_options = profile .build_command_line ()
120134
121- if by_longname :
122- sep = ";" if any (True for l in by_longname if ":" in l ) else ":"
123- cmd_options += (
124- "--prerunmodifier" ,
125- f"robotcode.modifiers.ByLongName{ sep } { sep .join (by_longname )} " ,
126- )
127-
128- if exclude_by_longname :
129- sep = ";" if any (True for l in exclude_by_longname if ":" in l ) else ":"
130- cmd_options += (
131- "--prerunmodifier" ,
132- f"robotcode.modifiers.ExcludedByLongName{ sep } { sep .join (exclude_by_longname )} " ,
133- )
134-
135135 app .verbose (
136136 lambda : "Executing robot with following options:\n "
137137 + " " .join (f'"{ o } "' for o in (cmd_options + list (robot_options_and_args )))
@@ -170,9 +170,7 @@ def robot(
170170 ```
171171 """
172172
173- root_folder , profile , cmd_options = handle_robot_options (
174- app , by_longname , exclude_by_longname , robot_options_and_args
175- )
173+ root_folder , profile , cmd_options = handle_robot_options (app , robot_options_and_args )
176174
177175 app .exit (
178176 cast (
@@ -186,6 +184,8 @@ def robot(
186184 ),
187185 app .config .dry ,
188186 root_folder ,
187+ by_longname ,
188+ exclude_by_longname ,
189189 ).execute_cli ((* cmd_options , * robot_options_and_args ), exit = False ),
190190 )
191191 )
0 commit comments