Setters: support for setting string list fields

This commit is contained in:
Phillip Wittrock
2020-03-07 13:53:24 -08:00
parent 0b1ad031a9
commit 370502ed4b
13 changed files with 320 additions and 57 deletions

View File

@@ -7,6 +7,7 @@ import (
"fmt"
"io"
"os"
"strings"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
@@ -67,8 +68,15 @@ func (r *ListSettersRunner) runE(c *cobra.Command, args []string) error {
table.SetHeader([]string{"NAME", "VALUE", "SET BY", "DESCRIPTION", "COUNT"})
for i := range r.List.Setters {
s := r.List.Setters[i]
v := s.Value
// if the setter is for a list, populate the values
if len(s.ListValues) > 0 {
v = strings.Join(s.ListValues, ",")
v = fmt.Sprintf("[%s]", v)
}
table.Append([]string{
s.Name, s.Value, s.SetBy, s.Description, fmt.Sprintf("%d", s.Count)})
s.Name, v, s.SetBy, s.Description, fmt.Sprintf("%d", s.Count)})
}
table.Render()

View File

@@ -21,7 +21,7 @@ func NewSetRunner(parent string) *SetRunner {
r := &SetRunner{}
c := &cobra.Command{
Use: "set DIR NAME [VALUE]",
Args: cobra.RangeArgs(1, 3),
Args: cobra.MinimumNArgs(3),
Short: commands.SetShort,
Long: commands.SetLong,
Example: commands.SetExamples,
@@ -94,6 +94,11 @@ func (r *SetRunner) preRunE(c *cobra.Command, args []string) error {
var err error
r.Set.Name = args[1]
r.Set.Value = args[2]
// set remaining values as list values
if len(args) > 3 {
r.Set.ListValues = args[3:]
}
r.Set.Description = r.Perform.Description
r.Set.SetBy = r.Perform.SetBy
r.OpenAPIFile, err = ext.GetOpenAPIFile(args)