code: def main(*argv):
      """The main entrypoint to the gpustat CLI."""
      if not argv:
          argv = list(sys.argv)
  
      # attach SIGPIPE handler to properly handle broken pipe
      try:  # sigpipe not available under windows. just ignore in this case
          import signal
  
          signal.signal(signal.SIGPIPE, signal.SIG_DFL)
      except Exception:  # pylint: disable=broad-exception-caught
          pass
  
      # arguments to gpustat
      import argparse
  
      try:
          import shtab
      except ImportError:
          from . import _shtab as shtab
      parser = argparse.ArgumentParser("gpustat")
      shtab.add_argument_to(parser, preamble=SHTAB_PREAMBLE)
  
      def nonnegative_int(value):
          value = int(value)
          if value < 0:
              raise argparse.ArgumentTypeError(
                  "Only non-negative integers are allowed."
              )
          return value
  
      parser_color = parser.add_mutually_exclusive_group()
      parser_color.add_argument(
          "--force-color",
          "--color",
          action="store_true",
          help="Force to output with colors",
      )
      parser_color.add_argument(
          "--no-color",
          action="store_true",
          help="Suppress colored output",
      )
      parser.add_argument("--id", help="Target a specific GPU (index).")
      parser.add_argument(
          "-a",
          "--show-all",
          action="store_true",
          help="Display all gpu properties above",
      )
      parser.add_argument(
          "-c",
          "--show-cmd",
          action="store_true",
          help="Display cmd name of running process",
      )
      parser.add_argument(
          "-f",
          "--show-full-cmd",
          action="store_true",
          default=False,
          help="Display full command and cpu stats of running process",
      )
      parser.add_argument(
          "-u",
          "--show-user",
          action="store_true",
          help="Display username of running process",
      )
      parser.add_argument(
          "-p",
          "--show-pid",
          action="store_true",
          help="Display PID of running process",
      )
      parser.add_argument(
          "-F",
          "--show-fan-speed",
          "--show-fan",
          action="store_true",
          help="Display GPU fan speed",
      )
      codec_choices = ["", "enc", "dec", "enc,dec"]
      parser.add_argument(
          "-e",
          "--show-codec",
          nargs="?",
          const="enc,dec",
          default="",
          choices=codec_choices,
          help="Show encoder/decoder utilization",
      ).complete = get_complete_for_one_or_zero(  # type: ignore
          {"zsh": zsh_choices_to_complete(codec_choices, "codec")}
      )
      power_choices = ["", "draw", "limit", "draw,limit", "limit,draw"]
      parser.add_argument(
          "-P",
          "--show-power",
          nargs="?",
          const="draw,limit",
          choices=power_choices,
          help="Show GPU power usage or draw (and/or limit)",
      ).complete = get_complete_for_one_or_zero(  # type: ignore
          {"zsh": zsh_choices_to_complete(power_choices, "power")}
      )
      parser.add_argument(
          "--json",
          action="store_true",
          default=False,
          help="Print all the information in JSON format",
      )
      parser.add_argument(
          "-i",
          "--interval",
          "--watch",
          nargs="?",
          type=float,
          default=0,
          help="Use watch mode if given; seconds to wait between updates",
      ).complete = get_complete_for_one_or_zero(
          {"zsh": "_numbers float"}
      )  # type: ignore
      parser.add_argument(
          "--no-header",
          dest="show_header",
          action="store_false",
          default=True,
          help="Suppress header message",
      )
      parser.add_argument(
          "--gpuname-width",
          type=nonnegative_int,
          default=None,
          help="The width at which GPU names will be displayed.",
      )
      parser.add_argument(
          "--debug",
          action="store_true",
          default=False,
          help="Allow to print additional informations for debugging.",
      )
      parser.add_argument(
          "--no-processes",
          dest="no_processes",
          action="store_true",
          help="Do not display running process information (memory, user, etc.)",
      )
      parser.add_argument(
          "-v",
          "--version",
          action="version",
          version=("gpustat %s" % __version__),
      )
      args = parser.parse_args(argv[1:])
      # TypeError: GPUStatCollection.print_formatted() got an unexpected keyword argument 'print_completion'
      with suppress(AttributeError):
          del args.print_completion  # type: ignore
      if args.show_all:
          args.show_cmd = True
          args.show_user = True
          args.show_pid = True
          args.show_fan_speed = True
          args.show_codec = "enc,dec"
          args.show_power = "draw,limit"
      del args.show_all  # type: ignore
  
      if args.interval is None:  # with default value
          args.interval = 1.0
      if args.interval > 0:
          args.interval = max(0.1, args.interval)
          if args.json:
              sys.stderr.write(
                  "Error: --json and --interval/-i "
                  "can't be used together.\n"
              )
              sys.exit(1)
  
          loop_gpustat(**vars(args))
      else:
          del args.interval  # type: ignore
          print_gpustat(**vars(args))
  
file_path: gpustat/gpustat/cli.py
imports: import os
  import sys
  import time
  from contextlib import suppress
  from blessed import Terminal
  from gpustat import __version__
  from gpustat.core import GPUStatCollection
label_desc: Use image node_id 5 for calling a global function with example usage: main() and returns: value