From 9b8a219625fcbaa62d76811ee932f71b23157565 Mon Sep 17 00:00:00 2001
From: Tony Worm <tony@topcialsource.com>
Date: Sat, 18 May 2024 13:34:33 -0400
Subject: [PATCH] cli/list: move dm list to shared implementation

---
 lib/datamodel/cmd/list.go  |  3 ++-
 lib/datamodel/cmd/table.go | 42 --------------------------------------
 lib/datamodel/cmd/utils.go |  4 +---
 lib/gen/cmd/list.go        | 16 ---------------
 4 files changed, 3 insertions(+), 62 deletions(-)
 delete mode 100644 lib/datamodel/cmd/table.go

diff --git a/lib/datamodel/cmd/list.go b/lib/datamodel/cmd/list.go
index 041bf7386..fb25d25a7 100644
--- a/lib/datamodel/cmd/list.go
+++ b/lib/datamodel/cmd/list.go
@@ -9,10 +9,11 @@ import (
 	"github.com/hofstadter-io/hof/cmd/hof/flags"
 	"github.com/hofstadter-io/hof/lib/datamodel"
 	"github.com/hofstadter-io/hof/lib/runtime"
+	"github.com/hofstadter-io/hof/lib/yagu"
 )
 
 func list(R *runtime.Runtime, dflags flags.DatamodelPflagpole) error {
-	return printAsTable(
+	return yagu.PrintAsTable(
 		[]string{"Name", "Type", "Version", "Status", "ID"},
 		func(table *tablewriter.Table) ([][]string, error) {
 			var rows = make([][]string, 0, len(R.Datamodels))
diff --git a/lib/datamodel/cmd/table.go b/lib/datamodel/cmd/table.go
deleted file mode 100644
index e4bf29f34..000000000
--- a/lib/datamodel/cmd/table.go
+++ /dev/null
@@ -1,42 +0,0 @@
-package cmd
-
-import (
-	"os"
-
-	"github.com/olekukonko/tablewriter"
-)
-
-func defaultTableFormat(table *tablewriter.Table) {
-	table.SetAutoWrapText(false)
-	table.SetAutoFormatHeaders(true)
-	table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
-	table.SetAlignment(tablewriter.ALIGN_LEFT)
-	table.SetCenterSeparator("")
-	table.SetColumnSeparator("")
-	table.SetRowSeparator("")
-	table.SetHeaderLine(false)
-	table.SetBorder(false)
-	table.SetTablePadding("  ")
-	table.SetNoWhiteSpace(true)
-}
-
-type dataPrinter func(table *tablewriter.Table) ([][]string, error)
-
-func printAsTable(headers []string, printer dataPrinter) error {
-	table := tablewriter.NewWriter(os.Stdout)
-	table.SetHeader(headers)
-
-	defaultTableFormat(table)
-
-	rows, err := printer(table)
-	if err != nil {
-		return err
-	}
-
-	table.AppendBulk(rows)
-
-	// render
-	table.Render()
-
-	return nil
-}
diff --git a/lib/datamodel/cmd/utils.go b/lib/datamodel/cmd/utils.go
index 9bcb3dacb..bf77f8dda 100644
--- a/lib/datamodel/cmd/utils.go
+++ b/lib/datamodel/cmd/utils.go
@@ -14,6 +14,4 @@ func findMaxLabelLen(R *runtime.Runtime, dflags flags.DatamodelPflagpole) int {
 		}
 	}
 	return max
-}
-
-
+}
\ No newline at end of file
diff --git a/lib/gen/cmd/list.go b/lib/gen/cmd/list.go
index 8c7a73153..b8f1ee55b 100644
--- a/lib/gen/cmd/list.go
+++ b/lib/gen/cmd/list.go
@@ -39,20 +39,4 @@ func List(args []string, rflags flags.RootPflagpole, gflags flags.GenFlagpole) e
 			return rows, nil
 		},
 	)
-
-	// // TODO...
-	// // 1. use table printer
-	// // 2. move this command up, large blocks of this ought
-	// gens := make([]string, 0, len(R.Generators))
-	// for _, G := range R.Generators {
-	// 	gens = append(gens, G.Hof.Metadata.Name)
-	// }
-	// if len(gens) == 0 {
-	// 	return fmt.Errorf("no generators found")
-	// }
-	// fmt.Printf("Available Generators\n  ")
-	// fmt.Println(strings.Join(gens, "\n  "))
-	
-	// // print gens
-	// return nil
 }