Skip to content

Commit

Permalink
read configuration from custom path
Browse files Browse the repository at this point in the history
  • Loading branch information
atarutin committed Aug 28, 2023
1 parent cc8502d commit 234eb4d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 7 additions & 3 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@
from typing import Any


class Config:
class Config: # pylint: disable=too-few-public-methods
"""
Configuration for the application
"""

DEFAULT_CONFIG_PATH = "config.json"

data: dict[str, Any]
_instance = None

def __new__(cls):
def __new__(cls, config_path: str = DEFAULT_CONFIG_PATH):
# Singleton pattern
if cls._instance is None:
cls._instance = super(Config, cls).__new__(cls)
with open("config.json", encoding="utf-8") as file:
if not config_path:
config_path = cls.DEFAULT_CONFIG_PATH
with open(config_path, encoding="utf-8") as file:
cls._instance.data = json.load(file)
return cls._instance
12 changes: 11 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,19 @@ def choose_component_from_release(rel: NovaRelease) -> Optional[NovaComponent]:
""",
)

parser.add_argument(
"--config-path",
type=str,
required=False,
help="""
The path to configuration file, optional.
If not specified, the config.json file in the current directory will be used.
""",
)

args = parser.parse_args()

config = Config()
config = Config(args.config_path)

ji = JiraIntegration(
config.data["jira"]["host"],
Expand Down

0 comments on commit 234eb4d

Please sign in to comment.