code: def add_env_command(cli: click.Group) -> None:
      from bentoml._internal.utils.pkg import PackageNotFoundError
      from bentoml._internal.utils.pkg import get_pkg_version
      from bentoml.exceptions import CLIException
  
      @cli.command(help=gettext("Print environment info and exit"))
      @click.option(
          "-o",
          "--output",
          type=click.Choice(["md", "bash"]),
          default="md",
          show_default=True,
          help="Output format. '-o bash' to display without format.",
      )
      @click.pass_context
      def env(ctx: click.Context, output: t.Literal["md", "bash"]) -> None:  # type: ignore (unused warning)
          if output not in ["md", "bash"]:
              raise CLIException(f"Unknown output format: {output}")
  
          is_windows = sys.platform == "win32"
  
          info_dict: dict[str, str | list[str]] = {
              "bentoml": importlib.metadata.version("bentoml"),
              "python": platform.python_version(),
              "platform": platform.platform(),
          }
  
          if is_windows:
              from ctypes import windll
  
              # https://stackoverflow.com/a/1026626
              is_admin: bool = windll.shell32.IsUserAnAdmin() != 0
              info_dict["is_window_admin"] = str(is_admin)
          else:
              info_dict["uid_gid"] = f"{os.geteuid()}:{os.getegid()}"
  
          if "CONDA_PREFIX" in os.environ:
              # conda packages
              conda_like = None
              for possible_exec in ["conda", "mamba", "micromamba"]:
                  if shutil.which(possible_exec) is not None:
                      conda_like = possible_exec
                      break
              assert (
                  conda_like is not None
              ), "couldn't find a conda-like executable, while CONDA_PREFIX is set."
              conda_packages = run_cmd([conda_like, "env", "export"])
  
              # user is currently in a conda environment,
              # doing this is faster than invoking `conda --version`
              try:
                  conda_version = get_pkg_version("conda")
              except PackageNotFoundError:
                  conda_version = run_cmd([conda_like, "--version"])[
                      0
                  ].split(" ")[-1]
  
              info_dict[conda_like] = conda_version
              info_dict["in_conda_env"] = str(True)
              info_dict["conda_packages"] = conda_packages
  
          # process info from `pip freeze`
          pip_packages = run_cmd(
              [sys.executable, "-m", "pip", "freeze"]
          )
          info_dict["pip_packages"] = pip_packages
          click.echo(pretty_format(info_dict, output=output))
          ctx.exit(0)
  
file_path: BentoML/src/bentoml_cli/env.py
imports: from __future__ import annotations
  import importlib.metadata
  import os
  import platform
  import shlex
  import shutil
  import subprocess
  import sys
  import typing
  from gettext import gettext
  import click
label_desc: Use image node_id 7 for calling a global function with example usage: add_env_command(cli) without return types