@@ -20,9 +20,11 @@ import (
2020 "kcl-lang.io/kcl-go/pkg/tools/gen"
2121 "kcl-lang.io/kpm/pkg/client"
2222 "kcl-lang.io/kpm/pkg/constants"
23+ "kcl-lang.io/kpm/pkg/downloader"
2324 "kcl-lang.io/kpm/pkg/opt"
2425 pkg "kcl-lang.io/kpm/pkg/package"
2526 "kcl-lang.io/kpm/pkg/runner"
27+ "kcl-lang.io/kpm/pkg/utils"
2628)
2729
2830const (
@@ -79,6 +81,8 @@ type RunOptions struct {
7981 Format string
8082 // Writer is used to output the run result. Default is os.Stdout.
8183 Writer io.Writer
84+ // ModSpec is the module spec for the KCL module.
85+ ModSpec * downloader.ModSpec
8286}
8387
8488// NewRunOptions returns a new instance of RunOptions with default values.
@@ -125,7 +129,8 @@ func (o *RunOptions) Run() error {
125129 o .Entries [i ] = entry
126130 }
127131 }
128- result , err = cli .Run (
132+
133+ opts := []client.RunOption {
129134 client .WithRunSourceUrls (o .Entries ),
130135 client .WithSettingFiles (o .Settings ),
131136 client .WithArguments (o .Arguments ),
@@ -140,7 +145,13 @@ func (o *RunOptions) Run() error {
140145 client .WithStrictRange (o .StrictRangeCheck ),
141146 client .WithCompileOnly (o .CompileOnly ),
142147 client .WithLogger (os .Stdout ),
143- )
148+ }
149+
150+ if o .ModSpec != nil {
151+ opts = append (opts , client .WithRunModSpec (o .ModSpec ))
152+ }
153+
154+ result , err = cli .Run (opts ... )
144155
145156 if err != nil {
146157 if o .NoStyle {
@@ -196,22 +207,30 @@ func (o *RunOptions) Complete(args []string) error {
196207 }
197208
198209 for _ , arg := range args {
199- argUrl , err := url .Parse (arg )
200- if err != nil {
201- return err
202- }
203- query := argUrl .Query ()
204- if o .Tag != "" {
205- query .Set ("tag" , o .Tag )
206- }
207- if o .Commit != "" {
208- query .Set ("commit" , o .Commit )
209- }
210- if o .Branch != "" {
211- query .Set ("branch" , o .Branch )
210+
211+ modSpec := downloader.ModSpec {}
212+ err := modSpec .FromString (arg )
213+ // If the arg is a directory or is not a Mod Spec, parse it as other source
214+ if utils .DirExists (arg ) || err != nil {
215+ argUrl , err := url .Parse (arg )
216+ if err != nil {
217+ return err
218+ }
219+ query := argUrl .Query ()
220+ if o .Tag != "" {
221+ query .Set ("tag" , o .Tag )
222+ }
223+ if o .Commit != "" {
224+ query .Set ("commit" , o .Commit )
225+ }
226+ if o .Branch != "" {
227+ query .Set ("branch" , o .Branch )
228+ }
229+ argUrl .RawQuery = query .Encode ()
230+ o .Entries = append (o .Entries , argUrl .String ())
231+ } else {
232+ o .ModSpec = & modSpec
212233 }
213- argUrl .RawQuery = query .Encode ()
214- o .Entries = append (o .Entries , argUrl .String ())
215234 }
216235 return nil
217236}
0 commit comments