Skip to content

Commit 6ad874f

Browse files
author
Gerit Wagner
committed
format
1 parent 973420b commit 6ad874f

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

search_query/cli.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from search_query import load_search_file
1212
from search_query.exception import QuerySyntaxError
1313

14+
1415
def _cmd_translate(args: argparse.Namespace) -> int:
1516
"""Translate a query file from one platform/format to another."""
1617

@@ -27,21 +28,21 @@ def _cmd_translate(args: argparse.Namespace) -> int:
2728
platform=search_file.platform,
2829
field_general=search_file.field,
2930
)
30-
except QuerySyntaxError as e:
31-
print(f"Fatal error parsing query.")
31+
except QuerySyntaxError:
32+
print("Fatal error parsing query.")
3233
return 1
3334

3435
print(f"Converting from {search_file.platform} to {args.target}")
3536
try:
3637
translated_query = query.translate(args.target)
37-
except Exception as e:
38+
except Exception as e: # pylint: disble=broad-exception-caught
3839
print(f"Error translating query: {e}")
3940
return 1
4041

4142
converted_query = translated_query.to_string()
4243
search_file.search_string = converted_query
4344
search_file.platform = args.target
44-
45+
4546
print(f"Writing converted query to {args.output_file}")
4647
search_file.save(args.output_file)
4748
return 0
@@ -63,12 +64,15 @@ def _lint(args: argparse.Namespace) -> int:
6364
return exit_code
6465

6566

66-
def build_parser() -> argparse.ArgumentParser:
67+
def _build_parser() -> argparse.ArgumentParser:
6768
parser = argparse.ArgumentParser(
6869
prog="search-query",
69-
description="Tools for working with search queries (linting, translation, etc.)",
70+
description="Tools for working with search queries "
71+
+ "(linting, translation, etc.)",
72+
)
73+
subparsers = parser.add_subparsers(
74+
dest="command", metavar="<command>", required=True
7075
)
71-
subparsers = parser.add_subparsers(dest="command", metavar="<command>", required=True)
7276

7377
# translate
7478
p_tr = subparsers.add_parser(
@@ -100,7 +104,8 @@ def build_parser() -> argparse.ArgumentParser:
100104
p_li = subparsers.add_parser(
101105
"lint",
102106
help="Lint query files",
103-
description="Lint one or more query files. Intended for standalone use or pre-commit.",
107+
description="Lint one or more query files. "
108+
+ "Intended for standalone use or pre-commit.",
104109
)
105110
p_li.add_argument(
106111
"files",
@@ -113,7 +118,8 @@ def build_parser() -> argparse.ArgumentParser:
113118

114119

115120
def main(argv: list[str] | None = None) -> int:
116-
parser = build_parser()
121+
"""Main entry point for the CLI."""
122+
parser = _build_parser()
117123
args = parser.parse_args(argv)
118124
try:
119125
return args.func(args)

search_query/linter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def _get_parser(
2626

2727
try:
2828
parser.parse()
29-
except Exception as exc:
29+
except Exception:
3030
assert parser.linter.messages # type: ignore
3131
return parser
3232

0 commit comments

Comments
 (0)