(vp *viper.Viper)
| 27 | const notAvailable = "N/A" |
| 28 | |
| 29 | func newNodeCommand(vp *viper.Viper) *cobra.Command { |
| 30 | listCmd := &cobra.Command{ |
| 31 | Use: "nodes", |
| 32 | Aliases: []string{"node"}, |
| 33 | Short: "List Hubble nodes", |
| 34 | RunE: func(cmd *cobra.Command, _ []string) error { |
| 35 | ctx, cancel := context.WithCancel(cmd.Context()) |
| 36 | defer cancel() |
| 37 | hubbleConn, err := conn.NewWithFlags(ctx, vp) |
| 38 | if err != nil { |
| 39 | return err |
| 40 | } |
| 41 | defer hubbleConn.Close() |
| 42 | return runListNodes(ctx, cmd, hubbleConn) |
| 43 | }, |
| 44 | } |
| 45 | |
| 46 | // formatting flags |
| 47 | formattingFlags := pflag.NewFlagSet("Formatting", pflag.ContinueOnError) |
| 48 | formattingFlags.StringVarP( |
| 49 | &listOpts.output, "output", "o", "table", |
| 50 | `Specify the output format, one of: |
| 51 | json: JSON encoding |
| 52 | table: Tab-aligned columns |
| 53 | wide: Tab-aligned columns with additional information`) |
| 54 | listCmd.Flags().AddFlagSet(formattingFlags) |
| 55 | |
| 56 | // advanced completion for flags |
| 57 | listCmd.RegisterFlagCompletionFunc("output", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { |
| 58 | return []string{ |
| 59 | "json", |
| 60 | "table", |
| 61 | "wide", |
| 62 | }, cobra.ShellCompDirectiveDefault |
| 63 | }) |
| 64 | |
| 65 | template.RegisterFlagSets(listCmd, formattingFlags, config.ServerFlags) |
| 66 | return listCmd |
| 67 | } |
| 68 | |
| 69 | func runListNodes(ctx context.Context, cmd *cobra.Command, conn *grpc.ClientConn) error { |
| 70 | req := &observerpb.GetNodesRequest{} |
no test coverage detected
searching dependent graphs…