Skip to content

Commit e1ed383

Browse files
author
Gerit Wagner
committed
revise cli, update docs
1 parent e9e90c1 commit e1ed383

File tree

3 files changed

+63
-14
lines changed

3 files changed

+63
-14
lines changed

docs/source/index.rst

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,57 @@ To write a query to a JSON file, run the serializer:
162162
CLI Use
163163
=======
164164

165+
The CLI reads a query from an input file, converts it from a specified source format
166+
to a target format, and writes the converted query to an output file.
167+
168+
To translate a search query on the command line, run
169+
170+
.. code-block:: bash
171+
172+
search-query-translate --from colrev_web_of_science \
173+
--input input_query.txt \
174+
--to colrev_pubmed \
175+
--output output_query.txt
176+
177+
Arguments
178+
---------
179+
180+
- ``--from`` (required):
181+
The source query format.
182+
Example: ``colrev_web_of_science``
183+
184+
- ``--input`` (required):
185+
Path to the input file containing the original query.
186+
187+
- ``--to`` (required):
188+
The target query format.
189+
Example: ``colrev_pubmed``
190+
191+
- ``--output`` (required):
192+
Path to the file where the converted query will be written.
193+
194+
195+
196+
Example
197+
-------
198+
199+
Suppose you have a Web of Science search query saved in ``input_query.txt`` and you want to convert it to a PubMed-compatible format. Run:
200+
201+
.. code-block:: bash
202+
203+
search-query-translate --from colrev_web_of_science \
204+
--input input_query.txt \
205+
--to colrev_pubmed \
206+
--output output_query.txt
207+
208+
The converted query will be saved in ``output_query.txt``.
209+
165210
Linters can be run on the CLI:
166211

167212
.. code-block:: bash
168213
169-
search-file-lint search-file.json
214+
search-query-lint search-file.json
215+
170216
171217
Pre-commit Hooks
172218
================
@@ -179,7 +225,7 @@ Linters can be included as pre-commit hooks by adding the following to the ``.pr
179225
- repo: https://github.com/CoLRev-Environment/search-query
180226
rev: main # or version of search-query
181227
hooks:
182-
- id: search-file-lint
228+
- id: search-query-lint
183229
184230
For development and testing, use the following:
185231

@@ -188,9 +234,9 @@ For development and testing, use the following:
188234
repos:
189235
- repo: local
190236
hooks:
191-
- id: search-file-lint
237+
- id: search-query-lint
192238
name: Search-file linter
193-
entry: search-file-lint
239+
entry: search-query-lint
194240
language: python
195241
files: \.json$
196242

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 = "search_query.cli:main"
43-
search-file-lint = "search_query.linter:main"
42+
search-query-translate = "search_query.cli:main"
43+
search-query-lint = "search_query.linter:main"
4444

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

search_query/cli.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/usr/bin/env python3
22
"""CLI for search-query."""
33
import argparse
4-
4+
from pathlib import Path
55
import search_query.parser
6+
from search_query import SearchFile
7+
from search_query import load_search_file
68

79

810
def main():
@@ -44,16 +46,17 @@ def main():
4446

4547
print(f"Convert from {args.source} to {args.target}")
4648

47-
# Example stub (replace with actual logic)
48-
with open(args.input_file, encoding="utf-8") as infile:
49-
query_str = infile.read()
50-
query = search_query.parser.parse(query_str, syntax=args.source)
49+
if Path(args.input_file).suffix == ".json":
50+
51+
search_file = load_search_file(args.input_file)
52+
query = search_query.parser.parse(search_file.search_string, syntax=args.source, search_field_general="")
5153
converted_query = query.to_string(syntax=args.target)
54+
search_file.search_string = converted_query
55+
search_file.save()
5256

53-
with open(args.output_file, "w", encoding="utf-8") as outfile:
54-
outfile.write(converted_query)
57+
else:
58+
raise NotImplemented
5559

56-
print("Conversion complete.")
5760

5861

5962
if __name__ == "__main__":

0 commit comments

Comments
 (0)