Skip to content

Commit 347bcf6

Browse files
committed
ENH: Provide informative exception if command needs a heuristic to be specified
1 parent 7d2c526 commit 347bcf6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

heudiconv/cli/run.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def process_extra_commands(outdir, args):
6262
for f in args.files:
6363
treat_infofile(f)
6464
elif args.command == 'ls':
65+
ensure_heuristic_arg(args)
6566
heuristic = load_heuristic(args.heuristic)
6667
heuristic_ls = getattr(heuristic, 'ls', None)
6768
for f in args.files:
@@ -78,6 +79,7 @@ def process_extra_commands(outdir, args):
7879
% (str(study_session), len(sequences), suf)
7980
)
8081
elif args.command == 'populate-templates':
82+
ensure_heuristic_arg(args)
8183
heuristic = load_heuristic(args.heuristic)
8284
for f in args.files:
8385
populate_bids_templates(f, getattr(heuristic, 'DEFAULT_FIELDS', {}))
@@ -88,16 +90,21 @@ def process_extra_commands(outdir, args):
8890
for name_desc in get_known_heuristics_with_descriptions().items():
8991
print("- %s: %s" % name_desc)
9092
elif args.command == 'heuristic-info':
91-
from ..utils import get_heuristic_description, get_known_heuristic_names
92-
if not args.heuristic:
93-
raise ValueError("Specify heuristic using -f. Known are: %s"
94-
% ', '.join(get_known_heuristic_names()))
93+
ensure_heuristic_arg(args)
94+
from ..utils import get_heuristic_description
9595
print(get_heuristic_description(args.heuristic, full=True))
9696
else:
9797
raise ValueError("Unknown command %s", args.command)
9898
return
9999

100100

101+
def ensure_heuristic_arg(args):
102+
from ..utils import get_known_heuristic_names
103+
if not args.heuristic:
104+
raise ValueError("Specify heuristic using -f. Known are: %s"
105+
% ', '.join(get_known_heuristic_names()))
106+
107+
101108
def main(argv=None):
102109
parser = get_parser()
103110
args = parser.parse_args(argv)

0 commit comments

Comments
 (0)