Code review comments and more docs
@@ -28,22 +28,23 @@ import (
type ContainerToolListCommand struct {
*ContainerToolCommandBase
OutputList []interface{}
- SummaryObject interface{}
- SummaryTemplate string
// RunO Executes cobra.Command.Run and returns an List[Output]
RunO func(command *cobra.Command, args []string) ([]interface{}, error)
// When defined, StreamO Executes cobra.Command.Run and streams each item in the List as its added.
// This will ignore the RunO function.
StreamO func(command *cobra.Command, args []string)
- // This function will execute execute over the output and return a Summary Object which can be printed.
+ // This function will execute over the output list and return a Summary Object which can be printed.
+ // The SummaryTemplate Field can be used to print the Object.
TotalO func(list []interface{}) (interface{}, error)
+ SummaryObject interface{}
+ SummaryTemplate string
+ // Defines the stream to write objects to when using StreamO
Stream chan interface{}
}
func (commandList ContainerToolListCommand) ReadFromStream() ([]interface{}, error) {
results := make([]interface{}, 0)
for obj := range commandList.Stream {
- results = append(results, obj)
if _, ok := obj.(string); ok {
// Display any Arbitary strings written to the channel as is.
// These could be headers or any text.
@@ -52,6 +53,7 @@ func (commandList ContainerToolListCommand) ReadFromStream() ([]interface{}, err
obj, commandList.TemplateFuncMap, commandList.OutOrStdout())
continue
}
+ results = append(results, obj)
err := util.ExecuteTemplate(commandList.ReadTemplateFromFlagOrCmdDefault(),
obj, commandList.TemplateFuncMap, commandList.OutOrStdout())
if err != nil {
