diff --git a/datalad_xnat/init.py b/datalad_xnat/init.py index 634d446..7b5c5b2 100644 --- a/datalad_xnat/init.py +++ b/datalad_xnat/init.py @@ -153,17 +153,34 @@ def __call__(url, 'anonymous' if platform.credential_name == 'anonymous' else platform.authenticated_user) projects = platform.get_project_ids() - ui.message( - 'No project name specified. The following projects are ' - 'available on {} for user {}:'.format( + from datalad.ui import ui + if ui.is_interactive: + import inquirer + from inquirer.themes import GreenPassion + message = 'Select a project via arrow keys, ' \ + 'confirm with "Enter"'.format( url, - 'anonymous' if platform.credential_name == 'anonymous' - else platform.authenticated_user)) - for p in sorted(projects): - # list and prep for C&P - # TODO multi-column formatting? - ui.message(" {}".format(quote_cmdlinearg(p))) - return + 'anonymous' if platform.credential_name == 'anonymous' \ + else platform.authenticated_user) + checkbox = [inquirer.List('project', + message=message, + choices=sorted(projects))] + resp = inquirer.prompt(checkbox, theme=GreenPassion()) + lgr.info("Received the following project selection from the " + "interactive prompt: %s", str(resp['project'])) + project = resp['project'] + else: + ui.message( + 'No project name specified. The following projects are ' + 'available on {} for user {}:'.format( + url, + 'anonymous' if platform.credential_name == 'anonymous' + else platform.authenticated_user)) + for p in sorted(projects): + # list and prep for C&P + # TODO multi-column formatting? + ui.message(" {}".format(quote_cmdlinearg(p))) + return # query the specified project to make sure it exists and is accessible try: diff --git a/datalad_xnat/update.py b/datalad_xnat/update.py index 59b14f3..61f764f 100644 --- a/datalad_xnat/update.py +++ b/datalad_xnat/update.py @@ -127,17 +127,43 @@ def __call__(subjects='list', credential=None, dataset=None, ifexists=None, reck # provide subject list if 'list' in subjects: - from datalad.ui import ui subs = platform.get_subject_ids(xnat_project) - ui.message( - 'The following subjects are available for XNAT ' - 'project {}:'.format(xnat_project)) - for s in sorted(subs): - ui.message(" {}".format(quote_cmdlinearg(s))) - ui.message( - 'Specify a specific subject(s) or "all" to download associated ' - 'files for.') - return + from datalad.ui import ui + if ui.is_interactive: + import inquirer + from inquirer.themes import GreenPassion + hit = False + subs.insert(0, 'all') + subs.insert(1, 'cancel') + while not hit: + message = 'Select subject(s) to download from ' \ + 'Project "{}" via arrow keys. ' \ + 'Confirm with "Enter"'.format(xnat_project) + checkbox = [inquirer.Checkbox('subject', + message=message, + choices=subs)] + resp = inquirer.prompt(checkbox, theme=GreenPassion()) + if resp['subject']: + hit = True + else: + ui.message("Please select one or more subjects using " + "the right arrow keys. Unselect with the " + "left arrow key.") + if 'cancel' in resp['subject']: + return + lgr.info("Received the following subject list from an " + "interactive prompt: %s", str(resp['subject'])) + subjects = resp['subject'] + else: + ui.message( + 'The following subjects are available for XNAT ' + 'project {}:'.format(xnat_project)) + for s in sorted(subs): + ui.message(" {}".format(quote_cmdlinearg(s))) + ui.message( + 'Specify a specific subject(s) or "all" to download associated ' + 'files for.') + return # query the specified subject(s) to make sure it exists and is accessible # TODO we culd just take the input subject list at face-value diff --git a/setup.cfg b/setup.cfg index 8402c33..379593b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,6 +16,7 @@ python_requires = >= 3.6 install_requires = datalad >= 0.15.0 requests + inquirer packages = find: include_package_data = True