Skip to content

Commit

Permalink
Merge pull request #30 from zong-zhe/fix-run-npe
Browse files Browse the repository at this point in the history
fix: fix the npe when 'kcl mod run'
  • Loading branch information
Peefy authored Dec 25, 2023
2 parents fc0ddd8 + 02109f3 commit 7025818
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/kcl/commands/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func appendLangFlags(o *options.RunOptions, flags *pflag.FlagSet) {

func appendRunnerFlags(o *options.RunOptions, flags *pflag.FlagSet) {
flags.StringArrayVarP(&o.Arguments, "argument", "D", []string{},
"Specify the top-level argument")
"Specify the top-level argument")
flags.StringSliceVarP(&o.Settings, "setting", "Y", []string{},
"Specify the command line setting files")
flags.StringSliceVarP(&o.Overrides, "overrides", "O", []string{},
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
kcl-lang.io/kcl-go v0.7.2-0.20231224130422-a010bb43f658
kcl-lang.io/kcl-openapi v0.5.5
kcl-lang.io/kcl-playground v0.5.1
kcl-lang.io/kpm v0.4.8-0.20231225113156-9e4d623c9667
kcl-lang.io/kpm v0.5.0
)

require (
Expand Down Expand Up @@ -144,6 +144,7 @@ require (
golang.org/x/tools v0.8.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gotest.tools/v3 v3.5.1
kcl-lang.io/lib v0.7.4 // indirect
oras.land/oras-go v1.2.3 // indirect
oras.land/oras-go/v2 v2.3.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,8 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o=
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down Expand Up @@ -1290,8 +1292,8 @@ kcl-lang.io/kcl-openapi v0.5.5 h1:6LSbiy53nczagm7Ohgdy1DVgQ+5ffMihsOUY7PGkbh0=
kcl-lang.io/kcl-openapi v0.5.5/go.mod h1:Ai9mFztCVKkRSFabczO/r5hCNdqaNtAc2ZIRxTeV0Mk=
kcl-lang.io/kcl-playground v0.5.1 h1:MKQQUHgt4+2QyU2NVwa73oksOaBJGDi4keGoggA0MiU=
kcl-lang.io/kcl-playground v0.5.1/go.mod h1:IFmnlw7m011ccX8OidMUfnnN2u/TWdtQGxyABRTbmow=
kcl-lang.io/kpm v0.4.8-0.20231225113156-9e4d623c9667 h1:xFtBy+ijrzw8kn5M3jTMjPshlKHBDjgCPb79f3BfhK0=
kcl-lang.io/kpm v0.4.8-0.20231225113156-9e4d623c9667/go.mod h1:Ba2ijUHQR/sMdB4S7982vOrajly4LdgshrqXd2SXBog=
kcl-lang.io/kpm v0.5.0 h1:clJgyJY/xspFmO6uE/WyV81/3DsJJEpT8HP2aZ19XIw=
kcl-lang.io/kpm v0.5.0/go.mod h1:Ba2ijUHQR/sMdB4S7982vOrajly4LdgshrqXd2SXBog=
kcl-lang.io/lib v0.7.4 h1:D1mSGI6Ggb9B3lQqoscQuSOnaBpnkvucZA0WWWniLO0=
kcl-lang.io/lib v0.7.4/go.mod h1:ubsalGXxJaa5II/EsHmsI/tL2EluYHIcW+BwzQPt+uY=
oras.land/oras-go v1.2.3 h1:v8PJl+gEAntI1pJ/LCrDgsuk+1PKVavVEPsYIHFE5uY=
Expand Down
2 changes: 1 addition & 1 deletion pkg/options/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (o *RunOptions) Run() error {
}
// Maybe a single KCL module folder, use the kcl.mod entry profile to run.
if pkg, e := api.GetKclPackage(transformedEntries[0]); e == nil && fs.IsDir(transformedEntries[0]) {
entries := *pkg.GetPkgProfile().Entries
entries := pkg.GetPkgProfile().GetEntries()
if len(entries) > 0 {
opts.SetEntries(entries)
opts.SetPkgPath(transformedEntries[0])
Expand Down
17 changes: 17 additions & 0 deletions pkg/options/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package options

import (
"bytes"
"strings"
"testing"

"gotest.tools/v3/assert"
)

func TestRunOptions_Run(t *testing.T) {
Expand Down Expand Up @@ -139,3 +142,17 @@ func TestRunOptions_Validate(t *testing.T) {
}
}
}

func TestRunPkg(t *testing.T) {
var buf bytes.Buffer
options := NewRunOptions()
options.Entries = []string{"./testdata/run_pkg"}
options.Writer = &buf

err := options.Run()
assert.Equal(t, err, nil)
resStr := strings.ReplaceAll(buf.String(), "\r\n", "")
resStr = strings.ReplaceAll(resStr, "\n", "")

assert.Equal(t, resStr, "The_first_kcl_program: Hello World!")
}
5 changes: 5 additions & 0 deletions pkg/options/testdata/run_pkg/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "run_pkg"
edition = "0.0.1"
version = "0.0.1"

Empty file.
1 change: 1 addition & 0 deletions pkg/options/testdata/run_pkg/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The_first_kcl_program = 'Hello World!'

0 comments on commit 7025818

Please sign in to comment.