use tablewriter to format the output
Signed-off-by: jason yang <jasonyangshadow@gmail.com>
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
package list
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/app/wwctl/helper"
|
||||
"github.com/hpcng/warewulf/internal/pkg/api/container"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
@@ -11,24 +12,25 @@ import (
|
||||
)
|
||||
|
||||
func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
||||
|
||||
containerInfo, err := container.ContainerList()
|
||||
if err != nil {
|
||||
wwlog.Error("%s", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("%-16s %-6s %-16s %-20s %-20s %-8s\n", "CONTAINER NAME", "NODES", "KERNEL VERSION", "CREATION TIME", "MODIFICATION TIME", "SIZE")
|
||||
ph := helper.NewPrintHelper([]string{"CONTAINER NAME", "NODES", "KERNEL VERSION", "CREATION TIME", "MODIFICATION TIME", "SIZE"})
|
||||
for i := 0; i < len(containerInfo); i++ {
|
||||
createTime := time.Unix(int64(containerInfo[i].CreateDate), 0)
|
||||
modTime := time.Unix(int64(containerInfo[i].ModDate), 0)
|
||||
fmt.Printf("%-16s %-6d %-16s %-20s %-20s %-8s\n",
|
||||
ph.Append([]string{
|
||||
containerInfo[i].Name,
|
||||
containerInfo[i].NodeCount,
|
||||
strconv.FormatUint(uint64(containerInfo[i].NodeCount), 10),
|
||||
containerInfo[i].KernelVersion,
|
||||
createTime.Format(time.RFC822),
|
||||
modTime.Format(time.RFC822),
|
||||
util.ByteToString(int64(containerInfo[i].Size)))
|
||||
util.ByteToString(int64(containerInfo[i].Size)),
|
||||
})
|
||||
}
|
||||
ph.Render()
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user