Skip to content

Commit

Permalink
new cue runtime operational, ready to rock and roll
Browse files Browse the repository at this point in the history
  • Loading branch information
verdverm committed May 17, 2020
1 parent 401efea commit cbc96d6
Show file tree
Hide file tree
Showing 29 changed files with 595 additions and 118 deletions.
1 change: 1 addition & 0 deletions .hof/Cli/cmd/hof/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func init() {
RootCmd.PersistentFlags().StringVarP(&pflags.RootAccountPflag, "account", "A", "", "the account context to use during this hof execution")
RootCmd.PersistentFlags().StringVarP(&pflags.RootBillingPflag, "billing", "B", "", "the billing context to use during this hof execution")
RootCmd.PersistentFlags().StringVarP(&pflags.RootProjectPflag, "project", "P", "", "the project context to use during this hof execution")
RootCmd.PersistentFlags().StringVarP(&pflags.RootWorkspacePflag, "workspace", "W", "", "the workspace context to use during this hof execution")
RootCmd.PersistentFlags().StringVarP(&pflags.RootPackagePflag, "package", "p", "", "the package context to use during this hof execution")
RootCmd.PersistentFlags().StringSliceVarP(&pflags.RootLabelsPflag, "label", "L", nil, "Labels for use across all commands")
RootCmd.PersistentFlags().BoolVarP(&pflags.RootErrorsPflag, "all-errors", "E", false, "print all available errors")
Expand Down
1 change: 1 addition & 0 deletions .hof/Cli/cmd/hof/pflags/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var (
RootAccountPflag string
RootBillingPflag string
RootProjectPflag string
RootWorkspacePflag string
RootPackagePflag string
RootLabelsPflag []string
RootErrorsPflag bool
Expand Down
24 changes: 15 additions & 9 deletions .hof/Config/lib/cuefig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
const (
ConfigEntrypoint = ".hofcfg.cue"
ConfigWorkpath = ""
ConfigLocation = "local"
)

func LoadConfigDefault(cfg interface{}) (cue.Value, error) {
Expand All @@ -28,17 +27,24 @@ func LoadConfigDefault(cfg interface{}) (cue.Value, error) {

func LoadConfigConfig(workpath, entrypoint string, cfg interface{}) (val cue.Value, err error) {

// TODO Fallback order: local / user / global
fpath := filepath.Join(workpath, entrypoint)
_, err = os.Lstat(workpath)
if err != nil {
if _, ok := err.(*os.PathError); !ok && (strings.Contains(err.Error(), "file does not exist") || strings.Contains(err.Error(), "no such file")) {
// error is worse than non-existant

// possibly, check for workpath
if workpath != "" {
_, err = os.Lstat(workpath)
if err != nil {
if _, ok := err.(*os.PathError); !ok && (strings.Contains(err.Error(), "file does not exist") || strings.Contains(err.Error(), "no such file")) {
// error is worse than non-existant
return val, err
}
// otherwise, does not exist, so we should init?
// XXX want to let applications decide how to handle this
return val, err
}
// otherwise, does not exist, so we should init?
// XXX want to let applications decide how to handle this
return val, err
}

// check for entrypoint
_, err = os.Lstat(fpath)
if err != nil {
if _, ok := err.(*os.PathError); !ok && (strings.Contains(err.Error(), "file does not exist") || strings.Contains(err.Error(), "no such file")) {
Expand Down Expand Up @@ -93,7 +99,7 @@ func LoadConfigConfig(workpath, entrypoint string, cfg interface{}) (val cue.Val
for _, e := range errs {
util.PrintCueError(e)
}
return val, fmt.Errorf("Errors while reading DMA config file")
return val, fmt.Errorf("Errors while reading Config file: %q", fpath)
}

return val, nil
Expand Down
24 changes: 15 additions & 9 deletions .hof/Creds/lib/cuefig/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
const (
SecretEntrypoint = ".hofshh.cue"
SecretWorkpath = ""
SecretLocation = "local"
)

func LoadSecretDefault(cfg interface{}) (cue.Value, error) {
Expand All @@ -28,17 +27,24 @@ func LoadSecretDefault(cfg interface{}) (cue.Value, error) {

func LoadSecretConfig(workpath, entrypoint string, cfg interface{}) (val cue.Value, err error) {

// TODO Fallback order: local / user / global
fpath := filepath.Join(workpath, entrypoint)
_, err = os.Lstat(workpath)
if err != nil {
if _, ok := err.(*os.PathError); !ok && (strings.Contains(err.Error(), "file does not exist") || strings.Contains(err.Error(), "no such file")) {
// error is worse than non-existant

// possibly, check for workpath
if workpath != "" {
_, err = os.Lstat(workpath)
if err != nil {
if _, ok := err.(*os.PathError); !ok && (strings.Contains(err.Error(), "file does not exist") || strings.Contains(err.Error(), "no such file")) {
// error is worse than non-existant
return val, err
}
// otherwise, does not exist, so we should init?
// XXX want to let applications decide how to handle this
return val, err
}
// otherwise, does not exist, so we should init?
// XXX want to let applications decide how to handle this
return val, err
}

// check for entrypoint
_, err = os.Lstat(fpath)
if err != nil {
if _, ok := err.(*os.PathError); !ok && (strings.Contains(err.Error(), "file does not exist") || strings.Contains(err.Error(), "no such file")) {
Expand Down Expand Up @@ -93,7 +99,7 @@ func LoadSecretConfig(workpath, entrypoint string, cfg interface{}) (val cue.Val
for _, e := range errs {
util.PrintCueError(e)
}
return val, fmt.Errorf("Errors while reading DMA config file")
return val, fmt.Errorf("Errors while reading Secret file: %q", fpath)
}

return val, nil
Expand Down
4 changes: 4 additions & 0 deletions cmd/hof/cmd/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ import (
"github.com/spf13/cobra"

"github.com/hofstadter-io/hof/cmd/hof/ga"

"github.com/hofstadter-io/hof/lib/hack"
)

var hackLong = `development command`

func HackRun(args []string) (err error) {

err = hack.Hack(args)

return err
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/hof/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func init() {
RootCmd.PersistentFlags().StringVarP(&pflags.RootAccountPflag, "account", "A", "", "the account context to use during this hof execution")
RootCmd.PersistentFlags().StringVarP(&pflags.RootBillingPflag, "billing", "B", "", "the billing context to use during this hof execution")
RootCmd.PersistentFlags().StringVarP(&pflags.RootProjectPflag, "project", "P", "", "the project context to use during this hof execution")
RootCmd.PersistentFlags().StringVarP(&pflags.RootWorkspacePflag, "workspace", "W", "", "the workspace context to use during this hof execution")
RootCmd.PersistentFlags().StringVarP(&pflags.RootPackagePflag, "package", "p", "", "the package context to use during this hof execution")
RootCmd.PersistentFlags().StringSliceVarP(&pflags.RootLabelsPflag, "label", "L", nil, "Labels for use across all commands")
RootCmd.PersistentFlags().BoolVarP(&pflags.RootErrorsPflag, "all-errors", "E", false, "print all available errors")
Expand Down Expand Up @@ -235,7 +236,7 @@ Colloaborate (see also 'hof topic collaborate'):
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
propose Propose to include your changeset in a remote repository
Local development commands:
ui Run hof's local web ui
tui Run hof's terminal ui
Expand All @@ -258,4 +259,4 @@ Flags:
<<flag-usage>>
Use "hof [command] --help" for more information about a command.
Use "hof topic [subject]" for more information about a subject.
`
`
1 change: 1 addition & 0 deletions cmd/hof/pflags/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var (
RootAccountPflag string
RootBillingPflag string
RootProjectPflag string
RootWorkspacePflag string
RootPackagePflag string
RootLabelsPflag []string
RootErrorsPflag bool
Expand Down
8 changes: 8 additions & 0 deletions design/cli/pflags.cue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ import (
Help: "the project context to use during this hof execution"
},
// these are more cue specific with a dash of hof
{
Name: "workspace"
Long: "workspace"
Short: "W"
Type: "string"
Default: ""
Help: "the workspace context to use during this hof execution"
},
{
Name: "package"
Long: "package"
Expand Down
17 changes: 8 additions & 9 deletions design/config/main.cue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import (
hof "github.com/hofstadter-io/hof/schema"

"github.com/hofstadter-io/hofmod-cuefig/schema"
)

Expand All @@ -9,13 +11,8 @@ import (
Entrypoint: ".hofcfg.cue"

ConfigSchema: {
models: {
name: "string"
}
stores: {
name: "string"
type: "string"
}
Modelset: hof.#Modelsets
Datastores: hof.#Datastores
}
}

Expand All @@ -24,8 +21,10 @@ import (
Entrypoint: ".hofshh.cue"

ConfigSchema: {
[Cred=string]: {
[Key=string]: string
[Group=string]: {
[Cred=string]: {
[Key=string]: string
}
}
}
}
112 changes: 112 additions & 0 deletions gen/cuefig/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package cuefig

// Name: config

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

"cuelang.org/go/cue"
// "cuelang.org/go/cue/build"
"cuelang.org/go/cue/errors"
"cuelang.org/go/cue/load"

"github.com/hofstadter-io/hof/lib/util"
)

const (
ConfigEntrypoint = ".hofcfg.cue"
ConfigWorkpath = ""
ConfigLocation = "local"
)

func LoadConfigDefault(cfg interface{}) (cue.Value, error) {
return LoadConfigConfig(ConfigWorkpath, ConfigEntrypoint, cfg)
}

func LoadConfigConfig(workpath, entrypoint string, cfg interface{}) (val cue.Value, err error) {
fmt.Println("Cuefig[Config].Load:", workpath, entrypoint)

// Fallback order: local / user / global
fpath := filepath.Join(workpath, entrypoint)

// possibly, check for workpath
if workpath != "" {
_, err = os.Lstat(workpath)
if err != nil {
if _, ok := err.(*os.PathError); !ok && (strings.Contains(err.Error(), "file does not exist") || strings.Contains(err.Error(), "no such file")) {
// error is worse than non-existant
return val, err
}
// otherwise, does not exist, so we should init?
// XXX want to let applications decide how to handle this
fmt.Println("missing:", workpath)
return val, err
}
}

// check for entrypoint
_, err = os.Lstat(fpath)
if err != nil {
if _, ok := err.(*os.PathError); !ok && (strings.Contains(err.Error(), "file does not exist") || strings.Contains(err.Error(), "no such file")) {
// error is worse than non-existant
return val, err
}
// otherwise, does not exist, so we should init?
// XXX want to let applications decide how to handle this
fmt.Println("missing:", fpath)
return val, err
}

fmt.Println(" - found cue file:", fpath)

var errs []error

CueRT := &cue.Runtime{}
BIS := load.Instances([]string{fpath}, nil)
for _, bi := range BIS {

if bi.Err != nil {
// fmt.Println("BI ERR", bi.Err, bi.Incomplete, bi.DepsErrors)
es := errors.Errors(bi.Err)
for _, e := range es {
errs = append(errs, e.(error))
}
continue
}

// Build the Instance
I, err := CueRT.Build(bi)
if err != nil {
es := errors.Errors(err)
// fmt.Println("BUILD ERR", es, I)
for _, e := range es {
errs = append(errs, e.(error))
}
continue
}

// Get top level value from cuelang
V := I.Value()

err = V.Decode(&cfg)
if err != nil {
errs = append(errs, err)
continue
}

val = V

}

if len(errs) > 0 {
for _, e := range errs {
util.PrintCueError(e)
}
return val, fmt.Errorf("Errors while reading Config file: %q", fpath)
}

return val, nil
}
Loading

0 comments on commit cbc96d6

Please sign in to comment.