Skip to content
This repository was archived by the owner on Nov 14, 2024. It is now read-only.

feat: enable pretty output #16

Merged
merged 8 commits into from
Sep 14, 2021
Prev Previous commit
Next Next commit
feat: enable pretty output
  • Loading branch information
johnstcn committed Sep 13, 2021
commit 7df3d0ccc7bfac671a1ce98d449743a20b0ec41a
1 change: 1 addition & 0 deletions internal/cmd/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func NewCommand() *cobra.Command {

checkCmd.PersistentFlags().Int("verbosity", 0, "log level verbosity")
checkCmd.PersistentFlags().String("coder-version", "1.21", "version of Coder")
checkCmd.PersistentFlags().Bool("no-color", false, "disable colorful output")

checkCmd.AddCommand(
kubernetes.NewCommand(),
Expand Down
31 changes: 24 additions & 7 deletions internal/cmd/check/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,20 @@ func run(cmd *cobra.Command, _ []string) error {
currentContext.Namespace = "default"
}

log.Info(cmd.Context(), "kubernetes config:",
slog.F("context", rawConfig.CurrentContext),
slog.F("cluster", currentContext.Cluster),
slog.F("namespace", currentContext.Namespace),
slog.F("authinfo", currentContext.AuthInfo),
noColorFlag, err := cmd.Flags().GetBool("no-color")
if err != nil {
return xerrors.Errorf("parse no-color: %w", err)
}
outputMode := humanwriter.OutputModeEmoji
if noColorFlag {
outputMode = humanwriter.OutputModeText
}
hw := humanwriter.New(
os.Stdout,
humanwriter.WithColors(!noColorFlag),
humanwriter.WithMode(outputMode),
)

hw := humanwriter.New(os.Stdout)

localChecker := local.NewChecker(
local.WithLogger(log),
local.WithCoderVersion(cv),
Expand All @@ -144,6 +149,18 @@ func run(cmd *cobra.Command, _ []string) error {
kube.WithNamespace(currentContext.Namespace),
)

_ = hw.WriteResult(&api.CheckResult{
Name: "kubernetes config",
State: api.StateInfo,
Summary: "using the following context to talk to kubernetes",
Details: map[string]interface{}{
"context": rawConfig.CurrentContext,
"cluster": currentContext.Cluster,
"namespace": currentContext.Namespace,
"authinfo": currentContext.AuthInfo,
},
})

if err := localChecker.Validate(); err != nil {
return xerrors.Errorf("failed to validate local checks: %w", err)
}
Expand Down