forked from thibaudcolas/curlylint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
28316ee
commit 2afa4b2
Showing
7 changed files
with
157 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import json | ||
|
||
import click | ||
|
||
|
||
class TemplateTagsParamType(click.ParamType): | ||
""" | ||
Validates and converts CLI-provided template tags configuration. | ||
Expects: --template-tags '[["cache", "endcache"]]' | ||
""" | ||
|
||
name = "template tags" | ||
|
||
def convert(self, value, param, ctx): | ||
try: | ||
if isinstance(value, str): | ||
template_tags = json.loads(value) | ||
else: | ||
template_tags = value | ||
# Validate the expected list of lists. | ||
if not isinstance(template_tags, (list, tuple)): | ||
raise ValueError | ||
for tags in template_tags: | ||
if not isinstance(tags, (list, tuple)): | ||
raise ValueError | ||
return template_tags | ||
except ValueError: | ||
self.fail( | ||
f"expected a list of lists of tags as JSON, got {value!r}", | ||
param, | ||
ctx, | ||
) | ||
|
||
|
||
TEMPLATE_TAGS = TemplateTagsParamType() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters