Skip to content

Commit

Permalink
massage hof/dm cmd ux, start building internal dm types and funcs
Browse files Browse the repository at this point in the history
Signed-off-by: Tony Worm <tony@hofstadter.io>
  • Loading branch information
verdverm committed Dec 29, 2021
1 parent 3e5c27a commit 13d22cd
Show file tree
Hide file tree
Showing 25 changed files with 328 additions and 232 deletions.
5 changes: 2 additions & 3 deletions .hof/shadow/Cli/cmd/hof/cmd/datamodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ Hof handles the core data model definitions, history, and snapshot creation.`

func init() {

DatamodelCmd.PersistentFlags().StringSliceVarP(&(flags.DatamodelPflags.Datamodels), "datamodel", "D", nil, "Datamodels for the datamodel commands")
DatamodelCmd.PersistentFlags().StringSliceVarP(&(flags.DatamodelPflags.Modelsets), "modelset", "M", nil, "Modelsets for the datamodel commands")
DatamodelCmd.PersistentFlags().StringSliceVarP(&(flags.DatamodelPflags.Datamodels), "datamodel", "d", nil, "Datamodels for the datamodel commands")
DatamodelCmd.PersistentFlags().StringSliceVarP(&(flags.DatamodelPflags.Models), "model", "m", nil, "Models for the datamodel commands")
}

Expand Down Expand Up @@ -71,7 +70,7 @@ func init() {
DatamodelCmd.SetUsageFunc(usage)

DatamodelCmd.AddCommand(cmddatamodel.ListCmd)
DatamodelCmd.AddCommand(cmddatamodel.StatusCmd)
DatamodelCmd.AddCommand(cmddatamodel.InfoCmd)
DatamodelCmd.AddCommand(cmddatamodel.DiffCmd)
DatamodelCmd.AddCommand(cmddatamodel.HistoryCmd)
DatamodelCmd.AddCommand(cmddatamodel.CheckpointCmd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ import (
"github.com/spf13/cobra"
)

var statusLong = `print the data model status`
var infoLong = `print details for data models`

func StatusRun(args []string) (err error) {
func InfoRun(args []string) (err error) {

// you can safely comment this print out
fmt.Println("not implemented")

return err
}

var StatusCmd = &cobra.Command{
var InfoCmd = &cobra.Command{

Use: "status",
Use: "info",

Aliases: []string{
"s",
},

Short: "print the data model status",
Short: "print details for data models",

Long: statusLong,
Long: infoLong,

PreRun: func(cmd *cobra.Command, args []string) {

Expand All @@ -38,7 +38,7 @@ var StatusCmd = &cobra.Command{

// Argument Parsing

err = StatusRun(args)
err = InfoRun(args)
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand All @@ -52,8 +52,8 @@ func init() {
return false
}

ohelp := StatusCmd.HelpFunc()
ousage := StatusCmd.UsageFunc()
ohelp := InfoCmd.HelpFunc()
ousage := InfoCmd.UsageFunc()
help := func(cmd *cobra.Command, args []string) {
if extra(cmd) {
return
Expand All @@ -67,7 +67,7 @@ func init() {
return ousage(cmd)
}

StatusCmd.SetHelpFunc(help)
StatusCmd.SetUsageFunc(usage)
InfoCmd.SetHelpFunc(help)
InfoCmd.SetUsageFunc(usage)

}
1 change: 0 additions & 1 deletion .hof/shadow/Cli/cmd/hof/flags/datamodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package flags

type DatamodelPflagpole struct {
Datamodels []string
Modelsets []string
Models []string
}

Expand Down
5 changes: 2 additions & 3 deletions cmd/hof/cmd/datamodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ Hof handles the core data model definitions, history, and snapshot creation.`

func init() {

DatamodelCmd.PersistentFlags().StringSliceVarP(&(flags.DatamodelPflags.Datamodels), "datamodel", "D", nil, "Datamodels for the datamodel commands")
DatamodelCmd.PersistentFlags().StringSliceVarP(&(flags.DatamodelPflags.Modelsets), "modelset", "M", nil, "Modelsets for the datamodel commands")
DatamodelCmd.PersistentFlags().StringSliceVarP(&(flags.DatamodelPflags.Datamodels), "datamodel", "d", nil, "Datamodels for the datamodel commands")
DatamodelCmd.PersistentFlags().StringSliceVarP(&(flags.DatamodelPflags.Models), "model", "m", nil, "Models for the datamodel commands")
}

