Skip to content

Commit dd44a64

Browse files
committed
improve doc cli
1 parent 14418c6 commit dd44a64

File tree

3 files changed

+87
-86
lines changed

3 files changed

+87
-86
lines changed

cohort_creator/_cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import pandas as pd
1111
from datalad import api
12+
from rich_argparse import RichHelpFormatter
1213

1314
from cohort_creator._parsers import global_parser
1415
from cohort_creator._utils import get_bids_filter
@@ -56,7 +57,7 @@ def create_yoda(output_dir: Path) -> None:
5657

5758
def cli(argv: Sequence[str] = sys.argv) -> None:
5859
"""Entry point."""
59-
parser = global_parser()
60+
parser = global_parser(formatter_class=RichHelpFormatter)
6061

6162
args, _ = parser.parse_known_args(argv[1:])
6263

cohort_creator/_parsers.py

Lines changed: 10 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,23 @@
22
from __future__ import annotations
33

44
from argparse import ArgumentParser
5-
6-
from rich_argparse import RichHelpFormatter
5+
from argparse import HelpFormatter
76

87
from ._version import __version__
98

109
DOC_URL = "https://cohort-creator.readthedocs.io/en/latest/"
1110
FAQ_URL = f"{DOC_URL}faq.html"
1211

1312

