Skip to content

Commit a459cdf

Browse files
authored
Merge pull request #169 from kcl-lang/refactor-mod-graph
refactor: move 'kcl mod graph' to api Graph()
2 parents 5318611 + 314705e commit a459cdf

File tree

9 files changed

+34
-26
lines changed

9 files changed

+34
-26
lines changed

cmd/kcl/commands/mod_graph.go

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package cmd
22

33
import (
4-
"fmt"
54
"os"
65

7-
"github.com/dominikbraun/graph"
86
"github.com/spf13/cobra"
97
"golang.org/x/mod/module"
108
"kcl-lang.io/kpm/pkg/client"
@@ -65,7 +63,10 @@ func ModGraph(cli *client.KpmClient, args []string) error {
6563
return err
6664
}
6765

68-
kclPkg, err := pkg.LoadKclPkg(pwd)
66+
kclPkg, err := pkg.LoadKclPkgWithOpts(
67+
pkg.WithPath(pwd),
68+
pkg.WithSettings(cli.GetSettings()),
69+
)
6970
if err != nil {
7071
return err
7172
}
@@ -75,30 +76,20 @@ func ModGraph(cli *client.KpmClient, args []string) error {
7576
return err
7677
}
7778

78-
_, depGraph, err := cli.InitGraphAndDownloadDeps(kclPkg)
79-
if err != nil {
80-
return err
81-
}
79+
gra, err := cli.Graph(
80+
client.WithGraphMod(kclPkg),
81+
)
8282

83-
adjMap, err := depGraph.AdjacencyMap()
84-
if err != nil {
85-
return err
86-
}
83+
graStr, err := gra.DisplayGraphFromVertex(
84+
module.Version{Path: kclPkg.GetPkgName(), Version: kclPkg.GetPkgVersion()},
85+
)
8786

88-
// Print the dependency graph to stdout.
89-
root := module.Version{Path: kclPkg.GetPkgName(), Version: kclPkg.GetPkgVersion()}
90-
err = graph.BFS(depGraph, root, func(source module.Version) bool {
91-
for target := range adjMap[source] {
92-
reporter.ReportMsgTo(
93-
fmt.Sprint(format(source), " ", format(target)),
94-
cli.GetLogWriter(),
95-
)
96-
}
97-
return false
98-
})
9987
if err != nil {
10088
return err
10189
}
90+
91+
reporter.ReportMsgTo(graStr, cli.GetLogWriter())
92+
10293
return nil
10394
}
10495

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
kcl-lang.io/kcl-go v0.10.8
1414
kcl-lang.io/kcl-openapi v0.10.0
1515
kcl-lang.io/kcl-plugin v0.6.0
16-
kcl-lang.io/kpm v0.10.1-0.20241112023306-e41835e686a8
16+
kcl-lang.io/kpm v0.10.1-0.20241112112118-8cf5a37c7c35
1717
)
1818

1919
require (
@@ -103,7 +103,7 @@ require (
103103
github.com/docker/go-connections v0.5.0 // indirect
104104
github.com/docker/go-metrics v0.0.1 // indirect
105105
github.com/docker/go-units v0.5.0 // indirect
106-
github.com/dominikbraun/graph v0.23.0
106+
github.com/dominikbraun/graph v0.23.0 // indirect
107107
github.com/emirpasic/gods v1.18.1 // indirect
108108
github.com/fatih/color v1.18.0
109109
github.com/getkin/kin-openapi v0.128.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,8 +1707,8 @@ kcl-lang.io/kcl-openapi v0.10.0 h1:yetZMSnn/HHaMcfiLt1P2zhCF06O33jxkjtHrm08VR8=
17071707
kcl-lang.io/kcl-openapi v0.10.0/go.mod h1:kGCf0AZygrZyB+xpmMtiC3FYoiV/1rCLXuAq2QtuLf8=
17081708
kcl-lang.io/kcl-plugin v0.6.0 h1:rBdoqKDPdOtojeOHCFnXoB/I7ltFjV61r0KkfOcL5sE=
17091709
kcl-lang.io/kcl-plugin v0.6.0/go.mod h1:LoIouleHYRKAvFcdW30yUlhsMYH2W9zD5Ji1XHfbht4=
1710-
kcl-lang.io/kpm v0.10.1-0.20241112023306-e41835e686a8 h1:H4H6TEyre+dMzcHHWt6gkxqY+ENACrapl1oSmuHro2w=
1711-
kcl-lang.io/kpm v0.10.1-0.20241112023306-e41835e686a8/go.mod h1:/G40SABMTuPEVaD1lp0nvPx4v1TIvxIuDwNCV6N9YSU=
1710+
kcl-lang.io/kpm v0.10.1-0.20241112112118-8cf5a37c7c35 h1:8Z4QrdeJWx00TMw09r/UwbA1vvV2ej/M2MAfBpPEzUU=
1711+
kcl-lang.io/kpm v0.10.1-0.20241112112118-8cf5a37c7c35/go.mod h1:/G40SABMTuPEVaD1lp0nvPx4v1TIvxIuDwNCV6N9YSU=
17121712
kcl-lang.io/lib v0.10.8 h1:/Mhko6fngIstvdx9dAS3H6N1utogkWfoARVj643l5nU=
17131713
kcl-lang.io/lib v0.10.8/go.mod h1:0Dw/MQwRMjLDksxl4JerGBn/ueaxRyCCKBCCwQwJ1MI=
17141714
oras.land/oras-go v1.2.6 h1:z8cmxQXBU8yZ4mkytWqXfo6tZcamPwjsuxYU81xJ8Lk=

test/e2e/test_suites/test_mod_graph/input

Whitespace-only changes.

test/e2e/test_suites/test_mod_graph/stderr

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "test_space"
3+
edition = "v0.10.0"
4+
version = "0.0.1"
5+
6+
[dependencies]
7+
helloworld = "0.1.4"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[dependencies]
2+
[dependencies.helloworld]
3+
name = "helloworld"
4+
full_name = "helloworld_0.1.4"
5+
version = "0.1.4"
6+
reg = "ghcr.io"
7+
repo = "kcl-lang/helloworld"
8+
oci_tag = "0.1.4"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The_first_kcl_program = 'Hello World!'

0 commit comments

Comments
 (0)