diff --git a/cd/__init__.py b/cd/__init__.py index 9dd0619..d2b4385 100644 --- a/cd/__init__.py +++ b/cd/__init__.py @@ -6,9 +6,8 @@ from rwx import ps COMMANDS_PREFIX = 'cd-' -environment = os.environ -project = Project(environment) -projects = Projects(environment) +projects = Projects(os.environ) +project = Project(projects) def cd_clone_branch(): @@ -22,7 +21,7 @@ def cd_clone_branch(): def cd_list_environment(): - for variable, value in sorted(environment.items()): + for variable, value in sorted(os.environ.items()): print(variable, '=', value) diff --git a/cd/project.py b/cd/project.py index 4a734c9..b5740e2 100644 --- a/cd/project.py +++ b/cd/project.py @@ -11,12 +11,15 @@ NAME = [ class Project: - def __init__(self, environment): + def __init__(self, projects): + self.projects = projects # branch for variable in BRANCH: - if value := environment.get(variable, None): + if value := projects.environment.get(variable, None): self.branch = value # name for variable in NAME: - if value := environment.get(variable, None): + if value := projects.environment.get(variable, None): self.name = path.basename(value) + # url + self.url = path.join(projects.url, self.name) diff --git a/cd/projects.py b/cd/projects.py index d3b0581..81fe3db 100644 --- a/cd/projects.py +++ b/cd/projects.py @@ -12,11 +12,12 @@ SERVER_URL = [ class Projects: def __init__(self, environment): + self.environment = environment # group, name for variable in GROUP_AND_NAME: - if value := environment.get(variable, None): + if value := self.environment.get(variable, None): self.group, self.name = path.split(value) # url for variable in SERVER_URL: - if value := environment.get(variable, None): + if value := self.environment.get(variable, None): self.url = path.join(value, self.group)