Expand Down Expand Up @@ -71,7 +70,7 @@ func init() {
DatamodelCmd.SetUsageFunc(usage)

DatamodelCmd.AddCommand(cmddatamodel.ListCmd)
DatamodelCmd.AddCommand(cmddatamodel.StatusCmd)
DatamodelCmd.AddCommand(cmddatamodel.InfoCmd)
DatamodelCmd.AddCommand(cmddatamodel.DiffCmd)
DatamodelCmd.AddCommand(cmddatamodel.HistoryCmd)
DatamodelCmd.AddCommand(cmddatamodel.CheckpointCmd)
Expand Down
3 changes: 2 additions & 1 deletion cmd/hof/cmd/datamodel/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/spf13/cobra"

"github.com/hofstadter-io/hof/cmd/hof/flags"
"github.com/hofstadter-io/hof/lib/datamodel"
)

Expand All @@ -16,7 +17,7 @@ func CheckpointRun(args []string) (err error) {
// you can safely comment this print out
// fmt.Println("not implemented")

err = datamodel.RunCheckpointFromArgs(args)
err = datamodel.RunCheckpointFromArgs(args, flags.DatamodelPflags)

return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/hof/cmd/datamodel/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/spf13/cobra"

"github.com/hofstadter-io/hof/cmd/hof/flags"
"github.com/hofstadter-io/hof/lib/datamodel"
)

Expand All @@ -16,7 +17,7 @@ func DiffRun(args []string) (err error) {
// you can safely comment this print out
// fmt.Println("not implemented")

err = datamodel.RunDiffFromArgs(args)
err = datamodel.RunDiffFromArgs(args, flags.DatamodelPflags)

return err
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/hof/cmd/datamodel/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/spf13/cobra"

"github.com/hofstadter-io/hof/cmd/hof/flags"
"github.com/hofstadter-io/hof/lib/datamodel"
)

Expand All @@ -16,7 +17,7 @@ func HistoryRun(args []string) (err error) {
// you can safely comment this print out
// fmt.Println("not implemented")

err = datamodel.RunHistoryFromArgs(args)
err = datamodel.RunHistoryFromArgs(args, flags.DatamodelPflags)

return err
}
Expand Down Expand Up @@ -75,4 +76,4 @@ func init() {
HistoryCmd.SetHelpFunc(help)
HistoryCmd.SetUsageFunc(usage)

}
}
27 changes: 14 additions & 13 deletions cmd/hof/cmd/datamodel/status.go → cmd/hof/cmd/datamodel/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,33 @@ import (

"github.com/spf13/cobra"

"github.com/hofstadter-io/hof/cmd/hof/flags"
"github.com/hofstadter-io/hof/lib/datamodel"
)

var statusLong = `print the data model status`
var infoLong = `print details for data models`

