diff --git a/README.md b/README.md index 24d2967..643d990 100644 --- a/README.md +++ b/README.md @@ -238,10 +238,13 @@ You can customize the processing with additional optional arguments: --toc-check-pages Pages to check for table of contents (default: 20) --max-pages-per-node Max pages per node (default: 10) --max-tokens-per-node Max tokens per node (default: 20000) ---if-add-node-id Add node ID (yes/no, default: yes) ---if-add-node-summary Add node summary (yes/no, default: yes) ---if-add-doc-description Add doc description (yes/no, default: yes) +--if-add-node-id Add node IDs (on by default; disable with: --if-add-node-id no) +--if-add-node-summary Add node summaries (on by default; disable with: --if-add-node-summary no) +--if-add-doc-description Add a document description (on by default; disable with: --if-add-doc-description no) +--if-add-node-text Add raw text to nodes (off by default; enable with: --if-add-node-text) ``` +These flags take no value by default (a bare `--if-add-node-id` turns it on); the +legacy `--if-add-node-id no` form still works for turning an option off.
diff --git a/run_pageindex.py b/run_pageindex.py index a2d4c31..0af3f9e 100644 --- a/run_pageindex.py +++ b/run_pageindex.py @@ -5,6 +5,16 @@ from pageindex.index.page_index import * from pageindex.index.page_index_md import md_to_tree from pageindex.config import IndexConfig + +def _cli_bool(value): + """Parse a CLI boolean flag value. + + A bare ``--flag`` (no value) resolves to True via ``const``; an explicit + value keeps the legacy yes/no style working, so ``--flag no`` turns it off. + """ + return str(value).strip().lower() in ("yes", "true", "1", "y", "on") + + if __name__ == "__main__": # Set up argument parser parser = argparse.ArgumentParser(description='Process PDF or Markdown document and generate structure') @@ -20,14 +30,16 @@ if __name__ == "__main__": parser.add_argument('--max-tokens-per-node', type=int, default=None, help='Maximum number of tokens per node (PDF only)') - parser.add_argument('--if-add-node-id', action='store_true', default=None, - help='Add node id to the node') - parser.add_argument('--if-add-node-summary', action='store_true', default=None, - help='Add summary to the node') - parser.add_argument('--if-add-doc-description', action='store_true', default=None, - help='Add doc description to the doc') - parser.add_argument('--if-add-node-text', action='store_true', default=None, - help='Add text to the node') + # Bare flag (e.g. --if-add-node-id) turns the option on; an explicit value + # keeps the legacy yes/no style, so --if-add-node-id no turns it off. + parser.add_argument('--if-add-node-id', nargs='?', const=True, type=_cli_bool, default=None, + help='Add node IDs (on by default). Bare flag or yes/no, e.g. --if-add-node-id no') + parser.add_argument('--if-add-node-summary', nargs='?', const=True, type=_cli_bool, default=None, + help='Add node summaries (on by default). Bare flag or yes/no') + parser.add_argument('--if-add-doc-description', nargs='?', const=True, type=_cli_bool, default=None, + help='Add a document description (on by default). Bare flag or yes/no') + parser.add_argument('--if-add-node-text', nargs='?', const=True, type=_cli_bool, default=None, + help='Add raw text to nodes (off by default). Bare flag or yes/no') # Markdown specific arguments parser.add_argument('--if-thinning', type=str, default='no', diff --git a/tests/test_review_fixes.py b/tests/test_review_fixes.py index e447231..28ce5eb 100644 --- a/tests/test_review_fixes.py +++ b/tests/test_review_fixes.py @@ -128,3 +128,13 @@ def test_cloud_query_empty_collection_raises(monkeypatch): monkeypatch.setattr(backend, "_get_all_doc_ids", lambda col: []) with pytest.raises(ValueError, match="no documents"): backend.query("empty", "q") # doc_ids=None -> resolves to [] + + +# ── #10: CLI bool flags still parse legacy yes/no (a bare 'no' must be False) ── +def test_cli_bool_coerces_legacy_yes_no(): + import run_pageindex + + assert run_pageindex._cli_bool("no") is False # legacy off-switch + assert run_pageindex._cli_bool("yes") is True + assert run_pageindex._cli_bool("false") is False + assert run_pageindex._cli_bool(True) is True # bare flag -> const=True