public static CommandService createLocalCommandService(Cache cache)
      throws CommandServiceException {
    if (cache == null) {
      throw new CacheClosedException("Can not create command service as cache doesn't exist.");
    } else if (cache.isClosed()) {
      throw ((InternalCache) cache)
          .getCacheClosedException("Can not create command service as cache is closed.");
    }

    if (localCommandService == null || !localCommandService.isUsable()) {
      String nonExistingDependency = CliUtils.cliDependenciesExist(false);
      if (nonExistingDependency != null) {
        throw new DependenciesNotFoundException(
            String.format(
                "Could not find %s library which is needed for CLI/gfsh in classpath. Internal support for CLI & gfsh is not enabled. Note: For convenience, absolute path of gfsh-dependencies.jar from lib directory of GemFire product distribution can be included in CLASSPATH of an application.",
                nonExistingDependency));
      }

      localCommandService =
          new org.apache.geode.management.internal.cli.remote.MemberCommandService(
              (InternalCache) cache);
    }

    return localCommandService;
  }
Returns a newly created or existing instance of the
<code>CommandService</code> associated with the
specified <code>Cache</code>.

@param cache Underlying <code>Cache</code> instance to be used to create a Command Service.
@return a newly created or existing instance of the <code>CommandService</code> associated with
        the specified <code>Cache</code>
@throws CommandServiceException If command service could not be initialized.
geode-gfsh/src/main/java/org/apache/geode/management/cli/CommandService.java