mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-05-31 03:16:14 +00:00
Fix color in kubens success message when using fzf (#228)
This commit is contained in:
parent
9527e308e5
commit
8c323c5653
@ -20,7 +20,7 @@ func (op DeleteOp) Run(_, stderr io.Writer) error {
|
||||
// TODO inefficency here. we open/write/close the same file many times.
|
||||
deletedName, wasActiveContext, err := deleteContext(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error deleting context %q", deletedName)
|
||||
return errors.Wrapf(err, "error deleting context \"%s\"", deletedName)
|
||||
}
|
||||
if wasActiveContext {
|
||||
printer.Warning(stderr, "You deleted the current context. Use \"%s\" to select a new context.",
|
||||
|
@ -54,6 +54,6 @@ func (op InteractiveSwitchOp) Run(_, stderr io.Writer) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to switch context")
|
||||
}
|
||||
printer.Success(stderr, "Switched to context %s.", printer.SuccessColor.Sprint(name))
|
||||
printer.Success(stderr, "Switched to context \"%s\".", printer.SuccessColor.Sprint(name))
|
||||
return nil
|
||||
}
|
||||
|
@ -14,10 +14,10 @@ func TestPrintHelp(t *testing.T) {
|
||||
|
||||
out := buf.String()
|
||||
if !strings.Contains(out, "USAGE:") {
|
||||
t.Errorf("help string doesn't contain USAGE: ; output=%q", out)
|
||||
t.Errorf("help string doesn't contain USAGE: ; output=\"%s\"", out)
|
||||
}
|
||||
|
||||
if !strings.HasSuffix(out, "\n") {
|
||||
t.Errorf("does not end with New line; output=%q", out)
|
||||
t.Errorf("does not end with New line; output=\"%s\"", out)
|
||||
}
|
||||
}
|
||||
|
@ -46,11 +46,11 @@ func (op RenameOp) Run(_, stderr io.Writer) error {
|
||||
}
|
||||
|
||||
if !kc.ContextExists(op.Old) {
|
||||
return errors.Errorf("context %q not found, can't rename it", op.Old)
|
||||
return errors.Errorf("context \"%s\" not found, can't rename it", op.Old)
|
||||
}
|
||||
|
||||
if kc.ContextExists(op.New) {
|
||||
printer.Warning(stderr, "context %q exists, overwriting it.", op.New)
|
||||
printer.Warning(stderr, "context \"%s\" exists, overwriting it.", op.New)
|
||||
if err := kc.DeleteContextEntry(op.New); err != nil {
|
||||
return errors.Wrap(err, "failed to delete new context to overwrite it")
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ func Test_readLastContext_nonExistingFile(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if s != "" {
|
||||
t.Fatalf("expected empty string; got=%q", s)
|
||||
t.Fatalf("expected empty string; got=\"%s\"", s)
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ func Test_readLastContext(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if expected := "foo"; s != expected {
|
||||
t.Fatalf("expected=%q; got=%q", expected, s)
|
||||
t.Fatalf("expected=\"%s\"; got=\"%s\"", expected, s)
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ func Test_writeLastContext(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if expected := "ctx1"; v != expected {
|
||||
t.Fatalf("read wrong value=%q; expected=%q", v, expected)
|
||||
t.Fatalf("read wrong value=\"%s\"; expected=\"%s\"", v, expected)
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ func Test_kubectxFilePath(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if v != expected {
|
||||
t.Fatalf("expected=%q got=%q", expected, v)
|
||||
t.Fatalf("expected=\"%s\" got=\"%s\"", expected, v)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ func (op SwitchOp) Run(_, stderr io.Writer) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to switch context")
|
||||
}
|
||||
err = printer.Success(stderr, "Switched to context %q.", newCtx)
|
||||
err = printer.Success(stderr, "Switched to context \"%s\".", printer.SuccessColor.Sprint(newCtx))
|
||||
return errors.Wrap(err, "print error")
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ func switchContext(name string) (string, error) {
|
||||
|
||||
prev := kc.GetCurrentContext()
|
||||
if !kc.ContextExists(name) {
|
||||
return "", errors.Errorf("no context exists with the name: %q", name)
|
||||
return "", errors.Errorf("no context exists with the name: \"%s\"", name)
|
||||
}
|
||||
if err := kc.ModifyCurrentContext(name); err != nil {
|
||||
return "", err
|
||||
|
@ -24,7 +24,7 @@ func (c CurrentOp) Run(stdout, _ io.Writer) error {
|
||||
}
|
||||
ns, err := kc.NamespaceOfContext(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to read namespace of %q", ctx)
|
||||
return errors.Wrapf(err, "failed to read namespace of \"%s\"", ctx)
|
||||
}
|
||||
_, err = fmt.Fprintln(stdout, ns)
|
||||
return errors.Wrap(err, "write error")
|
||||
|
@ -55,6 +55,6 @@ func (op InteractiveSwitchOp) Run(_, stderr io.Writer) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to switch namespace")
|
||||
}
|
||||
printer.Success(stderr, "Active namespace is %q.", printer.SuccessColor.Sprint(name))
|
||||
printer.Success(stderr, "Active namespace is \"%s\".", printer.SuccessColor.Sprint(name))
|
||||
return nil
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ func TestNSFile(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if expected := "bar"; v != expected {
|
||||
t.Fatalf("Load()=%q; expected=%q", v, expected)
|
||||
t.Fatalf("Load()=\"%s\"; expected=\"%s\"", v, expected)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ func (s SwitchOp) Run(_, stderr io.Writer) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = printer.Success(stderr, "Active namespace is %q", toNS)
|
||||
err = printer.Success(stderr, "Active namespace is \"%s\"", printer.SuccessColor.Sprint(toNS))
|
||||
return err
|
||||
}
|
||||
|
||||
@ -59,11 +59,11 @@ func switchNamespace(kc *kubeconfig.Kubeconfig, ns string) (string, error) {
|
||||
return "", errors.Wrap(err, "failed to query if namespace exists (is cluster accessible?)")
|
||||
}
|
||||
if !ok {
|
||||
return "", errors.Errorf("no namespace exists with name %q", ns)
|
||||
return "", errors.Errorf("no namespace exists with name \"%s\"", ns)
|
||||
}
|
||||
|
||||
if err := kc.SetNamespace(ctx, ns); err != nil {
|
||||
return "", errors.Wrapf(err, "failed to change to namespace %q", ns)
|
||||
return "", errors.Wrapf(err, "failed to change to namespace \"%s\"", ns)
|
||||
}
|
||||
if err := kc.Save(); err != nil {
|
||||
return "", errors.Wrap(err, "failed to save kubeconfig file")
|
||||
|
@ -26,9 +26,9 @@ func TestPrintDeprecatedEnvWarnings_bgColors(t *testing.T) {
|
||||
})
|
||||
v := out.String()
|
||||
if !strings.Contains(v, "KUBECTX_CURRENT_FGCOLOR") {
|
||||
t.Fatalf("output doesn't contain 'KUBECTX_CURRENT_FGCOLOR': %q", v)
|
||||
t.Fatalf("output doesn't contain 'KUBECTX_CURRENT_FGCOLOR': \"%s\"", v)
|
||||
}
|
||||
if !strings.Contains(v, "KUBECTX_CURRENT_BGCOLOR") {
|
||||
t.Fatalf("output doesn't contain 'KUBECTX_CURRENT_BGCOLOR': %q", v)
|
||||
t.Fatalf("output doesn't contain 'KUBECTX_CURRENT_BGCOLOR': \"%s\"", v)
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ func (k *Kubeconfig) contextNode(name string) (*yaml.Node, error) {
|
||||
return contextNode, nil
|
||||
}
|
||||
}
|
||||
return nil, errors.Errorf("context with name %q not found", name)
|
||||
return nil, errors.Errorf("context with name \"%s\" not found", name)
|
||||
}
|
||||
|
||||
func (k *Kubeconfig) ContextNames() []string {
|
||||
|
@ -16,7 +16,7 @@ func TestKubeconfig_GetCurrentContext(t *testing.T) {
|
||||
|
||||
expected := "foo"
|
||||
if v != expected {
|
||||
t.Fatalf("expected=%q; got=%q", expected, v)
|
||||
t.Fatalf("expected=\"%s\"; got=\"%s\"", expected, v)
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ func TestKubeconfig_GetCurrentContext_missingField(t *testing.T) {
|
||||
|
||||
expected := ""
|
||||
if v != expected {
|
||||
t.Fatalf("expected=%q; got=%q", expected, v)
|
||||
t.Fatalf("expected=\"%s\"; got=\"%s\"", expected, v)
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,6 +50,6 @@ func TestKubeconfig_UnsetCurrentContext(t *testing.T) {
|
||||
out := tl.Output()
|
||||
expected := testutil.KC().WithCurrentCtx("").ToYAML(t)
|
||||
if out != expected {
|
||||
t.Fatalf("expected=%q; got=%q", expected, out)
|
||||
t.Fatalf("expected=\"%s\"; got=\"%s\"", expected, out)
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ func TestKubeconfig_NamespaceOfContext(t *testing.T) {
|
||||
t.Fatal("expected err")
|
||||
}
|
||||
if expected := `default`; v1 != expected {
|
||||
t.Fatalf("c1: expected=%q got=%q", expected, v1)
|
||||
t.Fatalf("c1: expected=\"%s\" got=\"%s\"", expected, v1)
|
||||
}
|
||||
|
||||
v2, err := kc.NamespaceOfContext("c2")
|
||||
@ -43,7 +43,7 @@ func TestKubeconfig_NamespaceOfContext(t *testing.T) {
|
||||
t.Fatal("expected err")
|
||||
}
|
||||
if expected := `c2n1`; v2 != expected {
|
||||
t.Fatalf("c2: expected=%q got=%q", expected, v2)
|
||||
t.Fatalf("c2: expected=\"%s\" got=\"%s\"", expected, v2)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user