-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
91 lines (69 loc) · 3.08 KB
/
cli.py
File metadata and controls
91 lines (69 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""
cli.py
------
Command-line interface for the BIDS-SQL input pipeline.
Subcommands:
index Discover, index, and validate a local BIDS folder
rules Print the active discovery rules and exit
Remote ingesters (index-openneuro, index-datalad) live in the separate
openneuro-bids-crawler repo which installs bids-sql as a dependency.
"""
import argparse
import asyncio
import logging
import sys
from rules import DEFAULT_BIDS_RULESET
# ─── Subcommand handlers ───────────────────────────────────────────────────────
def _cmd_index(args: argparse.Namespace) -> None:
from input_pipeline import run_pipeline
asyncio.run(run_pipeline(args.folder, skip_validation=args.no_validate))
def _cmd_rules(_args: argparse.Namespace) -> None: # noqa: ARG001
print(DEFAULT_BIDS_RULESET)
print()
print(DEFAULT_BIDS_RULESET.as_human_readable_list())
# ─── Argument parser ──────────────────────────────────────────────────────────
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
prog="bids-sql",
description="Index and query BIDS datasets.",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
# Index a local folder (full pipeline with validation)
python cli.py index /data/studies
# Skip validation (faster, useful without bids-validator installed)
python cli.py index /data/studies --no-validate
# Print active discovery rules
python cli.py rules
""",
)
sub = parser.add_subparsers(dest="command", metavar="command")
sub.required = True
# ── index ─────────────────────────────────────────────────────────────────
p_index = sub.add_parser(
"index",
help="Discover, index, and validate a local BIDS folder",
)
p_index.add_argument("folder", help="Root folder to scan for BIDS datasets")
p_index.add_argument(
"--no-validate",
action="store_true",
default=False,
help="Skip the bids-validator step (steps 4+5)",
)
p_index.set_defaults(func=_cmd_index)
# ── rules ─────────────────────────────────────────────────────────────────
p_rules = sub.add_parser("rules", help="Print active discovery rules and exit")
p_rules.set_defaults(func=_cmd_rules)
return parser
def main(argv: list[str] | None = None) -> None:
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(levelname)-8s %(message)s",
datefmt="%H:%M:%S",
)
parser = build_parser()
args = parser.parse_args(argv)
args.func(args)
if __name__ == "__main__":
main(sys.argv[1:])