You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: run.go
    path of file: ./repos/cerbos/cmd/cerbos/run
    
    the code of the file until where you have to start completion: // Copyright 2021-2024 Zenauth Ltd.
// SPDX-License-Identifier: Apache-2.0

package run

import (
	"context"
	"crypto/tls"
	"errors"
	"fmt"
	"io"
	"net/http"
	"os"
	"os/signal"
	"path/filepath"
	"strings"
	"sync"
	"syscall"
	"time"

	"github.com/alecthomas/kong"
	"github.com/go-cmd/cmd"
	"go.uber.org/automaxprocs/maxprocs"
	"go.uber.org/zap"
	"helm.sh/helm/v3/pkg/strvals"

	"github.com/cerbos/cerbos/internal/config"
	"github.com/cerbos/cerbos/internal/observability/logging"
	"github.com/cerbos/cerbos/internal/server"
)

const (
	help = `
Launches a command within the context of a Cerbos PDP. The policies are loaded by default from a directory named "policies" in the current working directory. The launched application can access Cerbos endpoints using the values from CERBOS_HTTP or CERBOS_GRPC environment variables.

If a file named ".cerbos.yaml" exists in the current working directory, it will be used as the configuration file for the PDP. You can override the config file and/or other configuration options using the flags described below.

Examples:

# Launch Go tests within a Cerbos context

cerbos run -- go test ./...

# Start Cerbos with a custom configuration file and run Python tests within the context

cerbos run
    
func (c *Cmd) Run(k *kong.Kong) error {
	notifyCtx, stopFunc := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
	defer stopFunc()

	logging.InitLogging(notifyCtx, c.LogLevel)
	defer zap.L().Sync() //nolint:errcheck

	log := zap.S().Named("run")

	undo, _ := maxprocs.Set(maxprocs.Logger(log.Infof))
	defer undo()

	if err := c.loadConfig(); err != nil {
		log.Errorw("Failed to load configuration", "error", err)
		return err
	}

	pdp, err := c.startPDP(notifyCtx)
	if err != nil {
		log.Errorw("Failed to start the PDP", "error", err)
		return err
	}

	command := c.prepCommand(pdp, k.Stdout, k.Stderr)
	statusChan := command.Start()

	cleanup := func() {
		if cerr := command.Stop(); cerr != nil && !errors.Is(cerr, cmd.ErrNotStarted) {
			log.Errorw("Error stopping command", "error", cerr)
		}

		pdp.stopFn()
		c.wg.Wait()
	}

	select {
	case err := <-pdp.errors:
		log.Errorw("Cerbos PDP error", "error", err)
		cleanup()

		return err
	case status := <-statusChan:
		if status.Error != nil {
			log.Errorw("Command execution error", "error", err)
			cleanup()

			return err
		}

		if status.Complete {
			log.Infof("Command finished with status %d", status.Exit)
		}

		cleanup()

		if status.Exit != 0 {
			stopFunc()
			undo()
			k.Exit(status.Exit)
		}
	case <-notifyCtx.Done():
		log.Info("Terminated by signal")
		cleanup()
	}

	return nil
}