summaryrefslogtreecommitdiff
path: root/lib/spack/spack/cmd/common/__init__.py
blob: d530bd6176970999b77d1f6983a42c238cc0fe25 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

import llnl.util.tty as tty
import llnl.util.tty.color as color

import spack.paths


def shell_init_instructions(cmd, equivalent):
    """Print out instructions for users to initialize shell support.

    Arguments:
        cmd (str): the command the user tried to run that requires
            shell support in order to work
        equivalent (str): a command they can run instead, without
            enabling shell support
    """

    shell_specific = "{sh_arg}" in equivalent

    msg = [
        "`%s` requires Spack's shell support." % cmd,
        "",
        "To set up shell support, run the command below for your shell.",
        "",
        color.colorize("@*c{For bash/zsh/sh:}"),
        "  . %s/setup-env.sh" % spack.paths.share_path,
        "",
        color.colorize("@*c{For csh/tcsh:}"),
        "  source %s/setup-env.csh" % spack.paths.share_path,
        "",
        color.colorize("@*c{For fish:}"),
        "  source %s/setup-env.fish" % spack.paths.share_path,
        "",
        color.colorize("@*c{For Windows batch:}"),
        "  %s\\spack_cmd.bat" % spack.paths.bin_path,
        "",
        color.colorize("@*c{For PowerShell:}"),
        "  %s\\setup-env.ps1" % spack.paths.share_path,
        "",
        "Or, if you do not want to use shell support, run "
        + ("one of these" if shell_specific else "this")
        + " instead:",
        "",
    ]

    if shell_specific:
        msg += [
            equivalent.format(sh_arg="--sh  ") + "  # bash/zsh/sh",
            equivalent.format(sh_arg="--csh ") + "  # csh/tcsh",
            equivalent.format(sh_arg="--fish") + "  # fish",
            equivalent.format(sh_arg="--bat ") + "  # batch",
            equivalent.format(sh_arg="--pwsh") + "  # powershell",
        ]
    else:
        msg += ["  " + equivalent]

    msg += [
        "",
        "If you have already set up Spack's shell support but still receive",
        "this message, please make sure to call Spack via the `spack` command",
        "without any path components (such as `bin/spack`).",
    ]

    msg += [""]
    tty.error(*msg)