Skip to content

Commit 82c5475

Browse files
author
Gerit Wagner
committed
cli revisions
1 parent d743740 commit 82c5475

File tree

5 files changed

+20
-26
lines changed

5 files changed

+20
-26
lines changed

docs/source/index.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,18 @@ To translate a search query on the command line, run
177177
Arguments
178178
---------
179179

180-
- ``--from`` (required):
181-
The source query format.
180+
- ``--from`` (required):
181+
The source query format.
182182
Example: ``colrev_web_of_science``
183183

184-
- ``--input`` (required):
184+
- ``--input`` (required):
185185
Path to the input file containing the original query.
186186

187-
- ``--to`` (required):
188-
The target query format.
187+
- ``--to`` (required):
188+
The target query format.
189189
Example: ``colrev_pubmed``
190190

191-
- ``--output`` (required):
191+
- ``--output`` (required):
192192
Path to the file where the converted query will be written.
193193

194194

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ dev = [
3939
]
4040

4141
[project.scripts]
42-
search-query-translate = "search_query.cli:main"
43-
search-query-lint = "search_query.linter:main"
42+
search-query-translate = "search_query.cli:translate"
43+
search-query-lint = "search_query.linter:lint"
4444

4545
[tool.pylint.MAIN]
4646
extension-pkg-whitelist = "lxml.etree"

search_query/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020

2121
# Instead of adding elements to __all__,
2222
# prefixing methods/variables with "__" is preferred.
23-
# Imports like "from x import *" are discouraged.
23+
# Imports like "from x import *" are discouraged.

search_query/cli.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
"""CLI for search-query."""
33
import argparse
44
from pathlib import Path
5+
6+
import search_query.linter
57
import search_query.parser
6-
from search_query import SearchFile
78
from search_query import load_search_file
89

910

10-
def main():
11+
def translate() -> None:
12+
"""Main entrypoint for the query translation CLI"""
1113
parser = argparse.ArgumentParser(
1214
description="Convert search queries between formats"
1315
)
@@ -47,17 +49,18 @@ def main():
4749
print(f"Convert from {args.source} to {args.target}")
4850

4951
if Path(args.input_file).suffix == ".json":
50-
5152
search_file = load_search_file(args.input_file)
52-
query = search_query.parser.parse(search_file.search_string, syntax=args.source, search_field_general="")
53+
query = search_query.parser.parse(
54+
search_file.search_string, syntax=args.source, search_field_general=""
55+
)
5356
converted_query = query.to_string(syntax=args.target)
5457
search_file.search_string = converted_query
5558
search_file.save()
5659

5760
else:
58-
raise NotImplemented
59-
61+
raise NotImplementedError
6062

6163

62-
if __name__ == "__main__":
63-
main()
64+
def lint() -> None:
65+
"""Main entrypoint for the query linter hook"""
66+
raise SystemExit(search_query.linter.pre_commit_hook())

search_query/linter.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,3 @@ def pre_commit_hook() -> int:
6464
return ExitCodes.FAIL
6565

6666
return ExitCodes.SUCCESS
67-
68-
69-
def main() -> None:
70-
"""Main entrypoint for the query linter hook"""
71-
raise SystemExit(pre_commit_hook())
72-
73-
74-
if __name__ == "__main__":
75-
main()

0 commit comments

Comments
 (0)