mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
test(cli): Improve speedtest debugging (#6341)
This commit is contained in:
+17
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user