bindOutputFlag will add the output flag to the given command and bind the value to the given format pointer
(cmd *cobra.Command, varRef *output.Format)
| 119 | // bindOutputFlag will add the output flag to the given command and bind the |
| 120 | // value to the given format pointer |
| 121 | func bindOutputFlag(cmd *cobra.Command, varRef *output.Format) { |
| 122 | cmd.Flags().VarP(newOutputValue(output.Table, varRef), outputFlag, "o", |
| 123 | "prints the output in the specified format. Allowed values: "+strings.Join(output.Formats(), ", ")) |
| 124 | |
| 125 | err := cmd.RegisterFlagCompletionFunc(outputFlag, func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { |
| 126 | var formatNames []string |
| 127 | for format, desc := range output.FormatsWithDesc() { |
| 128 | formatNames = append(formatNames, fmt.Sprintf("%s\t%s", format, desc)) |
| 129 | } |
| 130 | |
| 131 | // Sort the results to get a deterministic order for the tests |
| 132 | sort.Strings(formatNames) |
| 133 | return formatNames, cobra.ShellCompDirectiveNoFileComp |
| 134 | }) |
| 135 | |
| 136 | if err != nil { |
| 137 | log.Fatal(err) |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | type outputValue output.Format |
| 142 |
no test coverage detected
searching dependent graphs…