Skip to content

Commit add4102

Browse files
committed
feat: --root command line argument to specify a project root and disable autodetection of project root
closes #201
1 parent 27d21b5 commit add4102

File tree

12 files changed

+43
-12
lines changed

12 files changed

+43
-12
lines changed

packages/analyze/src/robotcode/analyze/cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
def analyze(app: Application, paths: Tuple[str]) -> Union[str, int, None]:
2727
"""TODO: Analyzes a Robot Framework project."""
2828

29-
config_files, root_folder, _ = get_config_files(paths, app.config.config_files, verbose_callback=app.verbose)
29+
config_files, root_folder, _ = get_config_files(
30+
paths, app.config.config_files, root_folder=app.config.root, verbose_callback=app.verbose
31+
)
3032

3133
try:
3234
robot_config = load_robot_config_from_path(

packages/language_server/src/robotcode/language_server/cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ def language_server(
8282
profile: Optional[RobotBaseProfile] = None
8383
analysis_config: Optional[WorkspaceAnalysisConfig] = None
8484

85-
config_files, root_folder, _ = get_config_files(paths, app.config.config_files, verbose_callback=app.verbose)
85+
config_files, root_folder, _ = get_config_files(
86+
paths, app.config.config_files, root_folder=app.config.root, verbose_callback=app.verbose
87+
)
8688
if root_folder:
8789
os.chdir(root_folder)
8890

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __str__(self) -> str:
6464
class CommonConfig:
6565
config_files: Optional[Sequence[Path]] = None
6666
profiles: Optional[Sequence[str]] = None
67+
root: Optional[Path] = None
6768
dry: bool = False
6869
verbose: bool = False
6970
colored_output: ColoredOutput = ColoredOutput.AUTO

packages/robot/src/robotcode/robot/config/loader.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class DiscoverdBy(str, Enum):
2828
LOCAL_ROBOT_TOML = ".robot.toml (local file)"
2929
USER_DEFAULT_CONFIG_TOML = "robot.toml (user default config)"
3030
NOT_FOUND = "not found"
31+
COMMAND_LINE = "command line"
3132

3233

3334
class ConfigType(str, Enum):
@@ -191,7 +192,12 @@ def load_robot_config_from_path(
191192

192193
def find_project_root(
193194
*sources: Union[str, Path],
195+
root_folder: Optional[Path] = None,
194196
) -> Tuple[Optional[Path], DiscoverdBy]:
197+
198+
if root_folder:
199+
return root_folder.absolute(), DiscoverdBy.COMMAND_LINE
200+
195201
if not sources:
196202
sources = (str(Path.cwd().absolute()),)
197203

packages/robot/src/robotcode/robot/config/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ def get_user_config_file(
4343
def get_config_files(
4444
paths: Optional[Sequence[Union[str, Path]]] = None,
4545
config_files: Optional[Sequence[Path]] = None,
46+
root_folder: Optional[Path] = None,
4647
*,
4748
verbose_callback: Optional[Callable[[str], None]] = None,
4849
) -> Tuple[Sequence[Tuple[Path, ConfigType]], Optional[Path], DiscoverdBy]:
49-
root_folder, discovered_by = find_project_root(*(paths or []))
50+
root_folder, discovered_by = find_project_root(*(paths or []), root_folder=root_folder)
5051

5152
if root_folder is None:
5253
root_folder = Path.cwd()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def libdoc(app: Application, robot_options_and_args: Tuple[str, ...]) -> None:
6767
pass
6868

6969
config_files, root_folder, _ = get_config_files(
70-
robot_arguments, app.config.config_files, verbose_callback=app.verbose
70+
robot_arguments, app.config.config_files, root_folder=app.config.root, verbose_callback=app.verbose
7171
)
7272
try:
7373
profile = (

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def rebot(app: Application, robot_options_and_args: Tuple[str, ...]) -> None:
6868
pass
6969

7070
config_files, root_folder, _ = get_config_files(
71-
robot_arguments, app.config.config_files, verbose_callback=app.verbose
71+
robot_arguments, app.config.config_files, root_folder=app.config.root, verbose_callback=app.verbose
7272
)
7373

7474
try:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def handle_robot_options(
255255
sys.path = old_sys_path
256256

257257
config_files, root_folder, _ = get_config_files(
258-
robot_arguments, app.config.config_files, verbose_callback=app.verbose
258+
robot_arguments, app.config.config_files, root_folder=app.config.root, verbose_callback=app.verbose
259259
)
260260
try:
261261
profile = (

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def testdoc(app: Application, robot_options_and_args: Tuple[str, ...]) -> None:
6767
pass
6868

6969
config_files, root_folder, _ = get_config_files(
70-
robot_arguments, app.config.config_files, verbose_callback=app.verbose
70+
robot_arguments, app.config.config_files, root_folder=app.config.root, verbose_callback=app.verbose
7171
)
7272

7373
try:

src/robotcode/cli/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@
4949
If not specified, the default profile is used.
5050
""",
5151
)
52+
@click.option(
53+
"-r",
54+
"--root",
55+
"root",
56+
type=click.Path(exists=True, path_type=Path, dir_okay=True, file_okay=False, resolve_path=True),
57+
multiple=False,
58+
show_envvar=True,
59+
help="Specifies the root path to be used for the project. It will be automatically detected if not provided.",
60+
)
5261
@click.option(
5362
"-f",
5463
"--format",
@@ -176,6 +185,7 @@ def robotcode(
176185
app: Application,
177186
config_files: Optional[List[Path]],
178187
profiles: Optional[List[str]],
188+
root: Optional[Path],
179189
format: Optional[OutputFormat],
180190
dry: bool,
181191
verbose: bool,
@@ -207,6 +217,7 @@ def robotcode(
207217
app.config.profiles = profiles
208218
app.config.dry = dry
209219
app.config.verbose = verbose
220+
app.config.root = root
210221

211222
if color is None:
212223
app.config.colored_output = ColoredOutput.AUTO

0 commit comments

Comments
 (0)