Insert or upgrade a mapping from an alias command name to the canonical source. Used for both symlinks and content-identical files (e.g. cross-compiler variants). If a mapping already exists with a lower score (e.g. lexgrog alias at score 1), upgrades it to score 10 since the alias nam
(
s: store.Store,
gz_path: str,
alias_source: str,
canonical_source: str,
)
| 325 | |
| 326 | |
| 327 | def _add_alias_mapping( |
| 328 | s: store.Store, |
| 329 | gz_path: str, |
| 330 | alias_source: str, |
| 331 | canonical_source: str, |
| 332 | ) -> bool: |
| 333 | """Insert or upgrade a mapping from an alias command name to the canonical source. |
| 334 | |
| 335 | Used for both symlinks and content-identical files (e.g. cross-compiler |
| 336 | variants). If a mapping already exists with a lower score (e.g. lexgrog |
| 337 | alias at score 1), upgrades it to score 10 since the alias name is the |
| 338 | primary command name. |
| 339 | |
| 340 | Returns True if a mapping was inserted or upgraded, False if unchanged. |
| 341 | """ |
| 342 | from explainshell import manpage |
| 343 | |
| 344 | alias_name = manpage.extract_name(gz_path) |
| 345 | existing_score = s.mapping_score(alias_name, canonical_source) |
| 346 | if existing_score is not None and existing_score >= 10: |
| 347 | logger.debug( |
| 348 | "alias mapping %s -> %s already exists (score %d)", |
| 349 | alias_name, |
| 350 | canonical_source, |
| 351 | existing_score, |
| 352 | ) |
| 353 | return False |
| 354 | if existing_score is not None: |
| 355 | # Upgrade score from lower value (e.g. lexgrog alias at score 1). |
| 356 | s.update_mapping_score(alias_name, canonical_source, score=10) |
| 357 | logger.info( |
| 358 | "upgraded alias mapping %s -> %s score %d -> 10", |
| 359 | alias_source, |
| 360 | canonical_source, |
| 361 | existing_score, |
| 362 | ) |
| 363 | else: |
| 364 | s.add_mapping(alias_name, canonical_source, score=10) |
| 365 | logger.info( |
| 366 | "mapped alias %s -> %s (name: %s)", |
| 367 | alias_source, |
| 368 | canonical_source, |
| 369 | alias_name, |
| 370 | ) |
| 371 | return True |
| 372 | |
| 373 | |
| 374 | # --------------------------------------------------------------------------- |
no test coverage detected