diff --git a/pkg/cli/commands/repo/get/command.go b/pkg/cli/commands/repo/get/command.go index d72aeabe..70c23450 100644 --- a/pkg/cli/commands/repo/get/command.go +++ b/pkg/cli/commands/repo/get/command.go @@ -79,6 +79,13 @@ func (r *runner) preRunE(cmd *cobra.Command, _ []string) error { } else { r.requestTable = true } + + allNamespacesFlag := cmd.Flags().Lookup("all-namespaces").Value.String() + if strings.Contains(allNamespacesFlag, "true") { + r.printFlags.HumanReadableFlags.WithNamespace = true + } else { + r.printFlags.HumanReadableFlags.WithNamespace = false + } return nil } diff --git a/pkg/cli/commands/repo/reg/command.go b/pkg/cli/commands/repo/reg/command.go index 7121e205..79e5220a 100644 --- a/pkg/cli/commands/repo/reg/command.go +++ b/pkg/cli/commands/repo/reg/command.go @@ -88,6 +88,15 @@ type runner struct { func (r *runner) preRunE(_ *cobra.Command, _ []string) error { const op errors.Op = command + ".preRunE" + if *r.cfg.Namespace == "" { + // Get the namespace from kubeconfig + namespace, _, err := r.cfg.ToRawKubeConfigLoader().Namespace() + if err != nil { + return fmt.Errorf("error getting namespace: %w", err) + } + r.cfg.Namespace = &namespace + } + client, err := porch.CreateClientWithFlags(r.cfg) if err != nil { return errors.E(op, err) diff --git a/pkg/cli/commands/repo/unreg/command.go b/pkg/cli/commands/repo/unreg/command.go index a853248a..f94fcc44 100644 --- a/pkg/cli/commands/repo/unreg/command.go +++ b/pkg/cli/commands/repo/unreg/command.go @@ -71,6 +71,15 @@ type runner struct { func (r *runner) preRunE(_ *cobra.Command, _ []string) error { const op errors.Op = command + ".preRunE" + if *r.cfg.Namespace == "" { + // Get the namespace from kubeconfig + namespace, _, err := r.cfg.ToRawKubeConfigLoader().Namespace() + if err != nil { + return fmt.Errorf("error getting namespace: %w", err) + } + r.cfg.Namespace = &namespace + } + client, err := porch.CreateClientWithFlags(r.cfg) if err != nil { return errors.E(op, err)