Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: strict setting files config running #314

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,6 @@ x = {
// person: {Name:kcl Age:101}
}

func ExampleRun_getField() {
// run kcl.yaml
x, err := kcl.Run("./testdata/app0/kcl.yaml")
assert(err == nil, err)

// print deploy_topology[1].zone
fmt.Println(x.First().Get("deploy_topology.1.zone"))

// Output:
// R000A
}

func Example() {
const k_code = `
name = "kcl"
Expand Down
31 changes: 0 additions & 31 deletions kclvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"sort"
"strconv"
"strings"
"sync"
"testing"

assert2 "github.com/stretchr/testify/assert"
Expand All @@ -37,36 +36,6 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}

func TestRunFiles(t *testing.T) {
_, err := kcl.RunFiles([]string{"./testdata/app0/kcl.yaml"})
if err != nil {
t.Fatal(err)
}
_, err = kcl.RunFiles([]string{"./testdata/app0/kcl.yaml"})
if err != nil {
t.Fatal(err)
}

chErr := make(chan error, 3)

var wg sync.WaitGroup
for i := 0; i < cap(chErr); i++ {
wg.Add(1)
go func() {
defer wg.Done()
_, e := kcl.RunFiles([]string{"./testdata/app0/kcl.yaml"})
chErr <- e
}()
}
wg.Wait()

for i := 0; i < cap(chErr); i++ {
if e := <-chErr; e != nil {
t.Fatal(e)
}
}
}

func TestStreamResult(t *testing.T) {
file, err := filepath.Abs("./testdata/stream/one_stream.k")
if err != nil {
Expand Down
6 changes: 0 additions & 6 deletions pkg/kcl/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ func TestKCLResultInt(t *testing.T) {
tAssert(t, *m == 1)
}

func TestRun_kcl_yaml(t *testing.T) {
const s = "../../testdata/app0/kcl.yaml"
_, err := RunFiles([]string{s})
tAssert(t, err == nil, err)
}

func TestRun(t *testing.T) {
const k_code = `
name = "kcl"
Expand Down
11 changes: 1 addition & 10 deletions pkg/kcl/opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,7 @@ func (p *Option) GetLogger() io.Writer {
func ParseArgs(pathList []string, opts ...Option) (Option, error) {
var tmpOptList []Option
for _, s := range pathList {
switch {
case strings.HasSuffix(s, ".k"):
tmpOptList = append(tmpOptList, WithKFilenames(s))
case strings.HasSuffix(s, ".yaml") || strings.HasSuffix(s, ".yml"):
tmpOptList = append(tmpOptList, WithSettings(s))
case isDir(s):
tmpOptList = append(tmpOptList, WithWorkDir(s))
default:
tmpOptList = append(tmpOptList, WithKFilenames(s))
}
tmpOptList = append(tmpOptList, WithKFilenames(s))
}

args := NewOption().Merge(opts...).Merge(tmpOptList...)
Expand Down
3 changes: 1 addition & 2 deletions pkg/settings/utils_settings_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ func LoadFile(filename string, src interface{}) (f *SettingsFile, err error) {

func (settings *SettingsFile) To_ExecProgram_Args() *gpyrpc.ExecProgram_Args {
args := &gpyrpc.ExecProgram_Args{
WorkDir: filepath.Dir(settings.Filename),

KFilenameList: []string{},
KCodeList: []string{},

Expand All @@ -106,6 +104,7 @@ func (settings *SettingsFile) To_ExecProgram_Args() *gpyrpc.ExecProgram_Args {
SortKeys: settings.Config.SortKeys,
ShowHidden: settings.Config.ShowHidden,
IncludeSchemaTypePath: settings.Config.IncludeSchemaTypePath,
PathSelector: settings.Config.PathSelector,
}
if settings.Config.Debug {
args.Debug = 1
Expand Down
Loading