args.py
python
sha256:0e9549ec7b463911bc08b7d586dc320b1ac9b1f5c943ee7e3865dcc6cb0f6f83
chore(governance): sync handover+roadmap to 84db8c8 (drift:…
Human
1 day ago
| 1 | """Argv preprocessing so global flags work before or after subcommands.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | GLOBAL_OPTIONS: dict[str, int] = { |
| 6 | "-C": 1, |
| 7 | "--repo": 1, |
| 8 | "--config": 1, |
| 9 | "--json": 0, |
| 10 | "-q": 0, |
| 11 | "--quiet": 0, |
| 12 | "-v": 0, |
| 13 | "--verbose": 0, |
| 14 | "--no-color": 0, |
| 15 | } |
| 16 | |
| 17 | STANDALONE_GLOBALS = frozenset({"-h", "--help", "--version"}) |
| 18 | |
| 19 | |
| 20 | def extract_global_args(argv: list[str]) -> tuple[list[str], list[str]]: |
| 21 | """Pull global flags out of ``argv`` regardless of position.""" |
| 22 | global_args: list[str] = [] |
| 23 | rest: list[str] = [] |
| 24 | index = 0 |
| 25 | while index < len(argv): |
| 26 | token = argv[index] |
| 27 | if token in STANDALONE_GLOBALS: |
| 28 | global_args.append(token) |
| 29 | index += 1 |
| 30 | continue |
| 31 | if token in GLOBAL_OPTIONS: |
| 32 | global_args.append(token) |
| 33 | value_count = GLOBAL_OPTIONS[token] |
| 34 | for _ in range(value_count): |
| 35 | index += 1 |
| 36 | if index >= len(argv): |
| 37 | break |
| 38 | global_args.append(argv[index]) |
| 39 | index += 1 |
| 40 | continue |
| 41 | rest.append(token) |
| 42 | index += 1 |
| 43 | return global_args, rest |
File History
1 commit
sha256:6abcf1fa82a7a621ccbc945f19acdba5bc0db54569599404a1452fb4a096a199
fix(ISR): default require_independent_second_reviewer to require
Human
minor
⚠
1 day ago