github.com/telepresenceio/telepresence/v2@v2.20.0-pro.6.0.20240517030216-236ea954e789/pkg/client/cli/cmd/list_namespaces.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 6 "github.com/spf13/cobra" 7 8 "github.com/telepresenceio/telepresence/v2/pkg/client/cli/daemon" 9 "github.com/telepresenceio/telepresence/v2/pkg/client/cli/output" 10 ) 11 12 type listNamespacesCommand struct { 13 rq *daemon.CobraRequest 14 } 15 16 func listNamespaces() *cobra.Command { 17 lnc := &listNamespacesCommand{} 18 19 cmd := &cobra.Command{ 20 Use: "list-namespaces", 21 Args: cobra.NoArgs, 22 Short: "Show all namespaces", 23 RunE: lnc.run, 24 } 25 lnc.rq = daemon.InitRequest(cmd) 26 return cmd 27 } 28 29 func (lnc *listNamespacesCommand) run(cmd *cobra.Command, _ []string) error { 30 nss, err := lnc.rq.GetAllNamespaces(cmd) 31 if err != nil { 32 return err 33 } 34 35 ctx := cmd.Context() 36 if output.WantsFormatted(cmd) { 37 output.Object(ctx, nss, false) 38 } else { 39 for _, ns := range nss { 40 fmt.Fprintln(output.Out(ctx), ns) 41 } 42 } 43 return nil 44 }