Skip to content

Commit 4765d98

Browse files
committed
[FIX] give all arguments to Editor to be able to use them
Before this commit: Overriding the `EditorCommand` to add new parameters/arguments to the command would work. But it would not be accessible from `Editor` class as only the `repository` was given from the args After this commit: Forward to the `Editor` all commands arguments ! This is potentially unstable if `__init__` is overridden by `Editor` subclasses
1 parent 18b9348 commit 4765d98

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# or merged change.
2929
# ------------------------------------------------------------------------------
3030

31-
__version__ = "1.2.3"
31+
__version__ = "1.3.0"
3232

3333
# --- Dependencies -------------------------------------------------------------
3434
# List other odev plugins from which this current plugin depends.

commands/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def run(self):
2121
editor_class = Editor.__subclasses__()[0]
2222

2323
try:
24-
editor = editor_class(self._database, self.args.repository)
24+
editor = editor_class(self._database, self.args)
2525
except ValueError as error:
2626
raise self.error(str(error)) from error
2727

common/editor.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from abc import ABC, abstractmethod
2+
from argparse import Namespace
23
from pathlib import Path
34
from typing import ClassVar, Optional
45

@@ -20,17 +21,21 @@ class Editor(ABC):
2021
_display_name: ClassVar[str]
2122
"""Display name of the code editor."""
2223

23-
def __init__(self, database: DummyDatabase | LocalDatabase, repository: Optional[str] = None):
24+
def __init__(self, database: DummyDatabase | LocalDatabase, cmd_args: Namespace):
2425
"""Initialize the editor with a database or repository.
2526
:param database: The database linked to the project to open in the editor.
26-
:param repository: The repository to open in the editor.
27+
:param cmd_args: Arguments from the `Editor` command.
2728
"""
29+
repository: Optional[str] = cmd_args.repository
2830
if isinstance(database, LocalDatabase) and repository is not None:
2931
raise ValueError("Cannot provide both database and repository")
3032

3133
self.database = database
3234
"""The database linked to the project to open in the editor."""
3335

36+
self.cmd_args = cmd_args
37+
"""The command arguments."""
38+
3439
self.repository: str = "odoo/odoo"
3540
"""The repository to open in the editor."""
3641

0 commit comments

Comments
 (0)