summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/spack/spack/cmd/env.py10
-rw-r--r--lib/spack/spack/test/cmd/env.py23
2 files changed, 33 insertions, 0 deletions
diff --git a/lib/spack/spack/cmd/env.py b/lib/spack/spack/cmd/env.py
index 75d573f6fe..5d436624bd 100644
--- a/lib/spack/spack/cmd/env.py
+++ b/lib/spack/spack/cmd/env.py
@@ -88,6 +88,11 @@ def env_activate(args):
)
return 1
+ # Error out when -e, -E, -D flags are given, cause they are ambiguous.
+ if args.env or args.no_env or args.env_dir:
+ tty.die('Calling spack env activate with --env, --env-dir and --no-env '
+ 'is ambiguous')
+
if ev.exists(env) and not args.dir:
spack_env = ev.root(env)
short_name = env
@@ -137,6 +142,11 @@ def env_deactivate(args):
)
return 1
+ # Error out when -e, -E, -D flags are given, cause they are ambiguous.
+ if args.env or args.no_env or args.env_dir:
+ tty.die('Calling spack env deactivate with --env, --env-dir and --no-env '
+ 'is ambiguous')
+
if 'SPACK_ENV' not in os.environ:
tty.die('No environment is currently active.')
diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py
index ea1c660804..d9d6f5483c 100644
--- a/lib/spack/spack/test/cmd/env.py
+++ b/lib/spack/spack/test/cmd/env.py
@@ -4,6 +4,7 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import glob
import os
+from argparse import Namespace
import pytest
from six import StringIO
@@ -11,6 +12,7 @@ from six import StringIO
import llnl.util.filesystem as fs
import llnl.util.link_tree
+import spack.cmd.env
import spack.environment as ev
import spack.hash_types as ht
import spack.modules
@@ -2632,3 +2634,24 @@ def test_query_develop_specs():
assert e.is_develop(Spec('mpich'))
assert not e.is_develop(Spec('mpileaks'))
+
+
+@pytest.mark.parametrize('method', [
+ spack.cmd.env.env_activate,
+ spack.cmd.env.env_deactivate
+])
+@pytest.mark.parametrize(
+ 'env,no_env,env_dir',
+ [
+ ('b', False, None),
+ (None, True, None),
+ (None, False, 'path/'),
+ ])
+def test_activation_and_deactiviation_ambiguities(method, env, no_env, env_dir, capsys):
+ """spack [-e x | -E | -D x/] env [activate | deactivate] y are ambiguous"""
+ args = Namespace(shell='sh', activate_env='a',
+ env=env, no_env=no_env, env_dir=env_dir)
+ with pytest.raises(SystemExit):
+ method(args)
+ _, err = capsys.readouterr()
+ assert 'is ambiguous' in err