Merge pull request #1519 from jlongtine/mod-get-europa

Remove dependence on project, use cue.mod path.
This commit is contained in:
Joel Longtine 2022-01-28 10:39:25 -07:00 committed by GitHub
commit 7b8a637bea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 16 deletions

View File

@ -3,10 +3,10 @@ package mod
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
"go.dagger.io/dagger/cmd/dagger/cmd/common"
"go.dagger.io/dagger/cmd/dagger/logger" "go.dagger.io/dagger/cmd/dagger/logger"
"go.dagger.io/dagger/mod" "go.dagger.io/dagger/mod"
"go.dagger.io/dagger/telemetry" "go.dagger.io/dagger/pkg"
"go.dagger.io/dagger/state"
) )
var getCmd = &cobra.Command{ var getCmd = &cobra.Command{
@ -25,25 +25,28 @@ var getCmd = &cobra.Command{
lg := logger.New() lg := logger.New()
ctx := lg.WithContext(cmd.Context()) ctx := lg.WithContext(cmd.Context())
project := common.CurrentProject(ctx) var err error
doneCh := common.TrackProjectCommand(ctx, cmd, project, nil, &telemetry.Property{
Name: "packages", cueModPath := pkg.GetCueModParent()
Value: args, // err = pkg.CueModInit(ctx, cueModPath)
}) _, err = state.Init(ctx, cueModPath)
if err != nil && err != state.ErrAlreadyInit {
lg.Fatal().Err(err).Msg("failed to initialize cue.mod")
}
var update = viper.GetBool("update") var update = viper.GetBool("update")
var processedRequires []*mod.Require var processedRequires []*mod.Require
var err error
if update && len(args) == 0 { if update && len(args) == 0 {
lg.Info().Msg("updating all installed packages...") lg.Info().Msg("updating all installed packages...")
processedRequires, err = mod.UpdateInstalled(ctx, project.Path) processedRequires, err = mod.UpdateInstalled(ctx, cueModPath)
} else if update && len(args) > 0 { } else if update && len(args) > 0 {
lg.Info().Msg("updating specified packages...") lg.Info().Msg("updating specified packages...")
processedRequires, err = mod.UpdateAll(ctx, project.Path, args) processedRequires, err = mod.UpdateAll(ctx, cueModPath, args)
} else if !update && len(args) > 0 { } else if !update && len(args) > 0 {
lg.Info().Msg("installing specified packages...") lg.Info().Msg("installing specified packages...")
processedRequires, err = mod.InstallAll(ctx, project.Path, args) processedRequires, err = mod.InstallAll(ctx, cueModPath, args)
} else { } else {
lg.Fatal().Msg("unrecognized update/install operation") lg.Fatal().Msg("unrecognized update/install operation")
} }
@ -58,7 +61,6 @@ var getCmd = &cobra.Command{
lg.Error().Err(err).Msg("error installing/updating packages") lg.Error().Err(err).Msg("error installing/updating packages")
} }
<-doneCh
}, },
} }

View File

@ -85,6 +85,7 @@ func (r *repo) checkout(ctx context.Context, version string) error {
err = w.Checkout(&git.CheckoutOptions{ err = w.Checkout(&git.CheckoutOptions{
Hash: *h, Hash: *h,
Force: true,
}) })
if err != nil { if err != nil {
return err return err

View File

@ -39,7 +39,7 @@ var (
func Vendor(ctx context.Context, p string) error { func Vendor(ctx context.Context, p string) error {
if p == "" { if p == "" {
p = getCueModParent() p = GetCueModParent()
} }
cuePkgDir := path.Join(p, "cue.mod", "pkg") cuePkgDir := path.Join(p, "cue.mod", "pkg")
@ -141,8 +141,8 @@ func extractModules(dest string) error {
}) })
} }
// getCueModParent traverses the directory tree up through ancestors looking for a cue.mod folder // GetCueModParent traverses the directory tree up through ancestors looking for a cue.mod folder
func getCueModParent() string { func GetCueModParent() string {
cwd, _ := os.Getwd() cwd, _ := os.Getwd()
parentDir := cwd parentDir := cwd