test(cli): Improve speedtest debugging (#6341)

This commit is contained in:
Mathias Fredriksson
2023-02-24 20:09:16 +02:00
committed by GitHub
parent 29dbfe067c
commit 5876dc1f97
3 changed files with 24 additions and 1 deletions
+17
View File
@@ -19,6 +19,8 @@ import (
"golang.org/x/xerrors"
"cdr.dev/slog"
"github.com/charmbracelet/lipgloss"
"github.com/kirsle/configdir"
"github.com/mattn/go-isatty"
@@ -179,6 +181,21 @@ func Root(subcommands []*cobra.Command) *cobra.Command {
return cmd
}
type contextKey int
const (
contextKeyLogger contextKey = iota
)
func ContextWithLogger(ctx context.Context, l slog.Logger) context.Context {
return context.WithValue(ctx, contextKeyLogger, l)
}
func LoggerFromContext(ctx context.Context) (slog.Logger, bool) {
l, ok := ctx.Value(contextKeyLogger).(slog.Logger)
return l, ok
}
// fixUnknownSubcommandError modifies the provided commands so that the
// ones with subcommands output the correct error message when an
// unknown subcommand is invoked.