Skip to content

Commit

Permalink
enh: test fs-license is a file on wrapper CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
oesteban committed Jun 3, 2020
1 parent 312da4a commit 7674b04
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion wrapper/fmriprep_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def is_in_directory(filepath, directory):
def get_parser():
"""Defines the command line interface of the wrapper"""
import argparse
from functools import partial

class ToDict(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
Expand All @@ -234,11 +235,21 @@ def __call__(self, parser, namespace, values, option_string=None):
d[k] = os.path.abspath(v)
setattr(namespace, self.dest, d)

def _is_file(path, parser):
"""Ensure a given path exists and it is a file."""
if not os.path.isfile(path):
raise parser.error(
"Path should point to a file (or symlink of file): <%s>." % path
)
return path

parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
add_help=False)

IsFile = partial(_is_file, parser=parser)

# Standard FMRIPREP arguments
parser.add_argument('bids_dir', nargs='?', type=os.path.abspath,
default='')
Expand Down Expand Up @@ -279,7 +290,7 @@ def __call__(self, parser, namespace, values, option_string=None):
', '.join(NONSTANDARD_REFERENCES)))

g_wrap.add_argument(
'--fs-license-file', metavar='PATH', type=os.path.abspath,
'--fs-license-file', metavar='PATH', type=IsFile,
default=os.getenv('FS_LICENSE', None),
help='Path to FreeSurfer license key file. Get it (for free) by registering'
' at https://surfer.nmr.mgh.harvard.edu/registration.html')
Expand Down

0 comments on commit 7674b04

Please sign in to comment.