14-
def base_parser() -> ArgumentParser:
13+
def base_parser(formatter_class: type[HelpFormatter] = HelpFormatter) -> ArgumentParser:
1514
parser = ArgumentParser(
1615
prog="cohort_creator",
1716
description="Creates a cohort by grabbing specific subjects from opennneuro datasets.",
1817
epilog=f"""
1918
For a more readable version of this help section,
2019
see the `online doc <{DOC_URL}>`_.
2120
""",
22-
formatter_class=RichHelpFormatter,
21+
formatter_class=formatter_class,
2322
)
2423
parser.add_argument(
2524
"-v",
@@ -128,8 +127,8 @@ def add_specialized_args(parser: ArgumentParser) -> ArgumentParser:
128127
return parser
129128

130129

131-
def global_parser() -> ArgumentParser:
132-
parser = base_parser()
130+
def global_parser(formatter_class: type[HelpFormatter] = HelpFormatter) -> ArgumentParser:
131+
parser = base_parser(formatter_class=formatter_class)
133132
subparsers = parser.add_subparsers(
134133
dest="command",
135134
help="Choose a subcommand",
@@ -138,63 +137,19 @@ def global_parser() -> ArgumentParser:
138137

139138
install_parser = subparsers.add_parser(
140139
"install",
141-
help="""
142-
Install several openneuro datasets.
143-
144-
Example:
145-
146-
.. code-block:: bash
147-
148-
cohort_creator install \\
149-
--dataset_listing inputs/dataset-results.tsv \\
150-
--participant_listing inputs/participant-results.tsv \\
151-
--output_dir outputs \\
152-
--dataset_types raw mriqc fmriprep \\
153-
--verbosity 3
154-
155-
If no ``--participant_listing`` is provided,
156-
a ``participants.tsv`` file will be generated
157-
in ``output_dir/code`` that contains all participants
158-
for all datasets in ``dataset_listing``.
159-
160-
Datasets listing can be passed directly as a list of datasets:
161-
162-
.. code-block:: bash
163-
164-
cohort_creator install \\
165-
--dataset_listing ds000001 ds000002 \\
166-
--output_dir outputs \\
167-
--dataset_types raw mriqc fmriprep \\
168-
--verbosity 3
169-
""",
140+
help="Install several openneuro datasets.",
170141
formatter_class=parser.formatter_class,
171142
)
172143
install_parser = add_common_arguments(install_parser)
173144
install_parser.add_argument(
174145
"--generate_participant_listing",
175146
action="store_true",
176-
help="Skips rerunning mriqc on the subset of participants.",
147+
help="Generate a participant_listing.tsv in the output_dir.",
177148
)
178149

179150
get_parser = subparsers.add_parser(
180151
"get",
181-
help="""
182-
Get specified data for a cohort of subjects.
183-
184-
Example:
185-
186-
.. code-block:: bash
187-
188-
cohort_creator get \\
189-
--dataset_listing inputs/dataset-results.tsv \\
190-
--participant_listing inputs/participant-results.tsv \\
191-
--output_dir outputs \\
192-
--dataset_types raw mriqc fmriprep \\
193-
--datatype anat func \\
194-
--space T1w MNI152NLin2009cAsym \\
195-
--jobs 6 \\
196-
--verbosity 3
197-
""",
152+
help="Get specified data for a cohort of subjects.",
198153
formatter_class=parser.formatter_class,
199154
)
200155
get_parser = add_common_arguments(get_parser)
@@ -212,22 +167,7 @@ def global_parser() -> ArgumentParser:
212167

213168
copy_parser = subparsers.add_parser(
214169
"copy",
215-
help="""
216-
Copy cohort of subjects into separate directory.
217-
218-
Example:
219-
220-
.. code-block:: bash
221-
222-
cohort_creator copy \\
223-
--dataset_listing inputs/dataset-results.tsv \\
224-
--participant_listing inputs/participant-results.tsv \\
225-
--output_dir outputs \\
226-
--dataset_types raw mriqc fmriprep \\
227-
--datatype anat func \\
228-
--space T1w MNI152NLin2009cAsym \\
229-
--verbosity 3
230-
""",
170+
help="Copy cohort of subjects into separate directory.",
231171
formatter_class=parser.formatter_class,
232172
)
233173
copy_parser = add_common_arguments(copy_parser)
@@ -240,22 +180,7 @@ def global_parser() -> ArgumentParser:
240180

241181
all_parser = subparsers.add_parser(
242182
"all",
243-
help="""
244-
Install, get, and copy cohort of subjects.
245-
246-
Example:
247-
248-
.. code-block:: bash
249-
250-
cohort_creator all \\
251-
--dataset_listing inputs/dataset-results.tsv \\
252-
--participant_listing inputs/participant-results.tsv \\
253-
--output_dir outputs \\
254-
--dataset_types raw mriqc fmriprep \\
255-
--datatype anat func \\
256-
--space T1w MNI152NLin2009cAsym \\
257-
--verbosity 3
258-
""",
183+
help="Install, get, and copy cohort of subjects.",
259184
formatter_class=parser.formatter_class,
260185
)
261186
all_parser = add_common_arguments(all_parser)

docs/source/usage_notes.rst

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,78 @@ Command-Line Arguments
99
:prog: cohort_creator
1010
:module: cohort_creator._parsers
1111
:func: global_parser
12+
13+
14+
Examples
15+
--------
16+
17+
install
18+
^^^^^^^
19+
20+
.. code-block:: bash
21+
22+
cohort_creator install \
23+
--dataset_listing inputs/dataset-results.tsv \
24+
--participant_listing inputs/participant-results.tsv \
25+
--output_dir outputs \
26+
--dataset_types raw mriqc fmriprep \
27+
--verbosity 3
28+
29+
If no ``--participant_listing`` is provided,
30+
a ``participants.tsv`` file will be generated
31+
in ``output_dir/code`` that contains all participants
32+
for all datasets in ``dataset_listing``.
33+
34+
Datasets listing can be passed directly as a list of datasets:
35+
36+
.. code-block:: bash
37+
38+
cohort_creator install \
39+
--dataset_listing ds000001 ds000002 \
40+
--output_dir outputs \
41+
--dataset_types raw mriqc fmriprep \
42+
--verbosity 3
43+
44+
get
45+
^^^
46+
47+
.. code-block:: bash
48+
49+
cohort_creator get \
50+
--dataset_listing inputs/dataset-results.tsv \
51+
--participant_listing inputs/participant-results.tsv \
52+
--output_dir outputs \
53+
--dataset_types raw mriqc fmriprep \
54+
--datatype anat func \
55+
--space T1w MNI152NLin2009cAsym \
56+
--jobs 6 \
57+
--verbosity 3
58+
59+
60+
copy
61+
^^^^
62+
63+
.. code-block:: bash
64+
65+
cohort_creator copy \
66+
--dataset_listing inputs/dataset-results.tsv \
67+
--participant_listing inputs/participant-results.tsv \
68+
--output_dir outputs \
69+
--dataset_types raw mriqc fmriprep \
70+
--datatype anat func \
71+
--space T1w MNI152NLin2009cAsym \
72+
--verbosity 3
73+
74+
all
75+
^^^
76+
77+
.. code-block:: bash
78+
79+
cohort_creator all \
80+
--dataset_listing inputs/dataset-results.tsv \
81+
--participant_listing inputs/participant-results.tsv \
82+
--output_dir outputs \
83+
--dataset_types raw mriqc fmriprep \
84+
--datatype anat func \
85+
--space T1w MNI152NLin2009cAsym \
86+
--verbosity 3

0 commit comments

Comments
 (0)