Skip to content

Commit

Permalink
Merge branch 'main' into win10
Browse files Browse the repository at this point in the history
  • Loading branch information
germanosin committed Oct 31, 2024
2 parents 2afdc46 + d82cd3d commit f2fa063
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 478 deletions.
2 changes: 1 addition & 1 deletion cmd/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewEvalCmd(appConfig *app.AppConfig) *cobra.Command {
cmd.Context(),
projectFunc,
pkl.PreconfiguredOptions,
pklutils.WithVals(),
pklutils.WithVals(appConfig.Logger),
func(opts *pkl.EvaluatorOptions) {
opts.CacheDir = appConfig.CacheDir
if appConfig.RootDir != "" {
Expand Down
5 changes: 3 additions & 2 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (

"github.com/apple/pkl-go/pkl"
"hpkl.io/hpkl/pkg/hpkl"

Check failure on line 12 in pkg/app/app.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package hpkl.io/hpkl/pkg/hpkl; to add it:
"hpkl.io/hpkl/pkg/logger"
)

type AppConfig struct {
Logger *Logger
Logger *logger.Logger
project *pkl.Project
ctx context.Context
PlainHttp bool
Expand Down Expand Up @@ -65,7 +66,7 @@ func (a *AppConfig) Reset() {

func NewAppConfig(ctx context.Context, outWriter io.Writer, errWriter io.Writer) (*AppConfig, error) {

logger := NewLogger(outWriter, errWriter)
logger := logger.New(outWriter, errWriter)

return &AppConfig{
Logger: logger,
Expand Down
3 changes: 2 additions & 1 deletion pkg/app/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"hpkl.io/hpkl/pkg/logger"
)

func TestDeduplicate(t *testing.T) {
stdWriter := new(bytes.Buffer)
errWriter := new(bytes.Buffer)

r, err := NewResolver(&AppConfig{
Logger: NewLogger(stdWriter, errWriter),
Logger: logger.New(stdWriter, errWriter),
project: nil,
ctx: context.Background(),
PlainHttp: true,
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/logger.go → pkg/logger/logger.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app
package logger

import (
"fmt"
Expand All @@ -11,7 +11,7 @@ type Logger struct {
err io.Writer
}

func NewLogger(outWriter io.Writer, errWriter io.Writer) *Logger {
func New(outWriter io.Writer, errWriter io.Writer) *Logger {
return &Logger{
out: outWriter,
err: errWriter,
Expand Down
5 changes: 3 additions & 2 deletions pkg/pklutils/vals.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package pklutils

import (
"github.com/apple/pkl-go/pkl"
"hpkl.io/hpkl/pkg/logger"
"hpkl.io/hpkl/pkg/vals"
)

func WithVals() func(options *pkl.EvaluatorOptions) {
valsReader, err := vals.NewValsReader()
func WithVals(logger *logger.Logger) func(options *pkl.EvaluatorOptions) {
valsReader, err := vals.NewValsReader(logger)

if err != nil {
panic(err)
Expand Down
79 changes: 62 additions & 17 deletions pkg/vals/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@ package vals

import (
"net/url"
"strings"

"github.com/apple/pkl-go/pkl"
"github.com/helmfile/vals"
"hpkl.io/hpkl/pkg/logger"
)

func NewValsReader() (*ValsReader, error) {
const key_eparator = "!"

type MapElement struct {
name string
isDirectory bool
}

func (m *MapElement) Name() string {
return m.name
}

func (m *MapElement) IsDirectory() bool {
return m.isDirectory
}

func NewValsReader(logger *logger.Logger) (*ValsReader, error) {
runtime, err := ValsInstance()

if err != nil {
Expand All @@ -16,36 +32,65 @@ func NewValsReader() (*ValsReader, error) {

return &ValsReader{
Runtime: runtime,
Logger: logger,
}, nil
}

type ValsReader struct {
Runtime *vals.Runtime
Runtime *KeysRuntime
Logger *logger.Logger
}

func (r *ValsReader) Read(url url.URL) ([]byte, error) {
func (r *ValsReader) IsGlobbable() bool {
return true
}

func (r *ValsReader) HasHierarchicalUris() bool {
return false
}

func (r *ValsReader) ListElements(url url.URL) ([]pkl.PathElement, error) {
url.Scheme = ""
code, err := r.Runtime.Get(url.String())
basePart := strings.TrimSuffix(url.String(), "/**")
key := strings.Replace(basePart, key_eparator, "#", 1)

res, err := r.Runtime.GetMap(key)

if err != nil {
return []byte{}, err
return nil, err
}

return []byte(code), nil
}
result := make([]pkl.PathElement, len(res))

func (r *ValsReader) Scheme() string {
return "vals"
}
i := 0
for k, v := range res {
path := basePart + "/" + k
switch v.(type) {
case string:
result[i] = &MapElement{path, false}
default:
result[i] = &MapElement{path, true}
}
i++
}

func (r *ValsReader) IsGlobbable() bool {
return false
return result, nil
}

func (r *ValsReader) HasHierarchicalUris() bool {
return false
func (r *ValsReader) Read(url url.URL) ([]byte, error) {

url.Scheme = ""
key := strings.Replace(url.String(), key_eparator, "#", 1)

res, err := r.Runtime.GetString(key)

if err != nil {
return nil, err
} else {
return []byte(res), nil
}
}

func (r *ValsReader) ListElements(url url.URL) ([]pkl.PathElement, error) {
return make([]pkl.PathElement, 0), nil
func (r *ValsReader) Scheme() string {
return "vals"
}
Loading

0 comments on commit f2fa063

Please sign in to comment.