class_docstr: Click command class customized for BentoML CLI, allow specifying a default
  command for each group defined.
  
  This command groups will also introduce support for aliases for commands and groups.
  
  Example:
  
  .. code-block:: python
  
      @click.group(cls=BentoMLCommandGroup)
      def cli(): ...
  
      @click.group(name="cloud", aliases=["cloud"], cls=BentoMLCommandGroup)
      def cli(): ...
  
      @cli.command(aliases=["serve-http"])
      def serve(): ...
code: def bentoml_track_usage(
      func: F[P] | WrappedCLI[bool, bool, str | None],
      cmd_group: click.Group,
      **kwargs: t.Any,
  ) -> WrappedCLI[bool]:
      from bentoml._internal.utils.analytics import BENTOML_DO_NOT_TRACK
      from bentoml._internal.utils.analytics import CliEvent
      from bentoml._internal.utils.analytics import cli_events_map
      from bentoml._internal.utils.analytics import track
  
      command_name = kwargs.get("name", func.__name__)
  
      @functools.wraps(func)
      def wrapper(
          do_not_track: bool, *args: P.args, **kwargs: P.kwargs
      ) -> t.Any:
          if do_not_track:
              os.environ[BENTOML_DO_NOT_TRACK] = str(True)
              return func(*args, **kwargs)
  
          start_time = time.time_ns()
  
          def get_tracking_event(return_value: t.Any) -> CliEvent:
              # we only need to pass type checking here for group name
              # since we know the cmd_group.name to be BentoMLCommandGroup
              assert cmd_group.name
  
              if (
                  cmd_group.name in cli_events_map
                  and command_name in cli_events_map[cmd_group.name]
              ):
                  return cli_events_map[cmd_group.name][command_name](
                      cmd_group.name, command_name, return_value
                  )
              return CliEvent(
                  cmd_group=cmd_group.name,
                  cmd_name=command_name,
              )
  
          try:
              return_value = func(*args, **kwargs)
              event = get_tracking_event(return_value)
              duration_in_ns = time.time_ns() - start_time
              event.duration_in_ms = duration_in_ns / 1e6
              track(event)
              return return_value
          except BaseException as e:
              event = get_tracking_event(None)
              duration_in_ns = time.time_ns() - start_time
              event.duration_in_ms = duration_in_ns / 1e6
              event.error_type = type(e).__name__
              event.return_code = (
                  2 if isinstance(e, KeyboardInterrupt) else 1
              )
              track(event)
              raise
  
      return wrapper
  
imports: from __future__ import annotations
  import difflib
  import functools
  import logging
  import os
  import re
  import time
  import typing
  import attr
  import click
  import click_option_group
  from click import ClickException
  from click.exceptions import UsageError
label_desc: Use image node_id 2 for calling the BentoMLCommandGroup obj's underlying member method code with example usage: obj.bentoml_track_usage(func, cmd_group) and returns: wrapper, func, CliEvent, return_value, cli_events_map