Returns a transformation function that backquotes command examples, adding backquotes and references to any found options.
(refs: set[str])
| 111 | |
| 112 | |
| 113 | def add_backquotes_with_refs(refs: set[str]) -> ty.Callable[[str], str]: |
| 114 | """Returns a transformation function that backquotes command examples, adding backquotes and |
| 115 | references to any found options.""" |
| 116 | |
| 117 | def _add_backquotes(s: re.Match) -> str: |
| 118 | to_add: str = s.string[s.start() : s.end()] |
| 119 | flag = re.search(r"-+[\w-]+[^\.\=\s\/]*", to_add) |
| 120 | if flag is not None and flag.string[flag.start() : flag.end()] in refs: |
| 121 | # add cross reference |
| 122 | cross_ref = flag.string[flag.start() : flag.end()] |
| 123 | option = s.string[s.start() : s.end()] |
| 124 | return f":option:`{option} <{cross_ref}>`" |
| 125 | else: |
| 126 | return add_backquotes(s) |
| 127 | |
| 128 | return _add_backquotes |
| 129 | |
| 130 | |
| 131 | def extract_default_value(s: str) -> tuple[str, str | None]: |
no outgoing calls
no test coverage detected