Skip to content

Commit

Permalink
feat: sync kcl 0.8 abi spec
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Feb 21, 2024
1 parent e5e87bd commit 7116d45
Show file tree
Hide file tree
Showing 9 changed files with 502 additions and 441 deletions.
7 changes: 6 additions & 1 deletion kclvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,16 @@ func WithPrintOverridesAST(printOverridesAST bool) Option {
return kcl.WithPrintOverridesAST(printOverridesAST)
}

// WithSortKeys returns a Option which hold a sortKeys switch.
// WithSortKeys returns a Option which holds a sortKeys switch.
func WithSortKeys(sortKeys bool) Option {
return kcl.WithSortKeys(sortKeys)
}

// WithShowHidden returns a Option which holds a showHidden switch.
func WithShowHidden(sortKeys bool) Option {
return kcl.WithShowHidden(sortKeys)
}

// WithLogger returns a Option which hold a logger.
func WithLogger(l io.Writer) Option {
return kcl.WithLogger(l)
Expand Down
29 changes: 29 additions & 0 deletions kclvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,35 @@ func TestWithExternalpkg(t *testing.T) {
assert2.Equal(t, "a: Hello External_1 World!\nb: Hello External_2 World!", result.GetRawYamlResult())
}

func TestWithSortKeys(t *testing.T) {
file, err := filepath.Abs("./testdata/test_plan/main.k")
if err != nil {
t.Fatal(err)
}
result, err := kcl.Run(file, kcl.WithSortKeys(true))
if err != nil {
t.Fatal(err)
}
assert2.Equal(t, "a: 2\nb: 1", result.GetRawYamlResult())
}

func TestWithShowHidden(t *testing.T) {
file, err := filepath.Abs("./testdata/test_plan/main.k")
if err != nil {
t.Fatal(err)
}
result, err := kcl.Run(file, kcl.WithShowHidden(true))
if err != nil {
t.Fatal(err)
}
assert2.Equal(t, "b: 1\na: 2\n_c: 3", result.GetRawYamlResult())
result, err = kcl.Run(file, kcl.WithShowHidden(true), kcl.WithSortKeys(true))
if err != nil {
t.Fatal(err)
}
assert2.Equal(t, "_c: 3\na: 2\nb: 1", result.GetRawYamlResult())
}

func TestWithLogger(t *testing.T) {
file, err := filepath.Abs("./testdata/test_print/main.k")
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions pkg/kcl/opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ func WithSortKeys(sortKeys bool) Option {
return *opt
}

// kcl -H --show_hidden
func WithShowHidden(showHidden bool) Option {
var opt = NewOption()
opt.ShowHidden = showHidden
return *opt
}

// Merge will merge all options into one.
func (p *Option) Merge(opts ...Option) *Option {
for _, opt := range opts {
Expand Down Expand Up @@ -273,6 +280,9 @@ func (p *Option) Merge(opts ...Option) *Option {
if opt.SortKeys {
p.SortKeys = opt.SortKeys
}
if opt.ShowHidden {
p.ShowHidden = opt.ShowHidden
}
if opt.IncludeSchemaTypePath {
p.IncludeSchemaTypePath = opt.IncludeSchemaTypePath
}
Expand Down
24 changes: 15 additions & 9 deletions pkg/settings/utils_settings_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ type ConfigStruct struct {
Overrides []string `yaml:"overrides"`
PathSelector []string `yaml:"path_selector"`

StrictRangeCheck bool `yaml:"strict_range_check"`
DisableNone bool `yaml:"disable_none"`
Verbose int `yaml:"verbose"`
Debug bool `yaml:"debug"`
PackageMaps map[string]string `yaml:"package_maps"`
StrictRangeCheck bool `yaml:"strict_range_check"`
DisableNone bool `yaml:"disable_none"`
Verbose int `yaml:"verbose"`
Debug bool `yaml:"debug"`
PackageMaps map[string]string `yaml:"package_maps"`
SortKeys bool `yaml:"sort_keys"`
ShowHidden bool `yaml:"show_hidden"`
IncludeSchemaTypePath bool `yaml:"include_schema_type_path"`
}

type KeyValueStruct struct {
Expand Down Expand Up @@ -96,10 +99,13 @@ func (settings *SettingsFile) To_ExecProgram_Args() *gpyrpc.ExecProgram_Args {
DisableYamlResult: false,
PrintOverrideAst: false,

StrictRangeCheck: settings.Config.StrictRangeCheck,
DisableNone: settings.Config.DisableNone,
Verbose: int32(settings.Config.Verbose),
Debug: 0,
StrictRangeCheck: settings.Config.StrictRangeCheck,
DisableNone: settings.Config.DisableNone,
Verbose: int32(settings.Config.Verbose),
Debug: 0,
SortKeys: settings.Config.SortKeys,
ShowHidden: settings.Config.ShowHidden,
IncludeSchemaTypePath: settings.Config.IncludeSchemaTypePath,
}
if settings.Config.Debug {
args.Debug = 1
Expand Down
799 changes: 410 additions & 389 deletions pkg/spec/gpyrpc/gpyrpc.pb.go

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion pkg/spec/gpyrpc/gpyrpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ message ExecProgram_Args {
// Whether only compiling the program
bool compile_only = 15;

// Show hidden attributes
bool show_hidden = 16;

// -S --path_selector
repeated string path_selector = 17;
}
Expand Down Expand Up @@ -355,7 +358,8 @@ message CliConfig {
int64 verbose = 7;
bool debug = 8;
bool sort_keys = 9;
bool include_schema_type_path = 10;
bool show_hidden = 10;
bool include_schema_type_path = 11;
}

message KeyValuePair {
Expand Down
62 changes: 21 additions & 41 deletions scripts/kclvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,26 @@ const (
)

const (
KclvmAbiVersion KclvmVersionType = KclvmVersionType_v0_7_5
KclvmVersionType_latest = KclvmVersionType_v0_7_5
KclvmAbiVersion KclvmVersionType = KclvmVersionType_v0_8_0
KclvmVersionType_latest = KclvmVersionType_v0_8_0

KclvmVersionType_v0_7_5 KclvmVersionType = "v0.7.5"
KclvmVersionType_v0_7_4 KclvmVersionType = "v0.7.4"
KclvmVersionType_v0_7_3 KclvmVersionType = "v0.7.3"
KclvmVersionType_v0_7_2 KclvmVersionType = "v0.7.2"
KclvmVersionType_v0_7_1 KclvmVersionType = "v0.7.1"
KclvmVersionType_v0_7_0 KclvmVersionType = "v0.7.0"
KclvmVersionType_v0_7_0_beta_2 KclvmVersionType = "v0.7.0-beta.2"
KclvmVersionType_v0_7_0_beta_1 KclvmVersionType = "v0.7.0-beta.1"
KclvmVersionType_v0_7_0_alpha_2 KclvmVersionType = "v0.7.0-alpha.2"
KclvmVersionType_v0_7_0_alpha_1 KclvmVersionType = "v0.7.0-alpha.1"
KclvmVersionType_v0_6_0 KclvmVersionType = "v0.6.0"
KclvmVersionType_v0_6_0_alpha_1 KclvmVersionType = "v0.6.0-alpha.1"
KclvmVersionType_v0_5_6 KclvmVersionType = "v0.5.6"
KclvmVersionType_v0_5_5 KclvmVersionType = "v0.5.5"
KclvmVersionType_v0_5_4 KclvmVersionType = "v0.5.4"
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"
KclvmVersionType_v0_5_0_alpha_4 KclvmVersionType = "v0.5.0-alpha.4"
KclvmVersionType_v0_5_0_alpha_3 KclvmVersionType = "v0.5.0-alpha.3"
KclvmVersionType_v0_5_0_alpha_2 KclvmVersionType = "v0.5.0-alpha.2"
KclvmVersionType_v0_5_0_alpha_1 KclvmVersionType = "v0.5.0-alpha.1"
KclvmVersionType_v0_4_6 KclvmVersionType = "v0.4.6"
KclvmVersionType_v0_4_5 KclvmVersionType = "v0.4.5"
KclvmVersionType_v0_4_5_alpha_2 KclvmVersionType = "v0.4.5-alpha.2"
KclvmVersionType_v0_4_5_alpha_1 KclvmVersionType = "v0.4.5-alpha.1"
KclvmVersionType_v0_4_4 KclvmVersionType = "v0.4.4"
KclvmVersionType_v0_4_4_beta_2 KclvmVersionType = "v0.4.4-beta.2"
KclvmVersionType_v0_4_4_beta_1 KclvmVersionType = "v0.4.4-beta.1"
KclvmVersionType_v0_4_4_alpha_1 KclvmVersionType = "v0.4.4-alpha.1"
KclvmVersionType_v0_4_3 KclvmVersionType = "v0.4.3"
KclvmVersionType_v0_4_3_alpha_1 KclvmVersionType = "v0.4.3-alpha.1"
KclvmVersionType_v0_4_2_alpha_5 KclvmVersionType = "v0.4.2-alpha.5"
KclvmVersionType_v0_4_2_alpha_4 KclvmVersionType = "v0.4.2-alpha.4"
KclvmVersionType_v0_4_2_alpha_3 KclvmVersionType = "v0.4.2-alpha.3"
KclvmVersionType_v0_4_2_alpha_2 KclvmVersionType = "v0.4.2-alpha.2"
KclvmVersionType_v0_4_2_alpha_1 KclvmVersionType = "v0.4.2-alpha.1"
KclvmVersionType_v0_8_0 KclvmVersionType = "v0.8.0"
KclvmVersionType_v0_7_5 KclvmVersionType = "v0.7.5"
KclvmVersionType_v0_7_4 KclvmVersionType = "v0.7.4"
KclvmVersionType_v0_7_3 KclvmVersionType = "v0.7.3"
KclvmVersionType_v0_7_2 KclvmVersionType = "v0.7.2"
KclvmVersionType_v0_7_1 KclvmVersionType = "v0.7.1"
KclvmVersionType_v0_7_0 KclvmVersionType = "v0.7.0"
KclvmVersionType_v0_6_0 KclvmVersionType = "v0.6.0"
KclvmVersionType_v0_5_6 KclvmVersionType = "v0.5.6"
KclvmVersionType_v0_5_5 KclvmVersionType = "v0.5.5"
KclvmVersionType_v0_5_4 KclvmVersionType = "v0.5.4"
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_4_6 KclvmVersionType = "v0.4.6"
KclvmVersionType_v0_4_5 KclvmVersionType = "v0.4.5"
KclvmVersionType_v0_4_4 KclvmVersionType = "v0.4.4"
KclvmVersionType_v0_4_3 KclvmVersionType = "v0.4.3"
)
3 changes: 3 additions & 0 deletions testdata/test_plan/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[package]
name = "test_plan"

3 changes: 3 additions & 0 deletions testdata/test_plan/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
b = 1
a = 2
_c = 3

0 comments on commit 7116d45

Please sign in to comment.