-
Notifications
You must be signed in to change notification settings - Fork 196
Allows for multiple -s|--section options #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -551,13 +551,22 @@ def cli(opts: argparse.Namespace, args: Sequence[str]) -> int: | |
| ext = f"jinja2.ext.{ext}" | ||
| extensions.append(resolve_extension(ext, os.getcwd())) | ||
|
|
||
| # Use only a specific section if needed | ||
| if opts.section: | ||
| section = opts.section | ||
| # Use specified sections if needed | ||
| if len(opts.section) == 1: | ||
| section = opts.section[0] | ||
| if section in data: | ||
| data = data[section] | ||
| else: | ||
| raise InvalidUsage(f"unknown section: {section}") | ||
| elif len(opts.section) > 1: | ||
| # for multiple values, all must be iterables | ||
| merged_data = {} | ||
| for k, v in data.items(): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Walk |
||
| if k in opts.section: | ||
| if not isinstance(v, Iterable): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strings are |
||
| raise InvalidUsage(f"invalid section: {k}: must be iterable") | ||
| merged_data.update(v) | ||
| data = merged_data | ||
|
|
||
| deep_merge(data, parse_kv_string(opts.D or [])) | ||
|
|
||
|
|
@@ -702,8 +711,9 @@ def run() -> int: | |
| parser.add_argument( | ||
| "-s", | ||
| "--section", | ||
| help="Use only this section from the configuration", | ||
| help="Use only this section from the configuration. Can be used multiple times.", | ||
| dest="section", | ||
| action="append", | ||
| ) | ||
| parser.add_argument( | ||
| "--strict", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This crashes when
-sisn't passed at all.action="append"without a default leavesopts.sectionasNone, andlen(None)is why CI is fully red right now. The failing tests never pass-s, so the default path is just dead.default=[]on the argument fixes it.