|
1 | 1 | import argparse
|
2 | 2 | import logging
|
3 | 3 | import sys
|
| 4 | +from copy import deepcopy |
4 | 5 | from functools import partial
|
5 | 6 | from types import TracebackType
|
6 | 7 | from typing import List
|
|
17 | 18 | )
|
18 | 19 |
|
19 | 20 | logger = logging.getLogger(__name__)
|
| 21 | + |
| 22 | + |
| 23 | +class ParseKwargs(argparse.Action): |
| 24 | + """ |
| 25 | + Parse arguments in the for `key=value`. |
| 26 | +
|
| 27 | + Quoted strings are automatically unquoted. |
| 28 | + Can be submitted multiple times: |
| 29 | +
|
| 30 | + ex: |
| 31 | + -k key=value -k double-quotes="value" -k single-quotes='value' |
| 32 | +
|
| 33 | + will result in |
| 34 | +
|
| 35 | + namespace["opt"] == { |
| 36 | + "key": "value", |
| 37 | + "double-quotes": "value", |
| 38 | + "single-quotes": "value", |
| 39 | + } |
| 40 | + """ |
| 41 | + |
| 42 | + def __call__(self, parser, namespace, kwarg, option_string=None): |
| 43 | + kwargs = getattr(namespace, self.dest, None) or {} |
| 44 | + key, value = kwarg.split("=", 1) |
| 45 | + kwargs[key] = value.strip("'\"") |
| 46 | + setattr(namespace, self.dest, kwargs) |
| 47 | + |
| 48 | + |
| 49 | +tpl_arguments = ( |
| 50 | + { |
| 51 | + "name": ["--template", "-t"], |
| 52 | + "help": ( |
| 53 | + "changelog template file name " |
| 54 | + "(relative to the current working directory)" |
| 55 | + ), |
| 56 | + }, |
| 57 | + { |
| 58 | + "name": ["--extra", "-e"], |
| 59 | + "action": ParseKwargs, |
| 60 | + "dest": "extras", |
| 61 | + "metavar": "EXTRA", |
| 62 | + "help": "a changelog extra variable (in the form 'key=value')", |
| 63 | + }, |
| 64 | +) |
| 65 | + |
20 | 66 | data = {
|
21 | 67 | "prog": "cz",
|
22 | 68 | "description": (
|
|
190 | 236 | "default": None,
|
191 | 237 | "help": "keep major version at zero, even for breaking changes",
|
192 | 238 | },
|
| 239 | + *deepcopy(tpl_arguments), |
193 | 240 | {
|
194 | 241 | "name": "manual_version",
|
195 | 242 | "type": str,
|
|
246 | 293 | "If not set, it will generate changelog from the start"
|
247 | 294 | ),
|
248 | 295 | },
|
| 296 | + *deepcopy(tpl_arguments), |
249 | 297 | ],
|
250 | 298 | },
|
251 | 299 | {
|
|
0 commit comments