Return a sorted mapping of {CLI option: pretty value string} for the `ctx` Click.context, putting arguments first then options: {"input": ~/some/path, "--license": True} Skip options that are not set or hidden. If `generic_paths` is True, click.File and click.Path paramete
(ctx, generic_paths=False)
| 1682 | |
| 1683 | |
| 1684 | def get_pretty_params(ctx, generic_paths=False): |
| 1685 | """ |
| 1686 | Return a sorted mapping of {CLI option: pretty value string} for the `ctx` |
| 1687 | Click.context, putting arguments first then options: |
| 1688 | |
| 1689 | {"input": ~/some/path, "--license": True} |
| 1690 | |
| 1691 | Skip options that are not set or hidden. |
| 1692 | If `generic_paths` is True, click.File and click.Path parameters are made |
| 1693 | "generic" replacing their value with a placeholder. This is used mostly for |
| 1694 | testing. |
| 1695 | """ |
| 1696 | |
| 1697 | if TRACE: |
| 1698 | logger_debug('get_pretty_params: generic_paths', generic_paths) |
| 1699 | args = [] |
| 1700 | options = [] |
| 1701 | |
| 1702 | param_values = ctx.params |
| 1703 | for param in ctx.command.params: |
| 1704 | name = param.name |
| 1705 | value = param_values.get(name) |
| 1706 | |
| 1707 | if param.is_eager: |
| 1708 | continue |
| 1709 | # This attribute is not yet in Click 6.7 but in head |
| 1710 | if getattr(param, 'hidden', False): |
| 1711 | continue |
| 1712 | |
| 1713 | if value == param.default: |
| 1714 | continue |
| 1715 | if value is None: |
| 1716 | continue |
| 1717 | if value in (tuple(), [],): |
| 1718 | # option with multiple values, the value is a tuple |
| 1719 | continue |
| 1720 | |
| 1721 | if isinstance(param.type, click.Path) and generic_paths: |
| 1722 | value = '<path>' |
| 1723 | |
| 1724 | if isinstance(param.type, click.File): |
| 1725 | if generic_paths: |
| 1726 | value = '<file>' |
| 1727 | else: |
| 1728 | # the value cannot be displayed as-is as this may be an opened file- |
| 1729 | # like object |
| 1730 | vname = getattr(value, 'name', None) |
| 1731 | if vname: |
| 1732 | value = vname |
| 1733 | else: |
| 1734 | value = '<file>' |
| 1735 | |
| 1736 | # coerce to string for non-basic supported types |
| 1737 | if not (value in (True, False, None) |
| 1738 | or isinstance(value, (str, str, bytes, tuple, list, dict, dict))): |
| 1739 | value = repr(value) |
| 1740 | |
| 1741 | # opts is a list of CLI options as in "--strip-root": the last opt is |
no test coverage detected