diff --git a/README.md b/README.md index e8186245..8a5dcd6a 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,7 @@ You can use KCL to - [Install Go 1.19+](https://go.dev/dl/) ```bash -$ go run ./cmds/kcl-go -$ go run ./cmds/kcl-go run hello.k +go run ./cmds/kcl-go run hello.k name: kcl age: 1 two: 2 diff --git a/cmds/kcl-go/main.go b/cmds/kcl-go/main.go index af6240e1..1474bc99 100644 --- a/cmds/kcl-go/main.go +++ b/cmds/kcl-go/main.go @@ -1,7 +1,7 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +// Copyright 2023 The KCL Authors. All rights reserved. -// Kusion Configuration Language (KCL) is a declarative configuration language -// inspired by Python3 designed for Cloud-Native scenes used in Kusion. +// KCL is a declarative configuration language +// inspired by Python3 designed for Cloud-Native scenes. package main import "kcl-lang.io/kcl-go/cmds/kcl-go/command" diff --git a/go.mod b/go.mod index 5d560bf3..cdcdec7f 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( google.golang.org/grpc v1.53.0 google.golang.org/protobuf v1.28.1 gopkg.in/yaml.v3 v3.0.1 - kcl-lang.io/kcl-artifact-go v0.5.1 + kcl-lang.io/kcl-artifact-go v0.5.5 ) require ( diff --git a/go.sum b/go.sum index 586b1cda..38534b5f 100644 --- a/go.sum +++ b/go.sum @@ -63,5 +63,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -kcl-lang.io/kcl-artifact-go v0.5.1 h1:1OIeb1xdq72XIvd9mftBvqFJbzbEkPjGtdeiQizUFj8= -kcl-lang.io/kcl-artifact-go v0.5.1/go.mod h1:c07mqi9Hu2UjPW7lYfHhAAWOlZiB7lo7Vkr4jL5ov/M= +kcl-lang.io/kcl-artifact-go v0.5.5 h1:jsN6JDUDLhreT79ZhIes9G4+8KfwehWFJ6DTK/B29Sc= +kcl-lang.io/kcl-artifact-go v0.5.5/go.mod h1:c07mqi9Hu2UjPW7lYfHhAAWOlZiB7lo7Vkr4jL5ov/M= diff --git a/kclvm_test.go b/kclvm_test.go index 08561af1..1b20b49c 100644 --- a/kclvm_test.go +++ b/kclvm_test.go @@ -192,12 +192,14 @@ func TestFormatCode(t *testing.T) { } func TestGetSchemaType(t *testing.T) { - result, err := kcl.GetSchemaType("test.k", "schema Person:\n name: str", "") + result, err := kcl.GetSchemaType("test.k", "@info(\"v\", k=\"v\")\nschema Person:\n name: str", "") if err != nil { t.Fatal(err) } assert2.Equal(t, []*gpyrpc.KclType{ { + Filename: "test.k", + PkgPath: "__main__", Type: "schema", SchemaName: "Person", Properties: map[string]*gpyrpc.KclType{ @@ -208,19 +210,35 @@ func TestGetSchemaType(t *testing.T) { Required: []string{}, UnionTypes: []*gpyrpc.KclType{}, Decorators: []*gpyrpc.Decorator{}, + Examples: map[string]*gpyrpc.Example{}, }, }, Required: []string{"name"}, UnionTypes: []*gpyrpc.KclType{}, - Decorators: []*gpyrpc.Decorator{}, + Decorators: []*gpyrpc.Decorator{ + { + Name: "info", + Arguments: []string{"\"v\""}, + Keywords: map[string]string{ + "k": "\"v\"", + }, + }, + }, + Examples: map[string]*gpyrpc.Example{}, }, }, result) - result, err = kcl.GetSchemaType("./testdata/main.k", "", "Person") + p, err := filepath.Abs("./testdata/main.k") + if err != nil { + t.Fatal(err) + } + result, err = kcl.GetSchemaType(p, "", "Person") if err != nil { t.Fatal(err) } assert2.Equal(t, []*gpyrpc.KclType{ { + Filename: p, + PkgPath: "__main__", Type: "schema", SchemaName: "Person", Properties: map[string]*gpyrpc.KclType{ @@ -232,6 +250,7 @@ func TestGetSchemaType(t *testing.T) { Required: []string{}, UnionTypes: []*gpyrpc.KclType{}, Decorators: []*gpyrpc.Decorator{}, + Examples: map[string]*gpyrpc.Example{}, }, "age": { Type: "int", @@ -241,11 +260,13 @@ func TestGetSchemaType(t *testing.T) { Required: []string{}, UnionTypes: []*gpyrpc.KclType{}, Decorators: []*gpyrpc.Decorator{}, + Examples: map[string]*gpyrpc.Example{}, }, }, Required: []string{"name", "age"}, UnionTypes: []*gpyrpc.KclType{}, Decorators: []*gpyrpc.Decorator{}, + Examples: map[string]*gpyrpc.Example{}, }, }, result) } @@ -257,6 +278,8 @@ func TestGetSchemaTypeMapping(t *testing.T) { } assert2.Equal(t, map[string]*gpyrpc.KclType{ "Person": { + Filename: "test.k", + PkgPath: "__main__", Type: "schema", SchemaName: "Person", Properties: map[string]*gpyrpc.KclType{ @@ -267,19 +290,28 @@ func TestGetSchemaTypeMapping(t *testing.T) { Required: []string{}, UnionTypes: []*gpyrpc.KclType{}, Decorators: []*gpyrpc.Decorator{}, + Examples: map[string]*gpyrpc.Example{}, }, }, Required: []string{"name"}, UnionTypes: []*gpyrpc.KclType{}, Decorators: []*gpyrpc.Decorator{}, + Examples: map[string]*gpyrpc.Example{}, }, }, result) - result, err = kcl.GetSchemaTypeMapping("./testdata/main.k", "", "Person") + + p, err := filepath.Abs("./testdata/main.k") + if err != nil { + t.Fatal(err) + } + result, err = kcl.GetSchemaTypeMapping(p, "", "Person") if err != nil { t.Fatal(err) } assert2.Equal(t, map[string]*gpyrpc.KclType{ "Person": { + Filename: p, + PkgPath: "__main__", Type: "schema", SchemaName: "Person", Properties: map[string]*gpyrpc.KclType{ @@ -291,6 +323,7 @@ func TestGetSchemaTypeMapping(t *testing.T) { Required: []string{}, UnionTypes: []*gpyrpc.KclType{}, Decorators: []*gpyrpc.Decorator{}, + Examples: map[string]*gpyrpc.Example{}, }, "age": { Type: "int", @@ -300,11 +333,13 @@ func TestGetSchemaTypeMapping(t *testing.T) { Required: []string{}, UnionTypes: []*gpyrpc.KclType{}, Decorators: []*gpyrpc.Decorator{}, + Examples: map[string]*gpyrpc.Example{}, }, }, Required: []string{"name", "age"}, UnionTypes: []*gpyrpc.KclType{}, Decorators: []*gpyrpc.Decorator{}, + Examples: map[string]*gpyrpc.Example{}, }, }, result) } diff --git a/pkg/kcl/api.go b/pkg/kcl/api.go index 492335ce..71f4a4bd 100644 --- a/pkg/kcl/api.go +++ b/pkg/kcl/api.go @@ -1,6 +1,6 @@ // Copyright 2021 The KCL Authors. All rights reserved. -// Package kcl defines the top-level interface for the Kusion Configuration Language (KCL). +// Package kcl defines the top-level interface for KCL. package kcl import ( diff --git a/pkg/tools/list/list.go b/pkg/tools/list/list.go index bcc33902..8142abdb 100644 --- a/pkg/tools/list/list.go +++ b/pkg/tools/list/list.go @@ -6,7 +6,7 @@ It can also be schemas, schema attributes and so on. Supporting on listing these */ package list -// ListDepFiles return the depend files from the given path. It will scan and parse the kusion applications within the workdir, +// ListDepFiles return the depend files from the given path. It will scan and parse the applications within the workdir, // then list depend files of the applications. func ListDepFiles(workDir string, opt *Option) (files []string, err error) { if opt == nil { diff --git a/scripts/kclvm.go b/scripts/kclvm.go index fd474370..780a75d5 100644 --- a/scripts/kclvm.go +++ b/scripts/kclvm.go @@ -17,9 +17,11 @@ const ( ) const ( - KclvmAbiVersion KclvmVersionType = KclvmVersionType_v0_5_1 - KclvmVersionType_latest = KclvmVersionType_v0_5_1 + KclvmAbiVersion KclvmVersionType = KclvmVersionType_v0_5_3 + KclvmVersionType_latest = KclvmVersionType_v0_5_3 + KclvmVersionType_v0_5_3 KclvmVersionType = "v0.5.3" + KclvmVersionType_v0_5_2 KclvmVersionType = "v0.5.2" KclvmVersionType_v0_5_1 KclvmVersionType = "v0.5.1" KclvmVersionType_v0_5_0 KclvmVersionType = "v0.5.0" KclvmVersionType_v0_5_0_beta_1 KclvmVersionType = "v0.5.0-beta.1"