Skip to content

Commit

Permalink
chore: make selection of org / project in cli case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
netomi committed Nov 29, 2024
1 parent af907ea commit ecb5de4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion otterdog/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def complete_organizations(ctx, param, incomplete):
try:
config = OtterdogConfig.from_file(config_file, False)
out = []
for org in config.organization_configs:
for org in config.organization_names + config.project_names:
if incomplete in org:
out.append(CompletionItem(org))
return out
Expand Down
17 changes: 8 additions & 9 deletions otterdog/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ def __init__(self, config_file: str, local_mode: bool, working_dir: str | None =
for org in organizations:
org_config = OrganizationConfig.from_dict(org, self)
self._organizations.append(org_config)
self._organizations_map[org_config.name] = org_config
self._organizations_map[org_config.github_id] = org_config
self._organizations_map[org_config.name.lower()] = org_config
self._organizations_map[org_config.github_id.lower()] = org_config

@property
def config_file(self) -> str:
Expand Down Expand Up @@ -205,9 +205,8 @@ def default_base_template(self) -> str:
)
return base_template

@property
def organization_configs(self) -> dict[str, OrganizationConfig]:
return self._organizations_map
def _get_organization_config(self, project_or_organization_name: str):
return self._organizations_map[project_or_organization_name.lower()]

@property
def project_names(self) -> list[str]:
Expand All @@ -218,14 +217,14 @@ def organization_names(self) -> list[str]:
return [config.github_id for config in self._organizations]

def get_project_name(self, github_id: str) -> str | None:
organization = self._organizations_map.get(github_id)
if organization is not None:
return organization.name
org_config = self._get_organization_config(github_id)
if org_config is not None:
return org_config.name
else:
return None

def get_organization_config(self, project_or_organization_name: str) -> OrganizationConfig:
org_config = self._organizations_map.get(project_or_organization_name)
org_config = self._get_organization_config(project_or_organization_name)
if org_config is None:
raise RuntimeError(f"unknown organization with name / github_id '{project_or_organization_name}'")
return org_config
Expand Down

0 comments on commit ecb5de4

Please sign in to comment.