From 3e5c27abce3e3c464c25369c35896b81364ccb35 Mon Sep 17 00:00:00 2001 From: Tony Worm Date: Tue, 28 Dec 2021 15:39:42 -0500 Subject: [PATCH] rework hof/dm cmds a bit Signed-off-by: Tony Worm --- .hof/shadow/Cli/cmd/hof/cmd/datamodel.go | 3 +- .../shadow/Cli/cmd/hof/cmd/datamodel/apply.go | 73 ------------------ .../Cli/cmd/hof/cmd/datamodel/history.go | 2 - .../cmd/hof/cmd/datamodel/{get.go => list.go} | 22 +++--- .../Cli/cmd/hof/cmd/datamodel/status.go | 2 +- cmd/hof/cmd/datamodel.go | 3 +- cmd/hof/cmd/datamodel/apply.go | 77 ------------------- cmd/hof/cmd/datamodel/history.go | 4 +- cmd/hof/cmd/datamodel/{get.go => list.go} | 25 +++--- cmd/hof/cmd/datamodel/status.go | 4 +- design/cli/cmds/datamodel.cue | 23 ++---- lib/datamodel/{get.go => list.go} | 10 +-- 12 files changed, 38 insertions(+), 210 deletions(-) delete mode 100644 .hof/shadow/Cli/cmd/hof/cmd/datamodel/apply.go rename .hof/shadow/Cli/cmd/hof/cmd/datamodel/{get.go => list.go} (71%) delete mode 100644 cmd/hof/cmd/datamodel/apply.go rename cmd/hof/cmd/datamodel/{get.go => list.go} (69%) rename lib/datamodel/{get.go => list.go} (89%) diff --git a/.hof/shadow/Cli/cmd/hof/cmd/datamodel.go b/.hof/shadow/Cli/cmd/hof/cmd/datamodel.go index b5bf4416e..cb6674a05 100644 --- a/.hof/shadow/Cli/cmd/hof/cmd/datamodel.go +++ b/.hof/shadow/Cli/cmd/hof/cmd/datamodel.go @@ -70,11 +70,10 @@ func init() { DatamodelCmd.SetHelpFunc(help) DatamodelCmd.SetUsageFunc(usage) - DatamodelCmd.AddCommand(cmddatamodel.GetCmd) + DatamodelCmd.AddCommand(cmddatamodel.ListCmd) DatamodelCmd.AddCommand(cmddatamodel.StatusCmd) DatamodelCmd.AddCommand(cmddatamodel.DiffCmd) DatamodelCmd.AddCommand(cmddatamodel.HistoryCmd) DatamodelCmd.AddCommand(cmddatamodel.CheckpointCmd) - DatamodelCmd.AddCommand(cmddatamodel.ApplyCmd) } diff --git a/.hof/shadow/Cli/cmd/hof/cmd/datamodel/apply.go b/.hof/shadow/Cli/cmd/hof/cmd/datamodel/apply.go deleted file mode 100644 index 9a05ce809..000000000 --- a/.hof/shadow/Cli/cmd/hof/cmd/datamodel/apply.go +++ /dev/null @@ -1,73 +0,0 @@ -package cmddatamodel - -import ( - "fmt" - "os" - - "github.com/spf13/cobra" -) - -var applyLong = `apply a migraion sequence against a data store` - -func ApplyRun(args []string) (err error) { - - // you can safely comment this print out - fmt.Println("not implemented") - - return err -} - -var ApplyCmd = &cobra.Command{ - - Use: "apply", - - Aliases: []string{ - "a", - }, - - Short: "apply a migraion sequence against a data store", - - Long: applyLong, - - PreRun: func(cmd *cobra.Command, args []string) { - - }, - - Run: func(cmd *cobra.Command, args []string) { - var err error - - // Argument Parsing - - err = ApplyRun(args) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - }, -} - -func init() { - extra := func(cmd *cobra.Command) bool { - - return false - } - - ohelp := ApplyCmd.HelpFunc() - ousage := ApplyCmd.UsageFunc() - help := func(cmd *cobra.Command, args []string) { - if extra(cmd) { - return - } - ohelp(cmd, args) - } - usage := func(cmd *cobra.Command) error { - if extra(cmd) { - return nil - } - return ousage(cmd) - } - - ApplyCmd.SetHelpFunc(help) - ApplyCmd.SetUsageFunc(usage) - -} diff --git a/.hof/shadow/Cli/cmd/hof/cmd/datamodel/history.go b/.hof/shadow/Cli/cmd/hof/cmd/datamodel/history.go index f879fb42c..8bd11bfe8 100644 --- a/.hof/shadow/Cli/cmd/hof/cmd/datamodel/history.go +++ b/.hof/shadow/Cli/cmd/hof/cmd/datamodel/history.go @@ -24,8 +24,6 @@ var HistoryCmd = &cobra.Command{ Aliases: []string{ "hist", "h", - "log", - "l", }, Short: "show the history for a data model", diff --git a/.hof/shadow/Cli/cmd/hof/cmd/datamodel/get.go b/.hof/shadow/Cli/cmd/hof/cmd/datamodel/list.go similarity index 71% rename from .hof/shadow/Cli/cmd/hof/cmd/datamodel/get.go rename to .hof/shadow/Cli/cmd/hof/cmd/datamodel/list.go index dfa2c3357..2ee04effb 100644 --- a/.hof/shadow/Cli/cmd/hof/cmd/datamodel/get.go +++ b/.hof/shadow/Cli/cmd/hof/cmd/datamodel/list.go @@ -7,9 +7,9 @@ import ( "github.com/spf13/cobra" ) -var getLong = `find and display data models` +var listLong = `find and display data models` -func GetRun(args []string) (err error) { +func ListRun(args []string) (err error) { // you can safely comment this print out fmt.Println("not implemented") @@ -17,17 +17,17 @@ func GetRun(args []string) (err error) { return err } -var GetCmd = &cobra.Command{ +var ListCmd = &cobra.Command{ - Use: "get", + Use: "list", Aliases: []string{ - "g", + "l", }, Short: "find and display data models", - Long: getLong, + Long: listLong, PreRun: func(cmd *cobra.Command, args []string) { @@ -38,7 +38,7 @@ var GetCmd = &cobra.Command{ // Argument Parsing - err = GetRun(args) + err = ListRun(args) if err != nil { fmt.Println(err) os.Exit(1) @@ -52,8 +52,8 @@ func init() { return false } - ohelp := GetCmd.HelpFunc() - ousage := GetCmd.UsageFunc() + ohelp := ListCmd.HelpFunc() + ousage := ListCmd.UsageFunc() help := func(cmd *cobra.Command, args []string) { if extra(cmd) { return @@ -67,7 +67,7 @@ func init() { return ousage(cmd) } - GetCmd.SetHelpFunc(help) - GetCmd.SetUsageFunc(usage) + ListCmd.SetHelpFunc(help) + ListCmd.SetUsageFunc(usage) } diff --git a/.hof/shadow/Cli/cmd/hof/cmd/datamodel/status.go b/.hof/shadow/Cli/cmd/hof/cmd/datamodel/status.go index 4c56cb469..5d07fcebf 100644 --- a/.hof/shadow/Cli/cmd/hof/cmd/datamodel/status.go +++ b/.hof/shadow/Cli/cmd/hof/cmd/datamodel/status.go @@ -22,7 +22,7 @@ var StatusCmd = &cobra.Command{ Use: "status", Aliases: []string{ - "st", + "s", }, Short: "print the data model status", diff --git a/cmd/hof/cmd/datamodel.go b/cmd/hof/cmd/datamodel.go index b5bf4416e..cb6674a05 100644 --- a/cmd/hof/cmd/datamodel.go +++ b/cmd/hof/cmd/datamodel.go @@ -70,11 +70,10 @@ func init() { DatamodelCmd.SetHelpFunc(help) DatamodelCmd.SetUsageFunc(usage) - DatamodelCmd.AddCommand(cmddatamodel.GetCmd) + DatamodelCmd.AddCommand(cmddatamodel.ListCmd) DatamodelCmd.AddCommand(cmddatamodel.StatusCmd) DatamodelCmd.AddCommand(cmddatamodel.DiffCmd) DatamodelCmd.AddCommand(cmddatamodel.HistoryCmd) DatamodelCmd.AddCommand(cmddatamodel.CheckpointCmd) - DatamodelCmd.AddCommand(cmddatamodel.ApplyCmd) } diff --git a/cmd/hof/cmd/datamodel/apply.go b/cmd/hof/cmd/datamodel/apply.go deleted file mode 100644 index 8828859df..000000000 --- a/cmd/hof/cmd/datamodel/apply.go +++ /dev/null @@ -1,77 +0,0 @@ -package cmddatamodel - -import ( - "fmt" - "os" - - "github.com/spf13/cobra" - - "github.com/hofstadter-io/hof/lib/datamodel" -) - -var applyLong = `apply a migraion sequence against a data store` - -func ApplyRun(args []string) (err error) { - - // you can safely comment this print out - // fmt.Println("not implemented") - - err = datamodel.RunApplyFromArgs(args) - - return err -} - -var ApplyCmd = &cobra.Command{ - - Use: "apply", - - Aliases: []string{ - "a", - }, - - Short: "apply a migraion sequence against a data store", - - Long: applyLong, - - PreRun: func(cmd *cobra.Command, args []string) { - - }, - - Run: func(cmd *cobra.Command, args []string) { - var err error - - // Argument Parsing - - err = ApplyRun(args) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - }, -} - -func init() { - extra := func(cmd *cobra.Command) bool { - - return false - } - - ohelp := ApplyCmd.HelpFunc() - ousage := ApplyCmd.UsageFunc() - help := func(cmd *cobra.Command, args []string) { - if extra(cmd) { - return - } - ohelp(cmd, args) - } - usage := func(cmd *cobra.Command) error { - if extra(cmd) { - return nil - } - return ousage(cmd) - } - - ApplyCmd.SetHelpFunc(help) - ApplyCmd.SetUsageFunc(usage) - -} diff --git a/cmd/hof/cmd/datamodel/history.go b/cmd/hof/cmd/datamodel/history.go index 94773333d..f18e1ccce 100644 --- a/cmd/hof/cmd/datamodel/history.go +++ b/cmd/hof/cmd/datamodel/history.go @@ -28,8 +28,6 @@ var HistoryCmd = &cobra.Command{ Aliases: []string{ "hist", "h", - "log", - "l", }, Short: "show the history for a data model", @@ -77,4 +75,4 @@ func init() { HistoryCmd.SetHelpFunc(help) HistoryCmd.SetUsageFunc(usage) -} +} \ No newline at end of file diff --git a/cmd/hof/cmd/datamodel/get.go b/cmd/hof/cmd/datamodel/list.go similarity index 69% rename from cmd/hof/cmd/datamodel/get.go rename to cmd/hof/cmd/datamodel/list.go index 5aff9823b..e4944b100 100644 --- a/cmd/hof/cmd/datamodel/get.go +++ b/cmd/hof/cmd/datamodel/list.go @@ -7,33 +7,32 @@ import ( "github.com/spf13/cobra" "github.com/hofstadter-io/hof/cmd/hof/flags" - "github.com/hofstadter-io/hof/lib/datamodel" ) -var getLong = `find and display data models` +var listLong = `find and display data models` -func GetRun(args []string) (err error) { +func ListRun(args []string) (err error) { // you can safely comment this print out // fmt.Println("not implemented") - err = datamodel.RunGetFromArgs(args, flags.DatamodelPflags) + err = datamodel.RunListFromArgs(args, flags.DatamodelPflags) return err } -var GetCmd = &cobra.Command{ +var ListCmd = &cobra.Command{ - Use: "get", + Use: "list", Aliases: []string{ - "g", + "l", }, Short: "find and display data models", - Long: getLong, + Long: listLong, PreRun: func(cmd *cobra.Command, args []string) { @@ -44,7 +43,7 @@ var GetCmd = &cobra.Command{ // Argument Parsing - err = GetRun(args) + err = ListRun(args) if err != nil { fmt.Println(err) os.Exit(1) @@ -58,8 +57,8 @@ func init() { return false } - ohelp := GetCmd.HelpFunc() - ousage := GetCmd.UsageFunc() + ohelp := ListCmd.HelpFunc() + ousage := ListCmd.UsageFunc() help := func(cmd *cobra.Command, args []string) { if extra(cmd) { return @@ -73,7 +72,7 @@ func init() { return ousage(cmd) } - GetCmd.SetHelpFunc(help) - GetCmd.SetUsageFunc(usage) + ListCmd.SetHelpFunc(help) + ListCmd.SetUsageFunc(usage) } diff --git a/cmd/hof/cmd/datamodel/status.go b/cmd/hof/cmd/datamodel/status.go index 7c9a2493a..4f86e22a3 100644 --- a/cmd/hof/cmd/datamodel/status.go +++ b/cmd/hof/cmd/datamodel/status.go @@ -26,7 +26,7 @@ var StatusCmd = &cobra.Command{ Use: "status", Aliases: []string{ - "st", + "s", }, Short: "print the data model status", @@ -74,4 +74,4 @@ func init() { StatusCmd.SetHelpFunc(help) StatusCmd.SetUsageFunc(usage) -} +} \ No newline at end of file diff --git a/design/cli/cmds/datamodel.cue b/design/cli/cmds/datamodel.cue index 833a6d2e0..d6378821f 100644 --- a/design/cli/cmds/datamodel.cue +++ b/design/cli/cmds/datamodel.cue @@ -5,7 +5,6 @@ import ( ) #DatamodelCommand: schema.#Command & { - TBD: "α" Name: "datamodel" Usage: "datamodel" Aliases: ["dmod", "dm"] @@ -43,47 +42,35 @@ import ( ] Commands: [{ - TBD: "α" - Name: "get" - Usage: "get" - Aliases: ["g"] + Name: "list" + Usage: "list" + Aliases: ["l"] Short: "find and display data models" Long: Short }, { - TBD: "α" Name: "status" Usage: "status" - Aliases: ["st"] + Aliases: ["s"] Short: "print the data model status" Long: Short }, { - TBD: "α" Name: "diff" Usage: "diff" Aliases: ["d"] Short: "show the current diff for a data model" Long: Short }, { - TBD: "α" Name: "history" Usage: "history" - Aliases: ["hist", "h", "log", "l"] + Aliases: ["hist", "h"] Short: "show the history for a data model" Long: Short }, { - TBD: "α" Name: "checkpoint" Usage: "checkpoint" Aliases: ["cp"] Short: "calculate a migration changeset for a data model" Long: Short - }, { - TBD: "α" - Name: "apply" - Usage: "apply" - Aliases: ["a"] - Short: "apply a migraion sequence against a data store" - Long: Short }] } diff --git a/lib/datamodel/get.go b/lib/datamodel/list.go similarity index 89% rename from lib/datamodel/get.go rename to lib/datamodel/list.go index 61e062f8c..c4d1b8548 100644 --- a/lib/datamodel/get.go +++ b/lib/datamodel/list.go @@ -11,7 +11,7 @@ import ( // "github.com/hofstadter-io/hof/lib/cuetils" ) -func RunGetFromArgs(args []string, cmdpflags flags.DatamodelPflagpole) error { +func RunListFromArgs(args []string, cmdpflags flags.DatamodelPflagpole) error { // fmt.Println("lib/datamodel.Get", args, cmdpflags) // Loadup our Cue files @@ -29,7 +29,7 @@ func RunGetFromArgs(args []string, cmdpflags flags.DatamodelPflagpole) error { //syn, err := cuetils.PrintCueValue(val) //if err != nil { - //return err + //return err //} //fmt.Println(syn) @@ -58,7 +58,6 @@ func printTable(val cue.Value) error { } } - table.Render() return nil @@ -69,7 +68,7 @@ func printModel(model cue.Value, table *tablewriter.Table) error { // Model name name, _ := model.LookupPath(cue.ParsePath("Name")).String() - table.Append([]string{ name, "", "", "" }) + table.Append([]string{name, "", "", ""}) // Model fields fields := model.LookupPath(cue.ParsePath("Fields")) @@ -82,9 +81,8 @@ func printModel(model cue.Value, table *tablewriter.Table) error { fn, _ := f.LookupPath(cue.ParsePath("Name")).String() ft, _ := f.LookupPath(cue.ParsePath("type")).String() - table.Append([]string{ "", fn, ft, "" }) + table.Append([]string{"", fn, ft, ""}) } return nil } -