func StatusRun(args []string) (err error) {
func InfoRun(args []string) (err error) {

// you can safely comment this print out
// fmt.Println("not implemented")

err = datamodel.RunStatusFromArgs(args)
err = datamodel.RunInfoFromArgs(args, flags.DatamodelPflags)

return err
}

var StatusCmd = &cobra.Command{
var InfoCmd = &cobra.Command{

Use: "status",
Use: "info",

Aliases: []string{
"s",
},

Short: "print the data model status",
Short: "print details for data models",

Long: statusLong,
Long: infoLong,

PreRun: func(cmd *cobra.Command, args []string) {

Expand All @@ -42,7 +43,7 @@ var StatusCmd = &cobra.Command{

// Argument Parsing

err = StatusRun(args)
err = InfoRun(args)
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand All @@ -56,8 +57,8 @@ func init() {
return false
}

ohelp := StatusCmd.HelpFunc()
ousage := StatusCmd.UsageFunc()
ohelp := InfoCmd.HelpFunc()
ousage := InfoCmd.UsageFunc()
help := func(cmd *cobra.Command, args []string) {
if extra(cmd) {
return
Expand All @@ -71,7 +72,7 @@ func init() {
return ousage(cmd)
}

StatusCmd.SetHelpFunc(help)
StatusCmd.SetUsageFunc(usage)
InfoCmd.SetHelpFunc(help)
InfoCmd.SetUsageFunc(usage)

}
}
1 change: 0 additions & 1 deletion cmd/hof/flags/datamodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package flags

type DatamodelPflagpole struct {
Datamodels []string
Modelsets []string
Models []string
}

Expand Down
48 changes: 18 additions & 30 deletions design/cli/cmds/datamodel.cue
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,21 @@ import (

OmitRun: true

Pflags: [...schema.#Flag] & [
{
Name: "Datamodels"
Long: "datamodel"
Short: "D"
Type: "[]string"
Default: "nil"
Help: "Datamodels for the datamodel commands"
},
{
Name: "modelsets"
Long: "modelset"
Short: "M"
Type: "[]string"
Default: "nil"
Help: "Modelsets for the datamodel commands"
},
{
Name: "models"
Long: "model"
Short: "m"
Type: "[]string"
Default: "nil"

Help: "Models for the datamodel commands"
},
]
Pflags: [...schema.#Flag] & [ {
Name: "Datamodels"
Long: "datamodel"
Short: "d"
Type: "[]string"
Default: "nil"
Help: "Datamodels for the datamodel commands"
}, {
Name: "models"
Long: "model"
Short: "m"
Type: "[]string"
Default: "nil"
Help: "Models for the datamodel commands"
}]

Commands: [{
Name: "list"
Expand All @@ -48,10 +36,10 @@ import (
Short: "find and display data models"
Long: Short
}, {
Name: "status"
Usage: "status"
Name: "info"
Usage: "info"
Aliases: ["s"]
Short: "print the data model status"
Short: "print details for data models"
Long: Short
}, {
Name: "diff"
Expand Down
34 changes: 34 additions & 0 deletions lib/cuetils/find-root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cuetils

import (
"fmt"
"os"
"path/filepath"
)

func FindModuleAbsPath() (string, error) {
dir, err := os.Getwd()
if err != nil {
return "", err
}

found := false

for !found && dir != "/" {
try := filepath.Join(dir, "cue.mod")
info, err := os.Stat(try)
if err == nil && info.IsDir() {
found = true
break
}

next := filepath.Clean(filepath.Join(dir, ".."))
dir = next
}

if !found {
return "", fmt.Errorf("unable to find CUE module root")
}

return dir, nil
}
11 changes: 7 additions & 4 deletions lib/cuetils/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"cuelang.org/go/cue/errors"
)


type KeyVal struct {
Key string
Val cue.Value
Expand All @@ -20,6 +19,7 @@ type KeyVal struct {
//
// GetByAttrAndKeys(val, "myattr", []string{}, []string{})
//
// TODO, change this to return map[string]cue.Value
func GetByAttrKeys(val cue.Value, attr string, all, any []string) ([]KeyVal, error) {
// Todo, rewrite this to use structural

Expand All @@ -37,7 +37,10 @@ func GetByAttrKeys(val cue.Value, attr string, all, any []string) ([]KeyVal, err
}

// Loop through all top level fields
iter := S.Fields()
iter := S.Fields(
cue.Attributes(true),
cue.Definitions(true),
)
for iter.Next() {

label := iter.Label()
Expand All @@ -63,7 +66,7 @@ func GetByAttrKeys(val cue.Value, attr string, all, any []string) ([]KeyVal, err
R := regexp.MustCompile(l)
// loop over the field attt key names
found := false
for v, _ := range vals {
for v, _ := range vals {
m := R.MatchString(v)
if m {
found = true
Expand Down Expand Up @@ -91,7 +94,7 @@ func GetByAttrKeys(val cue.Value, attr string, all, any []string) ([]KeyVal, err
for _, l := range any {
R := regexp.MustCompile(l)
// loop over the field attt key names
for v, _ := range vals {
for v, _ := range vals {
m := R.MatchString(v)
if m {
match = true
Expand Down
Loading

0 comments on commit 13d22cd

Please sign in to comment.