diff --git a/conda/cli/conda_argparse.py b/conda/cli/conda_argparse.py index b4279c719e2..1394248f7ef 100644 --- a/conda/cli/conda_argparse.py +++ b/conda/cli/conda_argparse.py @@ -21,6 +21,7 @@ from .. import __version__ from ..auxlib.ish import dals +from ..auxlib.compat import isiterable from ..base.constants import COMPATIBLE_SHELLS, CONDA_HOMEPAGE_URL, DepsModifier, \ UpdateModifier, ExperimentalSolverChoice from ..common.constants import NULL @@ -173,6 +174,14 @@ def print_help(self): builder.extend(' %s' % cmd for cmd in sorted(other_commands)) print('\n'.join(builder)) + def _check_value(self, action, value): + # extend to properly handle when we accept multiple choices and the default is a list + if action.choices is not None and isiterable(value): + for element in value: + super()._check_value(action, element) + else: + super()._check_value(action, value) + def _exec(executable_args, env_vars): return (_exec_win if on_win else _exec_unix)(executable_args, env_vars) @@ -723,10 +732,14 @@ def configure_parser_init(sub_parsers): p.add_argument( 'shells', nargs='*', - help="One or more shells to be initialized. If not given, the default value is " - "'bash' on unix and 'cmd.exe' on Windows. Use the '--all' flag to initialize " - "all shells. Currently compatible shells are {%s}." - % ", ".join(sorted(COMPATIBLE_SHELLS)), + choices=COMPATIBLE_SHELLS, + metavar="SHELLS", + help=( + "One or more shells to be initialized. If not given, the default value is 'bash' on " + "unix and 'cmd.exe' & 'powershell' on Windows. Use the '--all' flag to initialize all " + f"shells. Available shells: {sorted(COMPATIBLE_SHELLS)}" + ), + default=["cmd.exe", "powershell"] if on_win else ["bash"], ) if on_win: diff --git a/conda/cli/main_init.py b/conda/cli/main_init.py index e6b5d1eeb8b..91a37768dfb 100644 --- a/conda/cli/main_init.py +++ b/conda/cli/main_init.py @@ -7,6 +7,7 @@ from ..base.context import context from ..common.compat import on_win +from ..exceptions import ArgumentError log = getLogger(__name__) @@ -18,26 +19,15 @@ def execute(args, parser): if args.install: return install(context.conda_prefix) - invalid_shells = tuple(s for s in args.shells if s not in COMPATIBLE_SHELLS) - if invalid_shells: - from ..exceptions import ArgumentError - from ..common.io import dashlist - raise ArgumentError("Invalid shells: %s\n\n" - "Currently available shells are:%s" - % (dashlist(invalid_shells), dashlist(sorted(COMPATIBLE_SHELLS)))) - if args.all: selected_shells = COMPATIBLE_SHELLS else: selected_shells = tuple(args.shells) - if not selected_shells: - selected_shells = ('cmd.exe', 'powershell') if on_win else ('bash',) - if args.dev: - assert len(selected_shells) == 1, "--dev can only handle one shell at a time right now" - shell = selected_shells[0] - return initialize_dev(shell) + if len(selected_shells) != 1: + raise ArgumentError("--dev can only handle one shell at a time right now") + return initialize_dev(selected_shells[0]) else: for_user = args.user