Skip to content

Commit d448c7f

Browse files
committed
fix argument name for crash CLI. add callbacks
1 parent a40ee7e commit d448c7f

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

nipype/scripts/cli.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
ExistingFilePath,
1111
UnexistingFilePath,
1212
RegularExpression,
13-
PythonModule,)
13+
PythonModule,
14+
check_not_none,)
1415

1516

1617
# declare the CLI group
@@ -20,8 +21,8 @@ def cli():
2021

2122

2223
@cli.command(context_settings=CONTEXT_SETTINGS)
23-
@click.argument('logdir', type=ExistingDirPath)
24-
@click.option('-r', '--regex', type=RegularExpression(), default='*',
24+
@click.argument('logdir', type=ExistingDirPath, callback=check_not_none)
25+
@click.option('-r', '--regex', type=RegularExpression(), callback=check_not_none,
2526
help='Regular expression to be searched in each traceback.')
2627
def search(logdir, regex):
2728
"""Search for tracebacks content.
@@ -43,16 +44,16 @@ def search(logdir, regex):
4344

4445

4546
@cli.command(context_settings=CONTEXT_SETTINGS)
46-
@click.argument('crashfile', type=ExistingFilePath,)
47+
@click.argument('crashfile', type=ExistingFilePath, callback=check_not_none)
4748
@click.option('-r', '--rerun', is_flag=True, flag_value=True,
4849
help='Rerun crashed node.')
4950
@click.option('-d', '--debug', is_flag=True, flag_value=True,
5051
help='Enable Python debugger when re-executing.')
5152
@click.option('-i', '--ipydebug', is_flag=True, flag_value=True,
5253
help='Enable IPython debugger when re-executing.')
53-
@click.option('--dir', type=ExistingDirPath,
54+
@click.option('-w', '--dir', type=ExistingDirPath,
5455
help='Directory where to run the node in.')
55-
def crash(crashfile, rerun, debug, ipydebug, directory):
56+
def crash(crashfile, rerun, debug, ipydebug, dir):
5657
"""Display Nipype crash files.
5758
5859
For certain crash files, one can rerun a failed node in a temp directory.
@@ -70,11 +71,11 @@ def crash(crashfile, rerun, debug, ipydebug, directory):
7071
sys.excepthook = ultratb.FormattedTB(mode='Verbose',
7172
color_scheme='Linux',
7273
call_pdb=1)
73-
display_crash_file(crashfile, rerun, debug, directory)
74+
display_crash_file(crashfile, rerun, debug, dir)
7475

7576

7677
@cli.command(context_settings=CONTEXT_SETTINGS)
77-
@click.argument('pklz_file', type=ExistingFilePath)
78+
@click.argument('pklz_file', type=ExistingFilePath, callback=check_not_none)
7879
def show(pklz_file):
7980
"""Print the content of Nipype node .pklz file.
8081
@@ -89,7 +90,8 @@ def show(pklz_file):
8990

9091

9192
@cli.command(context_settings=UNKNOWN_OPTIONS)
92-
@click.argument('module', type=PythonModule(), required=False)
93+
@click.argument('module', type=PythonModule(), required=False,
94+
callback=check_not_none)
9395
@click.argument('interface', type=str, required=False)
9496
@click.option('--list', is_flag=True, flag_value=True,
9597
help='List the available Interfaces inside the given module.')
@@ -152,8 +154,10 @@ def convert():
152154
@click.option("-i", "--interface", type=str, required=True,
153155
help="Name of the Nipype interface to export.")
154156
@click.option("-m", "--module", type=PythonModule(), required=True,
157+
callback=check_not_none,
155158
help="Module where the interface is defined.")
156159
@click.option("-o", "--output", type=UnexistingFilePath, required=True,
160+
callback=check_not_none,
157161
help="JSON file name where the Boutiques descriptor will be written.")
158162
@click.option("-t", "--ignored-template-inputs", type=str, multiple=True,
159163
help="Interface inputs ignored in path template creations.")

nipype/scripts/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
UnexistingFilePath = click.Path(dir_okay=False, resolve_path=True)
2525

2626

27+
# validators
28+
def check_not_none(ctx, param, value):
29+
if value is None:
30+
raise click.BadParameter('got {}.'.format(value))
31+
return value
32+
33+
2734
# declare custom click.ParamType
2835
class RegularExpression(click.ParamType):
2936
name = 'regex'

0 commit comments

Comments
 (0)