diff --git a/pkg/cmd/tknpac/info/templates/info.tmpl b/pkg/cmd/tknpac/info/templates/info.tmpl index 020a2fe0e9..2145f3652a 100644 --- a/pkg/cmd/tknpac/info/templates/info.tmpl +++ b/pkg/cmd/tknpac/info/templates/info.tmpl @@ -14,7 +14,7 @@ Webhook URL: {{ .Info.HookConfig.URL }} {{- end }} {{- end }} -{{- if (gt (len .Repos) 1) }} +{{- if (gt (len .Repos) 0) }} {{ $.CS.Underline "Repositories CR" }}: {{ len .Repos }} Namespace URL diff --git a/pkg/params/info/kube.go b/pkg/params/info/kube.go index b415eb9fe3..c48ca979ac 100644 --- a/pkg/params/info/kube.go +++ b/pkg/params/info/kube.go @@ -36,7 +36,7 @@ func (k *KubeOpts) AddFlags(cmd *cobra.Command) { fmt.Sprintf("Path to the kubeconfig file to use for CLI requests (default: %s)", envkconfig)) cmd.PersistentFlags().StringVarP( - &k.ConfigPath, + &k.Namespace, "namespace", "n", "", "If present, the namespace scope for this CLI request") } diff --git a/pkg/params/info/kube_test.go b/pkg/params/info/kube_test.go index ac193e1809..d22e5c46d8 100644 --- a/pkg/params/info/kube_test.go +++ b/pkg/params/info/kube_test.go @@ -50,3 +50,58 @@ func TestKubeOptsWithEnv(t *testing.T) { }) } } + +func TestKubeOptsFlags(t *testing.T) { + t.Setenv("HOME", "/home/user") + t.Setenv("KUBECONFIG", "") + defaultKubeconfigPath := "/home/user/.kube/config" + customKubeconfigPath := "/custom/kube/config" + + testcases := []struct { + name string + flags []string + expectNS string + expectCfg string + }{ + { + name: "namespace flag only", + flags: []string{"--namespace", "test-ns"}, + expectNS: "test-ns", + expectCfg: defaultKubeconfigPath, + }, + { + name: "namespace flag short form", + flags: []string{"-n", "test-ns"}, + expectNS: "test-ns", + expectCfg: defaultKubeconfigPath, + }, + { + name: "kubeconfig flag only", + flags: []string{"--kubeconfig", customKubeconfigPath}, + expectNS: "", + expectCfg: customKubeconfigPath, + }, + { + name: "both flags together", + flags: []string{"--namespace", "test-ns", "--kubeconfig", customKubeconfigPath}, + expectNS: "test-ns", + expectCfg: customKubeconfigPath, + }, + { + name: "both flags short form", + flags: []string{"-n", "test-ns", "-k", customKubeconfigPath}, + expectNS: "test-ns", + expectCfg: customKubeconfigPath, + }, + } + for _, tc := range testcases { + t.Run(tc.name, func(t *testing.T) { + k := &KubeOpts{} + cmd := &cobra.Command{} + k.AddFlags(cmd) + assert.NilError(t, cmd.ParseFlags(tc.flags)) + assert.Equal(t, k.Namespace, tc.expectNS, "namespace mismatch") + assert.Equal(t, k.ConfigPath, tc.expectCfg, "config path mismatch") + }) + } +}