cli: better formatting of lists (#2951)

This commit is contained in:
Kristoffer Dalby
2025-12-10 12:33:21 +01:00
committed by GitHub
parent c8376e44a2
commit f3f2d30004
2 changed files with 14 additions and 11 deletions

View File

@@ -562,23 +562,26 @@ func nodesToPtables(
var forcedTags string var forcedTags string
for _, tag := range node.GetForcedTags() { for _, tag := range node.GetForcedTags() {
forcedTags += "," + tag forcedTags += "\n" + tag
} }
forcedTags = strings.TrimLeft(forcedTags, ",")
forcedTags = strings.TrimLeft(forcedTags, "\n")
var invalidTags string var invalidTags string
for _, tag := range node.GetInvalidTags() { for _, tag := range node.GetInvalidTags() {
if !slices.Contains(node.GetForcedTags(), tag) { if !slices.Contains(node.GetForcedTags(), tag) {
invalidTags += "," + pterm.LightRed(tag) invalidTags += "\n" + pterm.LightRed(tag)
} }
} }
invalidTags = strings.TrimLeft(invalidTags, ",")
invalidTags = strings.TrimLeft(invalidTags, "\n")
var validTags string var validTags string
for _, tag := range node.GetValidTags() { for _, tag := range node.GetValidTags() {
if !slices.Contains(node.GetForcedTags(), tag) { if !slices.Contains(node.GetForcedTags(), tag) {
validTags += "," + pterm.LightGreen(tag) validTags += "\n" + pterm.LightGreen(tag)
} }
} }
validTags = strings.TrimLeft(validTags, ",")
validTags = strings.TrimLeft(validTags, "\n")
var user string var user string
if currentUser == "" || (currentUser == node.GetUser().GetName()) { if currentUser == "" || (currentUser == node.GetUser().GetName()) {
@@ -640,9 +643,9 @@ func nodeRoutesToPtables(
nodeData := []string{ nodeData := []string{
strconv.FormatUint(node.GetId(), util.Base10), strconv.FormatUint(node.GetId(), util.Base10),
node.GetGivenName(), node.GetGivenName(),
strings.Join(node.GetApprovedRoutes(), ", "), strings.Join(node.GetApprovedRoutes(), "\n"),
strings.Join(node.GetAvailableRoutes(), ", "), strings.Join(node.GetAvailableRoutes(), "\n"),
strings.Join(node.GetSubnetRoutes(), ", "), strings.Join(node.GetSubnetRoutes(), "\n"),
} }
tableData = append( tableData = append(
tableData, tableData,

View File

@@ -107,10 +107,10 @@ var listPreAuthKeys = &cobra.Command{
aclTags := "" aclTags := ""
for _, tag := range key.GetAclTags() { for _, tag := range key.GetAclTags() {
aclTags += "," + tag aclTags += "\n" + tag
} }
aclTags = strings.TrimLeft(aclTags, ",") aclTags = strings.TrimLeft(aclTags, "\n")
tableData = append(tableData, []string{ tableData = append(tableData, []string{
strconv.FormatUint(key.GetId(), 10), strconv.FormatUint(key.GetId(), 10),