Files
warewulf/internal/app/wwctl/profile/list/main.go
Jonathon Anderson e99e8c3dbb Update use of wwlog.Info to specify a format string
Since wwlog.Info() expect a format string, accidental inclusion of a
format string in the payload causes an error.

See also #1382, #1363

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
2024-09-25 13:49:11 -06:00

46 lines
1.2 KiB
Go

package list
import (
"strings"
"github.com/warewulf/warewulf/internal/app/wwctl/helper"
apiprofile "github.com/warewulf/warewulf/internal/pkg/api/profile"
"github.com/warewulf/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
)
func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) (err error) {
return func(cmd *cobra.Command, args []string) (err error) {
if len(args) > 0 && strings.Contains(args[0], ",") {
args = strings.FieldsFunc(args[0], func(r rune) bool { return r == ',' })
}
req := wwapiv1.GetProfileList{
ShowAll: vars.showAll,
ShowFullAll: vars.showFullAll,
ShowYaml: vars.showYaml,
ShowJson: vars.showJson,
Profiles: args,
}
profileInfo, err := apiprofile.ProfileList(&req)
if err != nil {
return
}
if len(profileInfo.Output) > 0 {
if vars.showYaml || vars.showJson {
wwlog.Info(profileInfo.Output[0])
} else {
ph := helper.New(strings.Split(profileInfo.Output[0], ":=:"))
for _, val := range profileInfo.Output[1:] {
ph.Append(strings.Split(val, ":=:"))
}
ph.Render()
wwlog.Info("%s", ph.String())
}
}
return
}
}