diff --git a/cmd/kcl/commands/mod_graph.go b/cmd/kcl/commands/mod_graph.go index eb569b0..688ab80 100644 --- a/cmd/kcl/commands/mod_graph.go +++ b/cmd/kcl/commands/mod_graph.go @@ -1,10 +1,8 @@ package cmd import ( - "fmt" "os" - "github.com/dominikbraun/graph" "github.com/spf13/cobra" "golang.org/x/mod/module" "kcl-lang.io/kpm/pkg/client" @@ -65,7 +63,10 @@ func ModGraph(cli *client.KpmClient, args []string) error { return err } - kclPkg, err := pkg.LoadKclPkg(pwd) + kclPkg, err := pkg.LoadKclPkgWithOpts( + pkg.WithPath(pwd), + pkg.WithSettings(cli.GetSettings()), + ) if err != nil { return err } @@ -75,30 +76,20 @@ func ModGraph(cli *client.KpmClient, args []string) error { return err } - _, depGraph, err := cli.InitGraphAndDownloadDeps(kclPkg) - if err != nil { - return err - } + gra, err := cli.Graph( + client.WithGraphMod(kclPkg), + ) - adjMap, err := depGraph.AdjacencyMap() - if err != nil { - return err - } + graStr, err := gra.DisplayGraphFromVertex( + module.Version{Path: kclPkg.GetPkgName(), Version: kclPkg.GetPkgVersion()}, + ) - // Print the dependency graph to stdout. - root := module.Version{Path: kclPkg.GetPkgName(), Version: kclPkg.GetPkgVersion()} - err = graph.BFS(depGraph, root, func(source module.Version) bool { - for target := range adjMap[source] { - reporter.ReportMsgTo( - fmt.Sprint(format(source), " ", format(target)), - cli.GetLogWriter(), - ) - } - return false - }) if err != nil { return err } + + reporter.ReportMsgTo(graStr, cli.GetLogWriter()) + return nil } diff --git a/go.mod b/go.mod index 6fbd9ca..9ca1d7a 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( kcl-lang.io/kcl-go v0.10.8 kcl-lang.io/kcl-openapi v0.10.0 kcl-lang.io/kcl-plugin v0.6.0 - kcl-lang.io/kpm v0.10.1-0.20241112023306-e41835e686a8 + kcl-lang.io/kpm v0.10.1-0.20241112112118-8cf5a37c7c35 ) require ( @@ -103,7 +103,7 @@ require ( github.com/docker/go-connections v0.5.0 // indirect github.com/docker/go-metrics v0.0.1 // indirect github.com/docker/go-units v0.5.0 // indirect - github.com/dominikbraun/graph v0.23.0 + github.com/dominikbraun/graph v0.23.0 // indirect github.com/emirpasic/gods v1.18.1 // indirect github.com/fatih/color v1.18.0 github.com/getkin/kin-openapi v0.128.0 // indirect diff --git a/go.sum b/go.sum index 5a701e3..973134d 100644 --- a/go.sum +++ b/go.sum @@ -1707,8 +1707,8 @@ kcl-lang.io/kcl-openapi v0.10.0 h1:yetZMSnn/HHaMcfiLt1P2zhCF06O33jxkjtHrm08VR8= kcl-lang.io/kcl-openapi v0.10.0/go.mod h1:kGCf0AZygrZyB+xpmMtiC3FYoiV/1rCLXuAq2QtuLf8= kcl-lang.io/kcl-plugin v0.6.0 h1:rBdoqKDPdOtojeOHCFnXoB/I7ltFjV61r0KkfOcL5sE= kcl-lang.io/kcl-plugin v0.6.0/go.mod h1:LoIouleHYRKAvFcdW30yUlhsMYH2W9zD5Ji1XHfbht4= -kcl-lang.io/kpm v0.10.1-0.20241112023306-e41835e686a8 h1:H4H6TEyre+dMzcHHWt6gkxqY+ENACrapl1oSmuHro2w= -kcl-lang.io/kpm v0.10.1-0.20241112023306-e41835e686a8/go.mod h1:/G40SABMTuPEVaD1lp0nvPx4v1TIvxIuDwNCV6N9YSU= +kcl-lang.io/kpm v0.10.1-0.20241112112118-8cf5a37c7c35 h1:8Z4QrdeJWx00TMw09r/UwbA1vvV2ej/M2MAfBpPEzUU= +kcl-lang.io/kpm v0.10.1-0.20241112112118-8cf5a37c7c35/go.mod h1:/G40SABMTuPEVaD1lp0nvPx4v1TIvxIuDwNCV6N9YSU= kcl-lang.io/lib v0.10.8 h1:/Mhko6fngIstvdx9dAS3H6N1utogkWfoARVj643l5nU= kcl-lang.io/lib v0.10.8/go.mod h1:0Dw/MQwRMjLDksxl4JerGBn/ueaxRyCCKBCCwQwJ1MI= oras.land/oras-go v1.2.6 h1:z8cmxQXBU8yZ4mkytWqXfo6tZcamPwjsuxYU81xJ8Lk= diff --git a/test/e2e/test_suites/test_mod_graph/input b/test/e2e/test_suites/test_mod_graph/input new file mode 100644 index 0000000..e69de29 diff --git a/test/e2e/test_suites/test_mod_graph/stderr b/test/e2e/test_suites/test_mod_graph/stderr new file mode 100644 index 0000000..e69de29 diff --git a/test/e2e/test_suites/test_mod_graph/stdout b/test/e2e/test_suites/test_mod_graph/stdout new file mode 100644 index 0000000..c63be9c --- /dev/null +++ b/test/e2e/test_suites/test_mod_graph/stdout @@ -0,0 +1 @@ +test_space@0.0.1 helloworld@0.1.4 \ No newline at end of file diff --git a/test/e2e/test_suites/test_mod_graph/test_space/kcl.mod b/test/e2e/test_suites/test_mod_graph/test_space/kcl.mod new file mode 100644 index 0000000..d1c9ccc --- /dev/null +++ b/test/e2e/test_suites/test_mod_graph/test_space/kcl.mod @@ -0,0 +1,7 @@ +[package] +name = "test_space" +edition = "v0.10.0" +version = "0.0.1" + +[dependencies] +helloworld = "0.1.4" diff --git a/test/e2e/test_suites/test_mod_graph/test_space/kcl.mod.lock b/test/e2e/test_suites/test_mod_graph/test_space/kcl.mod.lock new file mode 100644 index 0000000..1428530 --- /dev/null +++ b/test/e2e/test_suites/test_mod_graph/test_space/kcl.mod.lock @@ -0,0 +1,8 @@ +[dependencies] + [dependencies.helloworld] + name = "helloworld" + full_name = "helloworld_0.1.4" + version = "0.1.4" + reg = "ghcr.io" + repo = "kcl-lang/helloworld" + oci_tag = "0.1.4" diff --git a/test/e2e/test_suites/test_mod_graph/test_space/main.k b/test/e2e/test_suites/test_mod_graph/test_space/main.k new file mode 100644 index 0000000..fa7048e --- /dev/null +++ b/test/e2e/test_suites/test_mod_graph/test_space/main.k @@ -0,0 +1 @@ +The_first_kcl_program = 'Hello World!' \ No newline at end of file